【问题标题】:Get read-receipt with MailKit with Microsoft anti-spam enabled使用启用了 Microsoft 反垃圾邮件的 MailKit 获取已读回执
【发布时间】:2022-08-15 00:21:07
【问题描述】:

我正在使用 IMAP 连接到 Office 365 邮件服务器。 我们的系统管理员启用了反垃圾邮件,因此任何从外部收到的邮件都会被转换:我们只收到转发邮件而不是原始邮件。

使用 Thunderbird 或 Outlook Web Access,我可以将原始邮件视为附加的 EML 文件。

但是当我尝试解析邮件中的附件时,我在这些邮件中找不到附件。如果我收到一封带有真实附件的电子邮件,我可以找到它作为附件。

我尝试使用 message.ToString() 来获取我收到的完整消息:

Received: from *****.prod.outlook.com (*****)
 by *****.prod.outlook.com with HTTPS; Thu, 11 Aug 2022
 13:37:42 +0000
Received: from *****.PROD.OUTLOOK.COM (*****) by
 *****.prod.outlook.com (*****) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.23; Thu, 11 Aug
 2022 13:37:41 +0000
Received: from *****.prod.protection.outlook.com
 (*****) by *****.outlook.office365.com
 (*****) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11 via Frontend
 Transport; Thu, 11 Aug 2022 13:37:41 +0000
Authentication-Results: spf=none (sender IP is *****)
 smtp.helo=*****.aznetwork.eu; dkim=none (message not signed)
 header.d=none;dmarc=none action=none header.from=aznetwork.eu;compauth=pass
 reason=105
Received-SPF: None (protection.outlook.com: *****.aznetwork.eu does not
 designate permitted sender hosts)
Received: from *****.aznetwork.eu (*****) by
 *****.mail.protection.outlook.com (*****) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.5525.11 via Frontend Transport; Thu, 11 Aug 2022 13:37:41 +0000
Received: from localhost (localhost.localdomain [127.0.0.1])
    by *****.aznetwork.eu (Postfix) with ESMTP id 053BC1C631E
    for <recipient@mail.com>; Thu, 11 Aug 2022 15:37:41 +0200 (CEST)
Received: from *****.aznetwork.eu ([127.0.0.1])
    by localhost (*****.aznetwork.eu [127.0.0.1]) (amavisd-new, port 10032)
    with ESMTP id Tin75ip0CVd1 for <recipient@mail.com>;
    Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Received: from localhost (localhost.localdomain [127.0.0.1])
    by *****.aznetwork.eu (Postfix) with ESMTP id B55251C6446
    for <recipient@mail.com>; Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
X-Virus-Scanned: amavisd-new at *****.aznetwork.eu
Received: from *****.aznetwork.eu ([127.0.0.1])
    by localhost (*****.aznetwork.eu [127.0.0.1]) (amavisd-new, port 10026)
    with ESMTP id 4lpOVXL1yFKw for <recipient@mail.com>;
    Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Received: from *****.aznetwork.eu (*****.aznetwork.priv [*****])
    by *****.aznetwork.eu (Postfix) with ESMTP id 9E4CB1C631E
    for <recipient@mail.com>; Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Date: Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
From: Sender Name <sender@mail.com>
To: recipient@mail.com
Message-ID: <1682353652.2846324.1660225060639.JavaMail.zimbra@aznetwork.eu>
Subject: [EXTERNE]  Read-Receipt: Mail Subject
Auto-Submitted: auto-replied (zimbra; read-receipt)
Precedence: bulk
Return-Path: <>
X-MS-Exchange-Organization-ExpirationStartTime: 11 Aug 2022 13:37:41.4732
 (UTC)
X-MS-Exchange-Organization-ExpirationStartTimeReason: OriginalSubmit
X-MS-Exchange-Organization-ExpirationInterval: 1:00:00:00.0000000
X-MS-Exchange-Organization-ExpirationIntervalReason: OriginalSubmit
X-MS-Exchange-Organization-Network-Message-Id:
 384141c3-c532-4391-771a-08da7b9eaa12
X-EOPAttributedMessage: 0
X-EOPTenantAttributedMessage: 873b62a6-6fcf-467d-8380-ce41a1d6da9f:0
X-MS-Exchange-Organization-MessageDirectionality: Incoming
X-MS-PublicTrafficType: Email
X-MS-Exchange-Organization-AuthSource:
 *****.prod.protection.outlook.com
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Office365-Filtering-Correlation-Id: 384141c3-c532-4391-771a-08da7b9eaa12
X-MS-TrafficTypeDiagnostic: AM9PR02MB7641:EE_
Content-Type: multipart/mixed;
    boundary=\"_16f20566-32fe-437d-8fb6-e2fcbadabd01_\"
