예제 #1
0
        private void NewItemFromMailButton_Click(object sender, RibbonControlEventArgs e)
        {
            if (_mailItem == null)
            {
                return;
            }

            EnsureSettingsValid();

            StringBuilder body = new StringBuilder(_mailItem.HTMLBody);

            foreach (Attachment attachment in _mailItem.Attachments)
            {
                var fileName = attachment.FileName;
                if (IsImageFileExtension(Path.GetExtension(fileName)))
                {
                    string attach_content_id = @"http://schemas.microsoft.com/mapi/proptag/0x3712001E";
                    var    contentId         = attachment.PropertyAccessor.GetProperty(attach_content_id);
                    if (body.ToString().IndexOf(string.Format("src=\"cid:{0}\"", contentId), StringComparison.OrdinalIgnoreCase) > 0)
                    {
                        var tempName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + Path.GetExtension(fileName));
                        attachment.SaveAsFile(tempName);
                        body.Replace(string.Format("src=\"cid:{0}\"", contentId), string.Format("src=\"file:///{0}\"", tempName));
                    }
                }
            }

            var settings = MySettingsManager.GetSettings <TfsSettings>();
            var fields   = new Dictionary <string, object>();

            fields.Add(settings.FieldRefNameForMailBody, body.ToString());
            UIHelper.OpenWorkItemForm(settings.WorkItemType, _mailItem.Subject, fields);
        }