I try to list messages from an imap server, with the attachment information.
I have 3 problems :
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 ?
Is there a way to know if there is an attachment file without using Fetchmessage (very slow)?
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
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
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.
I havecreatedan email accountwith somemails. Among thesemails, twomailshave
unreadable subjects. I send youthe login andpassword ina next private post : "Emails with IMAP : Test email account"
Another problem isthe connection toan accountfails ifthe passwordcontainsnon-alphanumericcharacters. I had toreplace theprevious passwordwhich was: Dv[D[40BW(+{
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 “!@*()_+{}#$%^&[]<>?”.