We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Emails with IMAP : message subject and attachment

Hello, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I try to list messages from an imap server, with the attachment information.

I have 3 problems :

1. The subject (ImapMessageInfo.subject) is sometimes replaced by junk characters.
Example : “
Rappel: Enquête Boutique HP” replaced by “?l?/?_??_?? ~
To get the right subject I have to use a Mailmessage (got with Fetchmessage).
What’s wrong ?

2. Is there a way to know if there is an attachment file without using Fetchmessage (very slow) ?

3. If I use oImapClient.FetchMessage(SequenceNumber,true) instead of oImapClient.FetchMessage(SequenceNumber), an exception occurs when the subject is replaced by junk characters : “The ContentID cannot contain a '<' or '>' character. Nom du paramètre : value”

I use VS 2010 - W7, Aspose.Email for .NET 1.3 , net3.5

The code is :

Dim oImapClient As New Aspose.Email.Imap.ImapClient

Dim msgInfoColl As ImapMessageInfoCollection

Dim msgInfo As ImapMessageInfo

Dim message As MailMessage

Dim SequenceNumber As Integer

Dim subject As String

oImapClient = New Aspose.Email.Imap.ImapClient("...", 143, "...@....com", "...")

oImapClient.Connect(True)

...

oImapClient.SelectFolder(folderInfo.Name, True)

msgInfoColl = oImapClient.ListMessages()

For Each msgInfo In msgInfoColl

Console.WriteLine("From : " & msgInfo.From.Address)

Console.WriteLine("To : " & msgInfo.To(0).Address)

If ctrlSubject(msgInfo.Subject) Then 'no funk characters

subject = msgInfo.Subject

Else ‘Subject characters replaced by funk characters

SequenceNumber = msgInfo.SequenceNumber

message = oImapClient.FetchMessage(SequenceNumber)

subject = message.Subject

End If

Console.WriteLine("Subject : " & subject)

Next

Thank you for your responses.

Hi,

Thank you for your inquiry and sample code.

I am afraid that I am unable to replicate the problems listed as 1) and 3). I have performed my testing in an equivalent environment as of yours by connecting to Gmail Imap mail server. I have noticed that the Subject Encoding remains intact when getting the subject field from ImapMessageInfo class. Please check out the snapshot attached (result.png) in reference to the source code shared as below

VB.NET

Dim client = New Aspose.Email.Imap.ImapClient(“[imap.gmail.com](http://imap.gmail.com/)”, "username@gmail.com", “password”)
client.Connect(True)
Dim folder = client.CurrentFolder
client.SelectFolder(“Inbox”, True)
Dim messageInfoCol = client.ListMessages()
For Each messageInfo In messageInfoCol
Console.WriteLine(messageInfo.Subject)
Dim SequenceNumber = messageInfo.SequenceNumber
Dim message = client.FetchMessage(SequenceNumber,True)
Dim subject = message.Subject
Console.WriteLine(subject)
Next messageInfo

This encoding problem can be due to the Imap mail server it self. So if you are using some other server than Gmail then please try to provide us a test account for further investigation into this matter.

Regarding the point 2), at the moment there are no means available to detect the attachment by just listing the messages. You can use the client.FetchMessage(SequenceNumber,True) to ignore the attachment while fetching the message. By setting the ignoreAttachment parameter to true will definitely consume lesser time to execute than its converse.

Please feel free to write back.

Regards,

Hello,

I have created an email account with some mails.
Among these mails, two mails have unreadable subjects.
I send you the login and password in a next private post : "Emails with IMAP : Test email account"

Another problem is the connection to an account fails if the password contains non-alphanumeric characters. I had to replace the previous password which was: Dv[D[40BW(+{

Best regards.

Hi,

Thank you for sharing the test account details. I have verified the issue with [abcdigit.com](http://abcdigit.com/) server and found the encoding problem. To probe further into this matter, I have logged an investigative ticket (Id: NETWORKNET-33119) in our tracking system. We will keep you posted with updates on this.

[Edited] Regarding the non-alphanumeric characters in password while using ImapClient. I am unable to replicate the problem with gmail account by changing the password to “!@*()_+{}#$%^&[]<>?”.

Regards,