logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

IMAP: BodyHtmlText always NULL ?
quandary
#1 Posted : Tuesday, January 31, 2012 1:38:16 PM(UTC)
Rank: Advanced Member

Groups: Member
Joined: 6/6/2010(UTC)
Posts: 39
Points: 120
Location: Switzerland

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

ivx
#2 Posted : Tuesday, January 31, 2012 3:37:42 PM(UTC)
Rank: Administration

Groups: Administration
Joined: 9/15/2006(UTC)
Posts: 1,946
Points: 5,711
Man
Location: Estonia

Was thanked: 68 time(s) in 68 post(s)
Hi,

It's message related, before i can't see full message data, i can't comment.

BodyHtml searches first text/html content from message.
quandary
#3 Posted : Tuesday, January 31, 2012 5:46:12 PM(UTC)
Rank: Advanced Member

Groups: Member
Joined: 6/6/2010(UTC)
Posts: 39
Points: 120
Location: Switzerland

ivx;4497 wrote:
Hi,

It's message related, before i can't see full message data, i can't comment.

BodyHtml searches first text/html content from message.


I've modified the StoringCompleted event handler.

Code:

e.StoringCompleted += new EventHandler(delegate(object s1, EventArgs e1)
                    {
                        storeStream.Position = 0;


                        var sr = new System.IO.StreamReader(storeStream);
                        var strStreamContent = sr.ReadToEnd();
                        System.IO.File.WriteAllText(@"D:\Temp\MessageLog.txt", strStreamContent);
                        storeStream.Position = 0;


This is MessageLog.txt:
Code:

Return-Path: <webmaster@waldbuehne.ch>
Received: from compute4.internal (compute4.nyi.mail.srv.osa [10.202.2.44])
     by sloti14d1p1 (Cyrus git2.5+0-git-fastmail-7658) with LMTPA;
     Fri, 27 Jan 2012 09:26:06 -0500
X-Sieve: CMU Sieve 2.4
X-Spam-charsets: plain='utf-8'
X-Resolved-to: quandary82 (at) hailmail.net
X-Delivered-to: quandary82 (at) hailmail.net
X-Mail-from: webmaster@waldbuehne.ch
Received: from mx1.nyi.mail.srv.osa ([10.202.2.200])
by compute4.internal (LMTPProxy); Fri, 27 Jan 2012 09:26:06 -0500
Received: from msscript1.webland.ch (msscript1.webland.ch [92.43.216.251])
    (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
    (No client certificate requested)
    by mx1.nyi.mail.srv.osa (Postfix) with ESMTPS id C2ED24C0187
    for <quandary82 (at) hailmail.net>; Fri, 27 Jan 2012 09:26:05 -0500 (EST)
Received: from WLC103 ([92.43.216.200])
by msscript1.webland.ch (Webland.MailServer.v.10.1) with SMTP id LPD77020
for <quandary82 (at) hailmail.net>; Fri, 27 Jan 2012 15:28:20 +0100
thread-index: Aczc/4kGL6gebA89QG6h2w39+cfLDw==
Thread-Topic: Voting auf www.waldbuehne.ch
From: <webmaster@waldbuehne.ch>
To: <quandary82 (at) hailmail.net>
Subject: Voting auf www.waldbuehne.ch
Date: Fri, 27 Jan 2012 15:25:36 +0100
Message-ID: <2BB79800094F4D1A9A0CD8464186EB31@WLC103>
MIME-Version: 1.0
Content-Type: text/plain;
    charset="utf-8"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.1.7601.17609
X-Truedomain-Domain: waldbuehne.ch
X-Truedomain-SPF: No Record
X-Truedomain-DKIM: No Signature
X-Truedomain-ID: 552A67367CBBD26258E4D9F820256F6A
X-Truedomain: Neutral

Vielen Dank.

WICHTIG: Falls du beim Voting nicht teilgenommen hast, bitte untenstehenden Link nicht anklicken!

Sobald du den untenstehenden Link geklickt hast, wird Deine Wahl akzeptiert.

http://www.waldbuehne.ch/bands-detail.aspx?ID=2479&v=a568f9f2936a112a898e1a3e6be4595f

Deine Gurtenfestival Crew.




Is that the full message data ?
If yes, it would seem mainstream mail programs convert text/plain to HTML and thereby replace URLs with links.
ivx
#4 Posted : Wednesday, February 01, 2012 8:23:00 AM(UTC)
Rank: Administration

Groups: Administration
Joined: 9/15/2006(UTC)
Posts: 1,946
Points: 5,711
Man
Location: Estonia

Was thanked: 68 time(s) in 68 post(s)
Yes seems email programs show url.
Beacuse your message is just plain/text one.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF 1.9.5.5 | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.050 seconds.