1.

Solve : Outlook strips carriage returns and line feeds?

Answer»

Hi,

I'm seeing a strange thing with missing line feeds in an addin I'm building for Outlook 2003. When I manually enter TEXT
into the message body and then run the String.Split() code (below) it works find and can find the CRLFs. But if I paste text into the message body String.Split() cannot find the CRLFs - it's as if the CRLFs vanish!  But the message body still appears with paragraphs (as it the CRLFs are there).

Here are the DETAILS:

When the user sends an email my code does a split on the email message body on line feeds (CRLF) LIKE this:


void ThisApplication_ItemSend(object Item, ref bool Cancel)
{

     Outlook.MailItem mailitem = (Outlook.MailItem)Item;

     string[] Paragraphs = mailitem.Body.Split(Environment.NewLine.ToCharArray());

}


If I enter some short sentences (seperated by CRLFs) into a test email all works fine.
For example, a body of:

TestI
TestII


... works fine; there is a CRLF after "TestI".  But if I copy & paste the first line ("TestI " - added a SEPERATOR space) back into the body multiple times to get the following body:

TestI TestI TestI TestI TestI TestI TestI TestI TestI TestI TestI TestI TestI
TestII



... the CRLF after the last "TestI" unexplainably vanishes and therefor the string.Split() doesn't split right and returns just one item: the whole thing as one long string:

"TestI TestI TestI TestI TestI TestI TestI TestI TestI TestI TestI TestI TestI TestII"


Ironically, as I mentioned earlier, it still shows up in Outlook on two lines (as if there is a CRLF after the last "TestI").

I've experimented with other encodings (ASCII, US, ETC...) but with no difference. This only seems to be a problem when composing emails in "plain text" mode - "html" format doesn't have this problem.


Any help is much appreciated.

  Phil



Discussion

No Comment Found