X-MS-Exchange-Organization-SCL: 1
X-Microsoft-Antispam: BCL:0;
X-Forefront-Antispam-Report:
 CIP:*****;CTRY:FR;LANG:fr;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:*****.aznetwork.eu;PTR:*****.aznetwork.eu;CAT:NONE;SFS:(13230016)(36756003)(7696005)(6266002)(26005)(564344004)(356005)(7636003)(336012)(426003)(2616005)(66574015)(42882007)(83380400001)(78352004)(5660300002)(8676002)(6916009)(1096003);DIR:INB;
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2022 13:37:41.3795
 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 384141c3-c532-4391-771a-08da7b9eaa12
X-MS-Exchange-CrossTenant-Id: 873b62a6-6fcf-467d-8380-ce41a1d6da9f
X-MS-Exchange-CrossTenant-AuthSource:
 *****.prod.protection.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: Internet
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR02MB7641
X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.2537846
X-MS-Exchange-Processed-By-BccFoldering: 15.20.5525.010
X-Microsoft-Antispam-Mailbox-Delivery:
    ucf:0;jmr:0;auth:0;dest:I;ENG:(910001)(944506458)(944626604)(920097)(930097);
X-Microsoft-Antispam-Message-Info:
    =?iso-8859-1?somebase64data=
MIME-Version: 1.0

--_16f20566-32fe-437d-8fb6-e2fcbadabd01_
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: quoted-printable

ATTENTION: Ce message est originaire de l\'ext=E9rieur de ***. Ne pas clique=
r sur les liens internet ou ouvrir les pi=E8ces jointes =E0 moins que vous =
ne connaissiez l\'auteur ou sachiez que le contenu est sain (pas de virus).





--_16f20566-32fe-437d-8fb6-e2fcbadabd01_
Content-Type: message/rfc822

X-MS-Exchange-Organization-InternalOrgSender: True
Received: from *****.PROD.OUTLOOK.COM (*****) by
 *****.prod.outlook.com (*****) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.23; Thu, 11 Aug
 2022 13:37:41 +0000
Received: from *****.prod.protection.outlook.com
 (*****) by *****.outlook.office365.com
 (*****) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11 via Frontend
 Transport; Thu, 11 Aug 2022 13:37:41 +0000
Authentication-Results: spf=none (sender IP is *****)
 smtp.helo=*****.aznetwork.eu; dkim=none (message not signed)
 header.d=none;dmarc=none action=none header.from=aznetwork.eu;
Received-SPF: None (protection.outlook.com: *****.aznetwork.eu does not
 designate permitted sender hosts)
Received: from *****.aznetwork.eu (*****) by
 *****.mail.protection.outlook.com (*****) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.5525.11 via Frontend Transport; Thu, 11 Aug 2022 13:37:41 +0000
Received: from localhost (localhost.localdomain [127.0.0.1])
    by *****.aznetwork.eu (Postfix) with ESMTP id 053BC1C631E
    for <recipient@mail.com>; Thu, 11 Aug 2022 15:37:41 +0200 (CEST)
Received: from *****.aznetwork.eu ([127.0.0.1])
    by localhost (*****.aznetwork.eu [127.0.0.1]) (amavisd-new, port 10032)
    with ESMTP id Tin75ip0CVd1 for <recipient@mail.com>;
    Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Received: from localhost (localhost.localdomain [127.0.0.1])
    by *****.aznetwork.eu (Postfix) with ESMTP id B55251C6446
    for <recipient@mail.com>; Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
X-Virus-Scanned: amavisd-new at *****.aznetwork.eu
Received: from *****.aznetwork.eu ([127.0.0.1])
    by localhost (*****.aznetwork.eu [127.0.0.1]) (amavisd-new, port 10026)
    with ESMTP id 4lpOVXL1yFKw for <recipient@mail.com>;
    Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Received: from *****.aznetwork.eu (*****.aznetwork.priv [*****])
    by *****.aznetwork.eu (Postfix) with ESMTP id 9E4CB1C631E
    for <recipient@mail.com>; Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
