Hi Ivar !
Question: Below my code to load the body of an email-message by UID:
I have a simple e-mail message in my inbox (among others), which contains a registration link for the user to click.
Now I load this message by UID using Lumisoft.Net.
I can load the body, and I get the email content, but I always only get the content as text.
Opening the same message in any email client yields a link.
At first, I thought I only just need to replace
Code:
if (mime.BodyText != null)
strContent = mime.BodyText;
with
Code:
if(mime.BodyHtmlText != null)
strContent = mime.BodyHtmlText;
But BodyHtmlText is always null, while BodyText contains all the text (also the link as text), but no html tags at all.
I can extract the link with regex all-right, but either it's a bug/incompleteness in my code, or in yours.
Which one is it ?
Because according to my eyes, "my" code is correct ;-)
Code:
private void LoadMessage(long uid)
{
Console.Out.WriteLine("Fetching body");
//m_pTabPageMail_MessageAttachments.Items.Clear();
m_pIMAP.SelectFolder("INBOX");
this.Cursor = Cursors.WaitCursor;
try
{
/* NOTE: IMAP_Client_FetchHandler provides events to handle IMAP server returned
* fetch data items for requested message(s).
*/
LumiSoft.Net.IMAP.Client.IMAP_Client_FetchHandler fetchHandler = new LumiSoft.Net.IMAP.Client.IMAP_Client_FetchHandler();
fetchHandler.Rfc822 += new EventHandler<LumiSoft.Net.IMAP.Client.IMAP_Client_Fetch_Rfc822_EArgs>(delegate(object s, LumiSoft.Net.IMAP.Client.IMAP_Client_Fetch_Rfc822_EArgs e)
{
System.IO.MemoryStream storeStream = new System.IO.MemoryStream();
e.Stream = storeStream;
e.StoringCompleted += new EventHandler(delegate(object s1, EventArgs e1)
{
storeStream.Position = 0;
LumiSoft.Net.Mail.Mail_Message mime = LumiSoft.Net.Mail.Mail_Message.ParseFromStream(storeStream);
//m_pTabPageMail_MessagesToolbar.Items["save"].Enabled = true;
//m_pTabPageMail_MessagesToolbar.Items["delete"].Enabled = true;
//m_pTabPageMail_MessageAttachments.Tag = mime;
foreach (LumiSoft.Net.MIME.MIME_Entity entity in mime.Attachments)
{
ListViewItem item = new ListViewItem();
if (entity.ContentDisposition != null && entity.ContentDisposition.Param_FileName != null)
{
item.Text = entity.ContentDisposition.Param_FileName;
}
else
{
item.Text = "untitled";
}
item.ImageIndex = 0;
item.Tag = entity;
//m_pTabPageMail_MessageAttachments.Items.Add(item);
} // Next entity
if(mime.BodyHtmlText != null)
strContent = mime.BodyHtmlText;
else
{
if (mime.BodyText != null)
strContent = mime.BodyText;
//m_pTabPageMail_MessageText.Text = mime.BodyText;
}
}); // End Sub e.StoringCompleted
}); // End Sub fetchHandler.Rfc822
IMAP_SequenceSet seqSet = new IMAP_SequenceSet();
seqSet.Parse(uid.ToString());
// Start fetching (IMAP_Client_FetchHandler events are rised when IMAP server returns any data).
m_pIMAP.Fetch(true, seqSet, new IMAP_Fetch_DataItem[]{ new IMAP_Fetch_DataItem_Rfc822()}, fetchHandler);
} // End Try
catch (Exception ex)
{
MessageBox.Show(this, "Error: " + ex.ToString(), "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
} // End Catch
this.Cursor = Cursors.Default;
} // End Sub LoadMessage