0

I have a problem with the email Subject. I always get an email when there is an error somewhere. So when I look at the email, everything seems fine. But when I watch the characteristics off it, I can see a few errors. For example:

Subject: Text: Alarm Text about an error
For some reason a carriage return and a space at the start of the new line:
It’s still the same Subject again with a carriage return*

As you can see, for some reasons there are carriage returns (CRLF) which are completely random. What I’ve tried so far is to check when this happens. Found out that it is Random. When I’m trying to read it out (C#), the Subject is technically right. But instead off a carriage return, there is just nothing. To clarify this: the Subject should be like this:

Subject: Text: Alarm Text about an error for some reason a carriage return and a space at the start of the new line: It’s still the same Subject with a carriage return*

But I get it in the Code like this:

Subject: Text: Alarm Text about an errorfor some reason a carriage return and a space at the start of the new line:It’s still the same Subject with a carriage return

As you can see there is just nothing and there should be a space. So far I’ve tried to change the CRLF to space. Which obviously did not work ‘cause there is no carriage return in the Code. Then I tried to change the encoding to base64. Reason for that was:

http://www.kodokmarton.eu/desktop-application-web-programming/41-web-programming/129-random-newline-and-spaces-inserted-in-emails

So then I tried it like this:

How do I encode and decode a base64 string?

So far nothing worked. This is how I read the mails out:

imap = new AE.Net.Mail.ImapClient(mailServer, login, password, AuthMethods.Login, port, ssl);
var msgs = imap.SearchMessages(SearchCondition.Subject("text Subject"));
        for (int i = 0; i < msgs.Length; i++)
        {
            MailMessage msg = new MailMessage();
            msg = msgs[i].Value; 
            string Subject = msg.Subject;

NOTE: I have to fix it in the Code. For some reasons I can not change the way I send Emails or other things. It has to be in the Code.

Thanks for any advice!

Community
  • 1
  • 1
Tobe
  • 93
  • 1
  • 12
  • 2
    Doesn't look random to me - looks like header folding as per [RFC2822](https://www.ietf.org/rfc/rfc2822.txt) – Jon Skeet Jun 15 '16 at 08:24
  • Sadly Im not here to offer words of advice, but to say I saw something similar, I was trying to use imap to read a bunch of emails and found it was formatting the mail to 80 characters wide, so that a line that was say 200 characters long, was sent as 3 separate lines and I couldnt fix it, so I ended up using outlook as a mail client... long subjects are also prone to similar wrapping I think – BugFinder Jun 15 '16 at 08:25
  • @JonSkeet I've heard about this. But how can iI "fix" this. Is there a way to know when it happens? – Tobe Jun 15 '16 at 08:48
  • I'd expect some email clients to do it whenever it's required to make sure that every line is less than or equal to 78 characters. To get back to the original, I suspect you can just remove all CRLFs. But then, we don't really know what you're doing with the emails anyway.. – Jon Skeet Jun 15 '16 at 08:52
  • @JonSkeet Well the problem is, when i read them out, there are no CRLF. Like in the post written, there is just nothing... – Tobe Jun 15 '16 at 08:54
  • So where *are* you seeing the CRLF? It sounds like everything is working fine - the sending client is wrapping the subject line by splitting into lines, and the receiving client is unwrapping it by removing the CRLF. What's the problem? – Jon Skeet Jun 15 '16 at 09:06
  • @JonSkeet I see them when i copy Subject from outlook and insert it into notepad++. If i would see them in the Code everything would be great but like written, there is just nothing. For example if there was "Hello CRLF World!" in the Code it would be "HelloWorld!" and that's the problem. – Tobe Jun 15 '16 at 09:14
  • Where exactly are you seeing it in Outlook? If you're looking at the original headers, then don't - look at what the client shows you as a user. (It would really help if you'd be a *lot* clearer in the question - you're very vague about everything in terms of where you're observing what, which makes it very hard to help you.) – Jon Skeet Jun 15 '16 at 09:19
  • I open the Mail which I get. Then i open the properties and from there i copy it. The mail itself seems fine. My problem is, when i read the emails in visual studio with C# out, there is nothing like i tried to explain before. – Tobe Jun 15 '16 at 09:26

0 Answers0