Date: Thu, 11 Aug 2022 15:37:40 +0200 (CEST)
From: Sylvain DEVIDAL <sender@mail.com>
To: recipient@mail.com
Message-ID: <1682353652.2846324.1660225060639.JavaMail.zimbra@aznetwork.eu>
Subject: [EXTERNE]  Read-Receipt: Mail Subject
Content-Type: multipart/report; 
    boundary=\"----=_Part_2846322_558173291.1660225060636\"; report-type=disposition-notification
Auto-Submitted: auto-replied (zimbra; read-receipt)
Precedence: bulk
Return-Path: <>
X-MS-Exchange-Organization-OriginalArrivalTime: 11 Aug 2022 13:37:41.3795
 (UTC)
X-MS-Exchange-Organization-ExpirationStartTime: 11 Aug 2022 13:37:41.4732
 (UTC)
X-MS-Exchange-Organization-ExpirationStartTimeReason: OriginalSubmit
X-MS-Exchange-Organization-ExpirationInterval: 1:00:00:00.0000000
X-MS-Exchange-Organization-ExpirationIntervalReason: OriginalSubmit
X-MS-Exchange-Organization-Network-Message-Id:
 384141c3-c532-4391-771a-08da7b9eaa12
X-MS-Exchange-Organization-OriginalClientIPAddress: *****
X-MS-Exchange-Organization-OriginalServerIPAddress: *****
X-EOPAttributedMessage: 0
X-EOPTenantAttributedMessage: 873b62a6-6fcf-467d-8380-ce41a1d6da9f:0
X-MS-Exchange-Organization-TargetResourceForest: *****.prod.outlook.com
X-MS-Exchange-Organization-OrgEopForest: EUR01
X-MS-Exchange-Organization-MessageDirectionality: Incoming
X-MS-Exchange-Organization-Id: 873b62a6-6fcf-467d-8380-ce41a1d6da9f
X-MS-Exchange-Organization-FFO-ServiceTag: EUR01B
X-MS-Exchange-Organization-Cross-Premises-Headers-Processed:
 *****.prod.protection.outlook.com
X-MS-Exchange-Organization-ConnectingIP: *****
X-MS-Exchange-Organization-ConnectingEHLO: *****.aznetwork.eu
X-MS-Exchange-Organization-AS-LastExternalIp: *****
X-MS-Exchange-Organization-Originating-Country: FR
X-MS-Exchange-Organization-OriginalEnvelopeRecipients: recipient@mail.com
X-MS-Exchange-Organization-PtrDomains: *****.aznetwork.eu
X-MS-Exchange-Organization-EhloAndPtrDomain:
 *****.aznetwork.eu;*****.aznetwork.eu
X-MS-Exchange-Organization-MxPointsToUs: true
X-MS-Exchange-Organization-RecipientMxInfo-PFAFD:
 recipientdomain.com#*****.mail.protection.outlook.com
X-MS-Exchange-Organization-CompAuthRes: pass
X-MS-Exchange-Organization-CompAuthReason: 105
X-MS-Exchange-Organization-SpoofDetection-Frontdoor-DisplayDomainName:
 aznetwork.eu
X-MS-Exchange-Organization-Auth-ExtendedDmarcStatus: Pass
X-MS-Exchange-Organization-SenderRep-Score: 3
X-MS-Exchange-Organization-SenderRep-Data:
 IpClassSmallGrayBest_SmallGrayBest_unknown
X-MS-Exchange-Organization-VBR-Class: SmallGrayBest
X-MS-Exchange-Organization-HMATPModel-Spf: 5
X-MS-Exchange-Organization-HMATPModel-Recipient:
 *****
X-MS-Exchange-Organization-TransportTrafficType: Email
X-MS-PublicTrafficType: Email
X-MS-Exchange-Organization-OrderedPrecisionLatencyInProgress:
 LSRV=*****.PROD.OUTLOOK.COM:TOTAL-FE=0.093|SMR-PEN=0.082(RENV=0.068);2022-08-11T13:37:41.721Z
X-MS-Exchange-Organization-MessageLatency:
 SRV=*****.eop-EUR01.prod.protection.outlook.com:TOTAL-FE=0.247|SMR-PEN=0.221(RENV=0.031(SMRRC=0.029(SMRRC-TenantAttributionAndInboundConnectorAgent=0.026
 ))|REOH=0.189(SMREH=0.127(SMREH-Protocol Filter Agent=0.124)))|SMS=0.029
