S22.Imap | NET library component for communicating with IMAP servers
kandi X-RAY | S22.Imap Summary
kandi X-RAY | S22.Imap Summary
A free, easy-to-use and well-documented .NET library component for communicating with IMAP servers
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of S22.Imap
S22.Imap Key Features
S22.Imap Examples and Code Snippets
Community Discussions
Trending Discussions on S22.Imap
QUESTION
I'm working on building an email client using .net framework 4.6.1, which will fetch emails from a mailbox and display on the email client. Currently I'm using s22.Imap's ImapClient.GetMessage()
method to retrieve the email content. It works fine for the attachments and for bodyContent with most default encoding.
But some of my mails are of type CodePage = 932
and EncodingName = "Japanese (Shift-JIS)"
. I'm not able to fetch these emails since they throw System.NotSupportedException
for most of the BodyEncoding attributes / properties.
On Searching through the github issues for s22.Imap, there was an issue which was suggesting to use mailkit instead of s22.Imap. I would like to know more about how this encoding part is handled in mailkit. Also would like to know if there is a default way to handle encoding of unknown CodePage types.
...ANSWER
Answered 2020-Mar-24 at 13:56You can read this blog post that explains what most C# MIME parsers get wrong and why MimeKit can handle multiple charset encodings.
https://jeffreystedfast.blogspot.com/2013/09/time-for-rant-on-mime-parsers.html https://jeffreystedfast.blogspot.com/2013/08/why-decoding-rfc2047-encoded-headers-is.html
Since the StackOverflow moderators will likely complain about posting a link, here's a copy & paste of the content:
Time for a rant on mime parsers...Warning: Viewer discretion is advised.
Where should I begin?
I guess I should start by saying that I am obsessed with MIME and, in particular, MIME parsers. No, really. I am obsessed. Don't believe me? I've written and/or worked on several MIME parsers at this point. It started off in my college days working on Spruce which had a horrendously bad MIME parser, and so as you read farther along in my rant about shitty MIME parsers, keep in mind: I've been there, I've written a shitty MIME parser.
As a handful of people are aware, I've recently started implementing a C# MIME parser called MimeKit. As I work on this, I've been searching around on GitHub and Google to see what other MIME parsers exist out there to find out what sort of APIs they provide. I thought perhaps I'll find one that offers a well-designed API that will inspire me. Perhaps, by some miracle, I'd find one that was actually pretty good that I could just contribute to instead of writing my own from scratch (yea, wishful thinking). Instead, all I have found are poorly designed and implemented MIME parsers, many probably belong on the front page of the Daily WTF.
I guess I'll start with some softballs.
First, there's the fact that every single one of them were written as System.String
parsers. Don't be fooled by the ones claiming to be "stream parsers", because all any of those did was to slap a TextReader
on top of the byte stream and start using reader.ReadLine()
. What's so bad about that, you ask? For those not familiar with MIME, I'd like for you to take a look at the raw email sources in your inboxes particularly if you have correspondence with anyone outside of the US. Hopefully most of your friends and colleagues are using more-or-less MIME compliant email clients, but I guarantee you'll find at least a few emails with raw 8bit text.
Now, if the language they were using was C or C++, they might be able to get away with doing this because they'd technically be operating on byte arrays, but with Java and C#, a 'string' is a unicode string. Tell me: how does one get a unicode string from a raw byte array?
Bingo. You need to know the charset before you can convert those bytes into unicode characters.
To be fair, there's really no good way of handling raw 8bit text in message headers, but by using a TextReader
approach, you are really limiting the possibilities.
Next up is the ReadLine()
approach. One of the 2 early parsers in GMime (pan-mime-parser.c back in the version 0.7 days) used a ReadLine()
approach, so I understand the thinking behind this. And really, there's nothing wrong with this approach as far as correctness goes, it's more of a "this can never be fast" complaint. Of the two early parsers in GMime, the pan-mime-parser.c backend was horribly slow compared to the in-memory parser. Of course, that's not very surprising. More surprising to me at the time was that when I wrote GMime's current generation of parser (sometime between v0.7 and v1.0), it was just as fast as the in-memory parser ever was and only ever had up to 4k in a read buffer at any given time. My point is, there are far better approaches than ReadLine()
if you want your parser to be reasonably performant... and why wouldn't you want that? Your users definitely want that.
Okay, now come the more serious problems that I encountered in nearly all of the mime parser libraries I found.
I think that every single mime parser I've found so far uses the "String.Split()" approach for parsing address headers and/or for parsing parameter lists on headers such as Content-Type and Content-Disposition.
Here's an example from one C# MIME parser:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install S22.Imap
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page