message.Body.Text = ""

Oct 28, 2013 at 11:39 PM
So my company just did the switch from Exchange to Gmail for our email handling. We are using ImapX to do most of the sorting and we love it; however, it has one problem that we see right now.

On emails from a particular client the Body.Html will come back with all the necessary information; but the Body.Text field comes back as a blank string ("") and the Body.HasText = false.

However, when we look at the email we see text and a few pictures.

Could this be due to our client's email format?
Coordinator
Oct 29, 2013 at 8:14 AM
Hi maylortaylor,

Exactly. This completely depends on the message format, and which body parts the client included sending a message.
Body.Text and Body.Html are alternative views for the message body. Some messages will include both, others will only have html or text. So if Body.HasText is set to false, it means that the message didn't include a plain text body part, but as Body.HasHtml is true, has an html body part.

Hope this helps,

Greets,

Pavel
Oct 29, 2013 at 9:57 AM
Edited Oct 29, 2013 at 9:58 AM
I am also having this issue.
All my messages have empty HTML and empty Text.
If I use msg.Body.Text or msg.Body.Html it returns ""
Console.WriteLine("Logged in");
                Console.WriteLine("Downloading messages...");
                ImapX.Collections.CommonFolderCollection folders = client.Folders;
                client.Folders["Entries"].Messages.Download("ALL", ImapX.Enums.MessageFetchMode.Full);
                ImapX.Collections.MessageCollection messages = client.Folders["INBOX"].Messages;
                //client.Folders.Inbox.Messages.Download();
               // client.Folders["Entries"].Messages.Download("ALL",ImapX.Enums.MessageFetchMode.Body,-1);
                //ImapX.Collections.MessageCollection messages = client.Folders["Entries"].Messages;
                Console.WriteLine("Downloading messages complete");
                //ImapX.Collections.MessageCollection messages = client.Folders.All.Messages;
                StreamWriter sw = new StreamWriter("Entries.txt");
                foreach (ImapX.Message msg in messages)
                {
                    sw.WriteLine(msg.Body.HasText + " " + msg.Body.HasHtml);
                    Console.WriteLine("NEW MESSAGE: " + msg.Body.HasText + " " + msg.Body.HasHtml);
                }
                sw.Close();
I do receive lots of messages and they all contain subjects etc but no body at all
Coordinator
Oct 29, 2013 at 11:06 AM
Hi Zaphire,

first of all a couple of questions:
  1. Which server do you use?
  2. Do the messages contain any body parts? How about attachments and embedded resources?
  3. Can you provide test credentials? (if so, please send them to p13a92@gmail.com )
It will help me to give a more detailed explanation and provide a fix if needed.

Best regards,

Pavel
Oct 29, 2013 at 6:12 PM
This small line of code will do wonders for the message.Body.Html

HTMLstring= Regex.Replace(HTMLstring, "<.*?>", string.Empty);


It gets rid of all the HTML tags and leaves you only the text.
Coordinator
Oct 29, 2013 at 6:40 PM
Thank you maylortaylor, so if I got it right, you suggest just processing the Html, removing all tags and saving it in Body.Text in case there's no plain text part available?
I can include this as an option for the client behavior.
Oct 29, 2013 at 6:45 PM
Yep that sounds like it would be perfect!
Oct 29, 2013 at 6:54 PM
IMAPX gets better every day. Thank you, Pavel!

--Ravi
Coordinator
Oct 29, 2013 at 7:30 PM
Edited Oct 29, 2013 at 7:32 PM
You're welcome! The feature maylortaylor has mentioned is now available in the latest code in repository (isn't tested yet, so didn't update the binaries).
To enable automated body part generation, set client.Behavior.AutoGenerateMissingBody to true.

There was also a minor fix for MessageContent.Download to not request same data from the server if it has been done before.
Oct 29, 2013 at 7:40 PM
Edited Oct 29, 2013 at 7:40 PM
Should the Behavior property be named AutoGenerateMissingTextBody?

--Ravi
Coordinator
Oct 29, 2013 at 8:30 PM
The library will also generate Html from Text (replacing line breaks through <br />), so I decided to name the property AutoGenerateMissingBody.