Ejemplo n.º 1
0
        public ArrayList ExtractAttachments(MimeEntryCollection MimeEntries)
        {
            ArrayList _tmpAttachs = new ArrayList();

            foreach (MimeEntry entry in MimeEntries)
            {
                if (entry.ContentDisposition == Disposition.Attachment ||
                    entry.ContentDisposition == Disposition.Inline ||
                    entry.ContentType == "message/rfc822" ||                                                   // OZ: Fix Attached Email Problem
                    entry.ContentType == "application/ms-tnef" ||                                              // OZ: Fix Attached Wimmail.dat
                    entry.ContentType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase) ||     // OZ: Show attached image with out ContentDisposition
                    entry.ContentType.StartsWith("application/", StringComparison.InvariantCultureIgnoreCase)) // OZ: Fixed problem with attached file without Disposition.Attachment
                {
                    //if (entry.ContentType.StartsWith("text/html"))
                    //    continue;

                    string fileName = GetFileName(entry);

                    if (entry.ContentType == "application/ms-tnef")
                    {
                        TnefParser tnefParser = new TnefParser(entry.Body);

                        if (tnefParser.Parse())
                        {
                            _tmpAttachs.AddRange(tnefParser.Attachments);
                        }
                        else
                        {
                            AttachmentInfo att = new AttachmentInfo(fileName, entry.ContentType, entry.Body.Length);
                            att.Headers.Add(entry.Headers);
                            _tmpAttachs.Add(att);
                        }
                        // TODO: Parse tnef entry
                    }
                    else
                    {
                        AttachmentInfo att = new AttachmentInfo(fileName, entry.ContentType, entry.Body.Length);
                        att.Headers.Add(entry.Headers);
                        _tmpAttachs.Add(att);
                    }
                }

                if (entry.MimeEntries.Count > 0)
                {
                    _tmpAttachs.AddRange(ExtractAttachments(entry.MimeEntries));
                }
            }

            return(_tmpAttachs);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the attachment.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public static AttachmentData GetAttachment(MimeEntryCollection MimeEntries, ref int index)
        {
            foreach (MimeEntry entry in MimeEntries)
            {
                if (entry.ContentDisposition == Disposition.Attachment ||
                    entry.ContentDisposition == Disposition.Inline ||
                    entry.ContentType == "message/rfc822" ||
                    entry.ContentType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase))                     // OZ: Show attached image with out ContentDisposition
                {
                    //if (entry.ContentType.StartsWith("text/html"))
                    //    continue;

                    if (entry.ContentType == "application/ms-tnef")
                    {
                        TnefParser tnefParser = new TnefParser(entry.Body);

                        if (tnefParser.Parse())
                        {
                            int thefAttachCount = tnefParser.Attachments.Length;

                            if (thefAttachCount > index)
                            {
                                AttachmentData retVal = new AttachmentData();

                                retVal.FileName    = tnefParser.Attachments[index].FileName;
                                retVal.ContentType = tnefParser.Attachments[index].ContentType;
                                retVal.Data        = tnefParser.GetAttachmentBody(index);

                                return(retVal);
                            }

                            index -= (thefAttachCount - 1);
                        }
                        else
                        {
                            if (index == 0)
                            {
                                return(AttachmentData.Create(entry));
                            }
                            index--;
                        }
                    }
                    else
                    {
                        if (index == 0)
                        {
                            return(AttachmentData.Create(entry));
                        }
                        index--;
                    }
                }

                if (entry.MimeEntries.Count > 0)
                {
                    AttachmentData retVal = GetAttachment(entry.MimeEntries, ref index);
                    if (retVal != null)
                    {
                        return(retVal);
                    }
                }
            }

            return(null);
        }