Code Monkey home page Code Monkey logo

Comments (13)

NiKiZe avatar NiKiZe commented on July 20, 2024

That is my fault. When i changed to correctly parse displaynames containing "," using the .NET framework.

The message you are downloading probably have a ";" in one of the To,From,Reply-To,Cc or Bcc fields. this is not ok by standard (so the .NET framework throws on this) however it is quite common in spam emails.

I'm working on a fix, and it will be done in the next few days. But just to be sure can you confirm if this message is spam or not, and if possible post any header line of the above containing this ";" ?

from s22.imap.

rboy1 avatar rboy1 commented on July 20, 2024

Yes this is a spam message, but it breaks the app. Appreciate the fix.

On Fri, Mar 22, 2013 at 3:45 AM, Christian Nilsson <[email protected]

wrote:

That is my fault. When i changed to correctly parse displaynames
containing "," using the .NET framework.

The message you are downloading probably have a ";" in one of the
To,From,Reply-To,Cc or Bcc fields. this is not ok by standard (so the .NET
framework throws on this) however it is quite common in spam emails.

I'm working on a fix, and it will be done in the next few days. But just
to be sure can you confirm if this message is spam or not, and if possible
post any header line of the above containing this ";" ?


Reply to this email directly or view it on GitHubhttps://github.com//issues/48#issuecomment-15288313
.

from s22.imap.

rboy1 avatar rboy1 commented on July 20, 2024

This is the address:

Fidelity Life Insurance
[email protected]<=?UTF-8?B?b3Bxa3V2QG0ubGluYWFrZW4uY29t?=@
yahoo.com>;

On Fri, Mar 22, 2013 at 3:45 AM, Christian Nilsson <[email protected]

wrote:

That is my fault. When i changed to correctly parse displaynames
containing "," using the .NET framework.

The message you are downloading probably have a ";" in one of the
To,From,Reply-To,Cc or Bcc fields. this is not ok by standard (so the .NET
framework throws on this) however it is quite common in spam emails.

I'm working on a fix, and it will be done in the next few days. But just
to be sure can you confirm if this message is spam or not, and if possible
post any header line of the above containing this ";" ?


Reply to this email directly or view it on GitHubhttps://github.com//issues/48#issuecomment-15288313
.

from s22.imap.

NiKiZe avatar NiKiZe commented on July 20, 2024

@rboy1 You should handle exceptions on GetMessage so the app do not break. ;)
A quick fix in this case is to change mcol.Add(list); to mcol.Add(list.Trim(';')); (in MessageBuilder.cs function ParseAddressList(string list) )

Unfortunately there is several variants of this that need to be handled. but hope this helps you short term.

from s22.imap.

rboy1 avatar rboy1 commented on July 20, 2024

Short term I am catching and ignoring the emails. Will wait for your fix

On Mar 22, 2013, at 12:26 PM, Christian Nilsson [email protected] wrote:

@rboy1 You should handle exceptions on GetMessage so the app do not break. ;)
A quick fix in this case is to change mcol.Add(list); to mcol.Add(list.Trim(';')); (in MessageBuilder.cs function ParseAddressList(string list) )

Unfortunately there is several variants of this that need to be handled. but hope this helps you short term.


Reply to this email directly or view it on GitHub.

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

Thanks,
the call to ParseAddressList should be wrapped in a try/catch block so that no exception can bubble up to the user. Will be fixed shortly!

from s22.imap.

NiKiZe avatar NiKiZe commented on July 20, 2024

For now I created a fix in #49
I can not find a good solution to "catch" that the address was not parsed correctly. any Idéas?

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

We should just wrap the call to MailAddressCollection's Add method in try/catch. If the Add method throws an exception, it already means the address list contains illegal characters or is malformed.

        try {
            MailAddressCollection mcol = new MailAddressCollection();
            // Use .NET internal MailAddressParser.ParseMultipleAddresses
            // to parse the address list.
            mcol.Add(list);
            foreach (MailAddress m in mcol) {
                            // ...
            }
        } catch {
            // We don't want this to throw any exceptions even if the
            // address list is malformed.
        }

from s22.imap.

NiKiZe avatar NiKiZe commented on July 20, 2024

But i want (my app) to be informed about what failed and what the original data was. That might easily be done with a event that can be subscribed to?

Also we want to know about all cases that do not work and handle that, instead of depending on exceptions.
(I'm taught that depending on exceptions is bad practice)

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

How do you handle an illegal or deliberately malformed address, though? There's no way to magically fix it, so ParseMultipleAddresses throws an exception, which it should in my opinion. In such a case I much prefer swallowing the exception and hand the user a MailMessage instance with the respective field left empty to letting the exception bubble up.

from s22.imap.

NiKiZe avatar NiKiZe commented on July 20, 2024

That's why i suggested a Event.

The user can both get a MailMessage instance and also information about the incorrectly parsed address.
But i also prefer the function to catch the invalid formats before it have become exceptions.

from s22.imap.

lydiaMag avatar lydiaMag commented on July 20, 2024

I have a similar problem but in my case the character that causes the exception is ',' )not ';' (may because it is from a french sever ) this character is at the end of the 'To' adresses
I see that the character ',' is not handled in the ParseAddressList in the MessageBuilder.cs
I have made a pull request #68
list = list.TrimEnd(',');
Exception thrown :{An invalid character was found in the mail header: ','
at System.Net.Mail.DotAtomReader.ReadReverse(String data, Int32 index)
at System.Net.Mail.MailAddressParser.ParseDomain(String data, Int32& index)
at System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index)
at System.Net.Mail.MailAddressParser.ParseMultipleAddresses(String data)
at System.Net.Mail.MailAddressCollection.ParseValue(String addresses)
at System.Net.Mail.MailAddressCollection.Add(String addresses)
at S22.Imap.MessageBuilder.ParseAddressList(String list)
at S22.Imap.MessageBuilder.SetAddressFields(MailMessage m, NameValueCollection header)
at S22.Imap.MessageBuilder.FromHeader(String text)
at S22.Imap.MessageBuilder.FromMIME822(String text)
at S22.Imap.ImapClient.GetMessage(UInt32 uid, FetchOptions options, Boolean seen, String mailbox)
at S22.Imap.ImapClient.GetMessage(UInt32 uid, Boolean seen, String mailbox)
at MyProjects.Helpers.EmailHelper.GetMessages() in e:\MyProjects\OMR-Projects\Helpers\EmailHelper.cs:line 28}

from s22.imap.

jstedfast avatar jstedfast commented on July 20, 2024

@NiKiZe

Semi-colons are perfectly legal tokens in rfc822 group addresses. The fact that System.Net.Mail's MailAddress[Collection] parser doesn't handle them isn't a surprise since it's not really meant to be used to handle real-world mail, it's just a half-assed solution for sending mail, not receiving it.

Anyway, MimeKit's InternetAddressList Parse() and TryParse() methods handle this.

from s22.imap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.