Ejemplo n.º 1
0
 static bool IsAttachmentInline(MapiAttachment attachment)
 {
     foreach (MapiProperty property in attachment.ObjectData.Properties.Values)
     {
         if (property.Name == "\x0003ObjInfo")
         {
             ushort odtPersist1 = BitConverter.ToUInt16(property.Data, 0);
             return((odtPersist1 & (1 << (7 - 1))) == 0);
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
 static void SaveAttachment(MapiAttachment attachment, string fileName)
 {
     foreach (MapiProperty property in attachment.ObjectData.Properties.Values)
     {
         if (property.Name == "Package")
         {
             using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
             {
                 fs.Write(property.Data, 0, property.Data.Length);
             }
         }
     }
 }
        public static void Run()
        {
            string         dataDir    = RunExamples.GetDataDir_Outlook();
            MapiMessage    message    = MapiMessage.FromFile(dataDir + "messageWithEmbeddedEML.msg");
            MapiAttachment attachment = message.Attachments[0];

            // ExStart:GetNestedMailMessageAttachments
            // Create a MapiMessage object from the individual attachment
            MapiMessage getAttachment = MapiMessage.FromProperties(attachment.ObjectData.Properties);

            // Create object of type MailMessageImterpretor from the above message and Save the embedded message to file at disk
            MailMessage mailMessage = getAttachment.ToMailMessage(new MailConversionOptions());

            mailMessage.Save(dataDir + @"NestedMailMessageAttachments_out.eml", SaveOptions.DefaultEml);
            // ExEnd:GetNestedMailMessageAttachments
        }
        public static bool IsInlineAttachment(MapiAttachment att, MapiMessage msg)
        {
            switch (msg.BodyType)
            {
                case BodyContentType.PlainText:
                    // ignore indications for plain text messages
                    return false;

                case BodyContentType.Html:

                    // check the PidTagAttachFlags property
                    if (att.Properties.Contains(0x37140003))
                    {
                        long? attachFlagsValue = att.GetPropertyLong(0x37140003);
                        if (attachFlagsValue != null && (attachFlagsValue & 0x00000004) == 0x00000004)
                        {
                            // check PidTagAttachContentId property
                            if (att.Properties.Contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID) ||
                                att.Properties.Contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W))
                            {
                                string contentId = att.Properties.Contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID)
                                    ? att.Properties[MapiPropertyTag.PR_ATTACH_CONTENT_ID].GetString()
                                    : att.Properties[MapiPropertyTag.PR_ATTACH_CONTENT_ID_W].GetString();
                                if (msg.BodyHtml.Contains(contentId))
                                {
                                    return true;
                                }
                            }
                            // check PidTagAttachContentLocation property
                            if (att.Properties.Contains(0x3713001E) ||
                                att.Properties.Contains(0x3713001F))
                            {
                                return true;
                            }
                        }
                        else if ((att.Properties.Contains(0x3716001F) && att.GetPropertyString(0x3716001F) == "inline")
                            || (att.Properties.Contains(0x3716001E) && att.GetPropertyString(0x3716001E) == "inline"))
                        {
                            return true;
                        }
                    }
                    else if ((att.Properties.Contains(0x3716001F) && att.GetPropertyString(0x3716001F) == "inline")
                            || (att.Properties.Contains(0x3716001E) && att.GetPropertyString(0x3716001E) == "inline"))
                    {
                        return true;
                    }
                    return false;

                case BodyContentType.Rtf:

                    // If the body is RTF, then all OLE attachments are inline attachments.
                    // OLE attachments have 0x00000006 for the value of the PidTagAttachMethod property
                    if (att.Properties.Contains(MapiPropertyTag.PR_ATTACH_METHOD))
                    {
                        return att.GetPropertyLong(MapiPropertyTag.PR_ATTACH_METHOD) == 0x00000006;
                    }
                    return false;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 5
0
        public static bool IsInlineAttachment(MapiAttachment att, MapiMessage msg)
        {
            switch (msg.BodyType)
            {
            case BodyContentType.PlainText:
                // ignore indications for plain text messages
                return(false);

            case BodyContentType.Html:

                // check the PidTagAttachFlags property
                if (att.Properties.ContainsKey(0x37140003))
                {
                    long?attachFlagsValue = att.GetPropertyLong(0x37140003);
                    if (attachFlagsValue != null && (attachFlagsValue & 0x00000004) == 0x00000004)
                    {
                        // check PidTagAttachContentId property
                        if (att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID) ||
                            att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W))
                        {
                            string contentId = att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID)
                                    ? att.Properties[MapiPropertyTag.PR_ATTACH_CONTENT_ID].GetString()
                                    : att.Properties[MapiPropertyTag.PR_ATTACH_CONTENT_ID_W].GetString();
                            if (msg.BodyHtml.Contains(contentId))
                            {
                                return(true);
                            }
                        }
                        // check PidTagAttachContentLocation property
                        if (att.Properties.ContainsKey(0x3713001E) ||
                            att.Properties.ContainsKey(0x3713001F))
                        {
                            return(true);
                        }
                    }
                    else if ((att.Properties.ContainsKey(0x3716001F) && att.GetPropertyString(0x3716001F) == "inline") ||
                             (att.Properties.ContainsKey(0x3716001E) && att.GetPropertyString(0x3716001E) == "inline"))
                    {
                        return(true);
                    }
                }
                else if ((att.Properties.ContainsKey(0x3716001F) && att.GetPropertyString(0x3716001F) == "inline") ||
                         (att.Properties.ContainsKey(0x3716001E) && att.GetPropertyString(0x3716001E) == "inline"))
                {
                    return(true);
                }
                return(false);

            case BodyContentType.Rtf:

                // If the body is RTF, then all OLE attachments are inline attachments.
                // OLE attachments have 0x00000006 for the value of the PidTagAttachMethod property
                if (att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_METHOD))
                {
                    return(att.GetPropertyLong(MapiPropertyTag.PR_ATTACH_METHOD) == 0x00000006);
                }
                return(false);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 /// <summary>
 /// Set content id to attachment
 /// </summary>
 /// <param name="attach"></param>
 /// <param name="id"></param>
 public static void SetContentId(this MapiAttachment attach, object id)
 {
     attach.SetProperty(KnownPropertyList.AttachContentId, id);
 }
 /// <summary>
 /// Get Content Id from attachment
 /// </summary>
 /// <param name="attach"></param>
 public static string GetContentId(this MapiAttachment attach)
 {
     return(attach.GetPropertyString(KnownPropertyList.AttachContentId.Tag));
 }