X-MS-Exchange-Organization-MessageLatency:
 SRV=*****.PROD.OUTLOOK.COM:TOTAL-FE=0.116|SMR-PEN=0.082(RENV=0.068)|SMS=0.023(SMSC=0.033)
X-MS-Exchange-Forest-ArrivalHubServer: *****.prod.outlook.com
X-MS-Exchange-Organization-AuthSource:
 *****.prod.protection.outlook.com
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-FromEntityHeader: Internet
X-MS-Exchange-Organization-MessageScope: 7ca5d36b-aa6e-4988-8ce2-ebc9e7a7fc2a
X-MS-Exchange-Forest-MessageScope: 7ca5d36b-aa6e-4988-8ce2-ebc9e7a7fc2a
X-MS-Exchange-Organization-Antispam-ProtocolFilterHub-ScanContext:
 ProtocolFilterHub:SmtpOnEndOfData;
X-MS-Office365-Filtering-Correlation-Id: 384141c3-c532-4391-771a-08da7b9eaa12
X-MS-Exchange-Organization-P2SenderDisplayNamePII:
 H101(Oo2uoTVO0nYrZjTS6UNDuqjuYq+ejtD0u3d/6RR1MgI=)
X-MS-Exchange-Organization-P2SenderPII:
 *****
X-MS-Exchange-Organization-PFAHub-Total-Message-Size: 9121
X-MS-Exchange-Organization-OriginalSize: 9121
X-MS-TrafficTypeDiagnostic: AM9PR02MB7641:EE_
X-MS-Exchange-Organization-HygienePolicy: Premium
X-MS-Exchange-Organization-ReplicationInfo:
 ReplicaId=9de80d70-aee0-b1f9-8fed-3baa9e7bda08;ReplicatingServerFqdn=*****.eurprd02.prod.outlook.com
X-MS-Exchange-Forest-Language: fr
X-MS-Exchange-Forest-IndexAgent-0:
 Somebase64data=
X-MS-Exchange-Forest-IndexAgent: 1 833
X-MS-Exchange-Forest-EmailMessageHash: 6E6C2B22,31F80CB7
X-MS-Exchange-Organization-PhishSim-Rules-Execution-History:
 336d57ef-0937-4345-9ee7-7488d99e1eee
X-MS-Exchange-Organization-Antispam-PreContentFilter-PolicyLoadTime:
 PSOSUB:6;PSOSUBLOAD:5;PSOSUBRUN:0;PSOSUBCOUNT:1;SMORES:2;SMORESLOAD:1;SMORESRUN:0;SMORESCOUNT:0;SAORES:4;SAORESLOAD:1;SLORES:2;APORES:22;APORESLOAD:1;APORESRUN:20;APORESCOUNT:2;RSORES:1;SLORESLOAD:1;
X-MS-Exchange-Organization-AttachmentDetailsHeaderStamp-Success: 1.0
X-MS-Exchange-Organization-AttachmentDetails:
 0:EpUTydEBwSuS9oq8FNAFHYcMPGvyaOa9tpBsGPTlB4k=:U:Text:QVRUMDAwMDQ=::#:False:::N:::N::N:None:
X-MS-Exchange-Organization-MessageFingerprint:
 A0DBCBFD.2F1B0759.C2DDF092.B4130E24.200A4
