コード例 #1
0
        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;
            }
        }
コード例 #2
0
            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);
            }