Esempio n. 1
0
        public static EmailMessage Create(Stream source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (!source.CanRead)
            {
                throw new ArgumentException("Stream must support Read", "source");
            }
            MimeDocument mimeDocument = new MimeDocument();

            mimeDocument.Load(source, CachingMode.Copy);
            MimeTnefMessage mimeTnefMessage = new MimeTnefMessage(mimeDocument);

            return(new EmailMessage(mimeTnefMessage));
        }
Esempio n. 2
0
        private bool TryGenerateMessageFromEmlFileData(out string error)
        {
            error = string.Empty;
            MimeDocument mimeDocument = new MimeDocument();

            using (Stream stream = new MemoryStream(this.MessageFileData))
            {
                try
                {
                    mimeDocument.ComplianceMode = MimeComplianceMode.Strict;
                    mimeDocument.Load(stream, CachingMode.Copy);
                    this.message = EmailMessage.Create(mimeDocument);
                }
                catch (ArgumentNullException)
                {
                    return(false);
                }
                catch (ArgumentException)
                {
                    return(false);
                }
                catch (InvalidOperationException)
                {
                    return(false);
                }
                catch (NotSupportedException)
                {
                    return(false);
                }
                catch (MimeException ex)
                {
                    error = ex.Message;
                    return(false);
                }
            }
            if (mimeDocument.ComplianceStatus != MimeComplianceStatus.Compliant)
            {
                error = Strings.MimeDoesNotComplyWithStandards;
                return(false);
            }
            return(true);
        }