protected override void ExecuteAction(IResource resource, PairIDs pairIDs) { Tracer._Trace("Execute action: DisplayMessageAction"); if (resource.HasProp(PROP.EmbeddedMessage)) { IEMessage message = new OutlookAttachment(resource).OpenEmbeddedMessage(); if (message != null) { using ( message ) { string path = Core.FileResourceManager.GetUniqueTempDirectory(); path = Path.Combine(path, SaveToMSGAction.GetFileName(resource) + ".msg"); message.SaveToMSG(path); try { Process.Start(path); } catch (Exception e) { Utils.DisplayException(e, "Can't open file"); } } } } else { if (pairIDs == null) { return; } new ResourceProxy(resource).SetPropAsync(Core.Props.IsUnread, false); OutlookFacadeHelper.DisplayMessage(pairIDs.EntryId, pairIDs.StoreId); } }
private void InsertOLEObjects(IResource res) { IResourceList attachments = res.GetLinksOfType(null, PROP.Attachment); foreach (IResource attach in attachments.ValidResources) { if (attach.GetIntProp(PROP.AttachMethod) == AttachMethod.ATTACH_OLE) { IEAttach att = new OutlookAttachment(attach).OpenAttach(); if (att == null) { return; } using ( att ) { int pos = att.GetLongProp(MAPIConst.PR_RENDERING_POSITION, true); if (pos != -9999) { try { att.InsertOLEIntoRTF(_editRtfBody.Handle.ToInt32(), pos); } catch (Exception exception) { Tracer._TraceException(exception); } } } } } }
public MailBodyDescriptor(IResource mail) { try { IEMessage message = null; if (mail.Type == STR.Email) { PairIDs IDs = PairIDs.Get(mail); if (IDs != null) { message = OutlookSession.OpenMessage(IDs.EntryId, IDs.StoreId); } else { message = new OutlookAttachment(mail).OpenEmbeddedMessage(); } } else if (mail.Type == STR.EmailFile) { message = OutlookSession.OpenEmailFile(mail); } if (message != null) { using ( message ) { _subject = message.GetStringProp(MAPIConst.PR_SUBJECT); MessageBody body = message.GetRawBodyAsRTF(); if (body.Format == MailBodyFormat.PlainTextInRTF || body.Format == MailBodyFormat.RTF) { _body = _rtfParser.Parse(body.text); } else { _body = body.text; } _isHTML = (body.Format == EMAPILib.MailBodyFormat.HTML); } } } catch (Exception exception) { Tracer._TraceException(exception); } if (_subject == null) { _subject = string.Empty; } if (_body == null) { _body = string.Empty; } }
private MessageBody ReadBody() { if (_mail.HasProp(PROP.EmbeddedMessage)) { OutlookAttachment attach = new OutlookAttachment(_mail); EMAPILib.IEMessage message = attach.OpenEmbeddedMessage(); if (message != null) { using ( message ) { return(message.GetRawBodyAsRTF()); } } return(null); } if (_mail.Type == STR.EmailFile) { IEMessage message = OutlookSession.OpenEmailFile(_mail); if (message != null) { using ( message ) { _subject = message.GetStringProp(MAPIConst.PR_SUBJECT); return(message.GetRawBodyAsRTF()); } } return(null); } PairIDs IDs = PairIDs.Get(_mail); if (IDs != null) { EMAPILib.IEMessage message = OutlookSession.OpenMessage(IDs.EntryId, IDs.StoreId); if (message != null) { using ( message ) { return(OutlookSession.GetMessageBody(message)); } } else { string bodyText = "Could not open message. It may have been moved or deleted in Outlook. Or message store for this mail cannot be open."; return(new MessageBody(bodyText, MailBodyFormat.PlainText, 0)); } } return(null); }
private void UpdateAttachments() { _tracer.Trace("prepare UpdateAttachments"); IResourceList attachments = Core.ResourceStore.FindResourcesWithProp(null, PROP.AttachmentIndex); int count = attachments.Count; int processed = 0; UpdateProgress(processed, count); int ticks = System.Environment.TickCount; foreach (IResource attach in attachments.ValidResources) { try { IEAttach attachment = new OutlookAttachment(attach).OpenAttach(); if (attachment == null) { continue; } using ( attachment ) { string contentID = attachment.GetStringProp(MAPIConst.PR_ATTACH_CONTENT_ID); int attachNum = attachment.GetLongProp(MAPIConst.PR_ATTACH_NUM); int attachMethod = attachment.GetLongProp(MAPIConst.PR_ATTACH_METHOD); ResourceProxy resAttach = new ResourceProxy(attach); resAttach.BeginUpdate(); resAttach.SetProp(CommonProps.ContentId, contentID); resAttach.SetProp(PROP.PR_ATTACH_NUM, attachNum); resAttach.SetProp(PROP.AttachMethod, attachMethod); resAttach.EndUpdateAsync(); } } catch {} ++processed; if (System.Environment.TickCount - ticks > 250) { ticks = System.Environment.TickCount; UpdateProgress(processed, count); } } }
public void Unpack(IResource attachment) { try { OutlookAttachment att = GetAttachment(attachment); string fullFileName = Path.Combine(Path.GetTempPath(), ResourceSerializer.ResourceTransferFileName); att.SaveAs(fullFileName); IResource mail = (IResource)attachment.GetProp(PROP.InternalAttachment); ReceiveResourcesDialog dialog = new ReceiveResourcesDialog(fullFileName, mail); File.Delete(fullFileName); dialog.ShowDialog(); } catch (Exception exception) { Tracer._TraceException(exception); MsgBox.Error("Outlook plugin", "Impossible to unpack resources after transfer\n" + exception.Message); return; } }