X-MS-Exchange-Organization-AttachmentDetailsInfo-ChunkCount: 1
X-MS-Exchange-Organization-AttachmentDetailsInfo-0:
 [{\"ID\":0,\"FS\":308,\"HFH\":\"EpUTydEBwSuS9oq8FNAFHYcMPGvyaOa9tpBsGPTlB4k=\",\"FE\":\"\",\"CEXT\":[],\"CFT\":[],\"AF\":0,\"AFT\":\"{784:\\\"ATT00004\\\",789:\\\"text\\\"}\"}]
X-MS-Exchange-Organization-FeatureTable:
 {385:\"aznetwork.eu\",452:1,453:1,454:\"4A71A110@kp1.fr\",504:7,506:4,507:5,508:\"none\",509:\"aznetwork.eu\",510:\"*****.aznetwork.eu\",651:2,653:1,656:1,721:\"2.37\",722:\"2.35\",742:1,743:3,744:1,748:\"sign\",749:\"Latn\",758:\"A0DBC8FE.2F5B0759.F0DDB08F.A01F8E26.20082\",781:1,782:8,1010:0,1011:\"1830FF39|60572074|\",1101:\"0.194\"}
X-MS-Exchange-Organization-MetadataFeatureTable:
 {756:0,757:0,1010:0,1011:\"1830FF39|60572074|\",1036:\"199167\"}
X-MS-Exchange-Organization-Antispam-PreContentFilter-ScanContext:
 CategorizerOnSubmitted;CategorizerOnResolved;
X-MS-Exchange-Organization-AVScannedByV2: true
X-MS-Exchange-Organization-AVScanComplete: true
X-MS-Exchange-Organization-ExternalRoutingTopologyAnalysis:
X-MS-Exchange-Organization-Recipient-Limit-Verified: True
X-MS-Exchange-Organization-TotalRecipientCount: 1
X-MS-Exchange-Organization-HVERecipientsForked: 1.0
X-MS-Exchange-Organization-AntiPhishPolicy: Default_kp1
X-MS-Exchange-Organization-ASDirectionalityType: 1
X-MS-Exchange-Organization-Boomerang-Verdict: None
X-MS-Exchange-Organization-HMATPModel-DkimAuthStatus: 7
X-MS-Exchange-Organization-HMATPModel-DmarcAuthStatus: 4
X-MS-Exchange-Organization-Cross-Session-Cache:
 =?utf-8?somebase64data=
X-MS-Exchange-Organization-Cross-Session-Cache:
 01xSupported=1;TMD_SS=1;TMD_AOT=3433;TMD_CSUM=5377;TMD_DTAET=1;TMD_ES=0;TMD_TT=0;TMD_DMNSPM=8914;TMD_DMSPM=338;TMD_PSATP=0;TMD_PS=1939;TMD_SCNT=5;TMD_TSATP=0;TMD_TS=0;TMD_ATPP2=False;TMD_CI=fr-FR;TMD_CD=2013-03-15
 09:53:51.000;TMD_NEWT=0;TMD_NEWTT=0;TMD_QS=1;TR_SS=1;TR_SMAS=0;TR_TMAS=0;TR_UMAS=0;TR_TTU24H=0;TR_TT24H=0;TR_AFWR24H=18;TR_NDRSPMR24H=0;TR_R1H=315;TR_R24H=2709;TR_SPMR1H=0;TR_SPMR24H=0;TR_UP1R1H=0;TR_UP1R24H=0;TR_UP1SPMR24H=0;TR_QS=1;BR_V=None;DIR=1;PTRO=aznetwork.eu;P2O=aznetwork.eu;P_CAUTH=pass;P_CAUTHR=105;SIP2BCLAP=-1;SIP2BCLAF=-1;P2BCL=
X-MS-Exchange-Organization-Rules-Execution-History:
 95544e5a-848e-428b-b1a3-43568aa659bf%%%5a9c7fc7-bc74-434e-81a5-8fe8f957dcbb%%%22b9f62e-47d3-4bb9-87f7-b1c42aa1f5e3%%%79dacf70-5b24-4672-8325-97733f56b4e3%%%572c1ac3-7cd0-4e7c-8a3b-99003d82e392
MIME-Version: 1.0

------=_Part_2846322_558173291.1660225060636
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Le mail envoy=C3=A9 le 11 ao=C3=BBt 2022 =C3=A0 15:37:26 GMT+02:00 au desti=
nataire sender@mail.com avec l=E2=80=99objet \"Mail=
subject\" a =C3=A9t=C3=A9 affich=C3=A9. Cela ne signifie aucunement =
que ce mail ait =C3=A9t=C3=A9 lu (ou compris).=

------=_Part_2846322_558173291.1660225060636
Content-Type: message/disposition-notification; charset=utf-8
Content-Transfer-Encoding: 7bit

Reporting-UA: 78.252.48.37; ZimbraWebClient - GC104 (Win)/8.8.15_GA_4257
Original-Recipient: rfc822;sender@mail.com
Final-Recipient: rfc822;sender@mail.com
Original-Message-ID: <YA0XNMBBLHU4.N87S2N70CKU81@dev-crm22-upd1>
Disposition: manual-action/MDN-sent-manually; displayed

------=_Part_2846322_558173291.1660225060636--

--_16f20566-32fe-437d-8fb6-e2fcbadabd01_--

(对不起,长代码)

您可以在第 147 行看到它实际上包含原始消息,类型为 \"report\"(它是一个已读回执)。

但无论我尝试什么,我都无法解析它。

这是我当前的代码:(如果从邮箱加载,则消息 id 是我加载的邮件消息)

public static void ProcessReadReceiptNotification(MimeMessage message)
        {
            /// This part is the \"standard way\" to find a read-reciept, but it doesn\'t work
            var report = message.Body as MultipartReport;
            if (report == null || report.ReportType == null || !report.ReportType.Equals(\"disposition-notification\", StringComparison.OrdinalIgnoreCase))
            {
                // this is not a read receipt notification message...
                Console.WriteLine(\"this is not a read receipt notification message... will parse parts\");

                /// Then I tried to iterate all parts of the mail then load the message
                foreach (MimeEntity part in message.BodyParts)
                {
                    Console.WriteLine($\"A part of type {part.ContentType.MimeType} is found\");

                    if (part.ContentType.MimeType == \"message/rfc822\")
                    {
                        /// Here part.Message private property contains the message
                        Console.WriteLine(\"This is a message, we load it\");
                        using MemoryStream ms = new();
                        part.WriteTo(ms);
                        ms.Seek(0, SeekOrigin.Begin);
                        MimeMessage msg = MimeMessage.Load(ms);
                        /// Here my msg object is empty, or at least doesn\'t contain message data (subject, body, etc.)

                        //Console.WriteLine(msg.Body.ToString());
                        report = msg.Body as MultipartReport;
                        Console.WriteLine(report?.ToString());
                        /*
                        return ProcessReadReceiptNotification(msg);
                        */
                    }
                }
                Console.Write(\"Nothing found...\");
                return;
            }
            else
            {
                Console.WriteLine($\"Report Type : {report.ReportType}\");

                // process the report
                foreach (var mds in report.OfType<MessageDispositionNotification>())
                {
                    Console.WriteLine($\"{mds.Content}\");
                    var messageId = mds.Fields.Single(a => a.Field == \"Original-Message-ID\");
                    if (messageId is not null)
                    {
                        Console.Write($\"Le message {messageId.Value}\");
                    }
                    var readStatus = mds.Fields.Single(a => a.Field == \"Disposition\");
                    if (readStatus is not null)
                    {
                        var index = readStatus.Value.IndexOf(\";\");
                        Console.WriteLine($\" a été {readStatus.Value.Substring(index + 1)}.\");
                    }
                    return;
                }
                return;
            }
        }

我如何加载此正文部分并识别其已读回执(带有原始消息 ID)?

我发现在part.Message 私有属性中可以看到原始消息。但我无法访问它。 part.WriteTo(ms) 不会复制邮件。

    标签: c# imap mailkit


    【解决方案1】:

    我终于找到了如何阅读原始消息。

    而不是将零件加载为MimeMessage,我只需将其加载为MultipartReport...

    foreach (MimeEntity part in message.BodyParts)
                    {
                        Console.WriteLine($"A part of type {part.ContentType.MimeType} is found");
    
                        if (part.ContentType.MimeType == "message/rfc822")
                        {
                            Console.WriteLine("This is a message, we load it");
                            using MemoryStream ms = new();
                            part.WriteTo(ms, true);
                            ms.Seek(0, SeekOrigin.Begin);
                            report = MimeEntity.Load(ms) as MultipartReport;
                            Console.WriteLine(report?.ToString());
                        }
                    }
    

    【讨论】:

      【解决方案2】:

      无需将内容写入流,只是为了再次重新解析它。

      您需要做的就是:

      foreach (MimeEntity part in message.BodyParts)
      {
          Console.WriteLine($"A part of type {part.ContentType.MimeType} is found");
      
          // MessageParts are message/rfc822 (or equivalent such as message/news
          // or message/global which is the UTF-8 version of message/rfc822)
          //
          // Never use case-sensitive string comparisons like
          // part.ContentType.MimeType == "message/rfc822" because MIME does not
          // restrict things to lowercase. Instead, the recommended way of checking
          // for an exact mime-type is part.ContentType.IsMimeType("message", "rfc822")
          // or
          // part.ContentType.MimeType.Equals("message/rfc822", StringComparison.OrdinalIgnoreCase).
          if (part is MessagePart rfc822)
          {
              Console.WriteLine("This is a message, lets see if the body is a multipart/report");
              if (rfc822.Body is MultipartReport report)
              {
                  // handle the multipart/report which is already in a parsed state
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-23
        • 2014-05-19
        • 1970-01-01
        • 2011-01-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多