Beispiel #1
0
        public MultipartReport Build()
        {
            // Initiate multipart

            var multipart = new MultipartReport("disposition-notification");

            // Insert text part
            var textPart = new TextPart();

            textPart.ContentTransferEncoding = ContentEncoding.SevenBit;
            textPart.SetText(Encoding.ASCII, this.sw.ToString());
            textPart.ContentTransferEncoding = ContentEncoding.SevenBit;
            multipart.Add(textPart);

            // Insert header part
            var headerPart = new MessageDispositionNotification();

            headerPart.ContentTransferEncoding = ContentEncoding.Default;
            foreach (var header in this.headers)
            {
                headerPart.Fields.Add(header);
            }
            headerPart.ContentTransferEncoding = ContentEncoding.SevenBit;
            multipart.Add(headerPart);
            return(multipart);
        }
Beispiel #2
0
        protected void WriteMdn(HttpResponse response, MimeMessage mdn, int status)
        {
            response.StatusCode = status;

            foreach (var header in mdn.Headers)
            {
                response.Headers.Add(header.Field, header.Value);
            }

            var contentType = ((MultipartSigned)mdn.Body).Headers[HeaderId.ContentType];

            response.Headers.Add("Content-Type", this.NormalizeHeaderValue(contentType));

            // Write MDN to response without header names.
            // Force 7bit encoding in MIME Response
            MultipartSigned mSigned = mdn.Body as MultipartSigned;

            Debug.Assert(mSigned != null, nameof(mSigned) + " != null");
            MultipartReport mReport = mSigned[0] as MultipartReport;

            Debug.Assert(mReport != null, nameof(mReport) + " != null");
            TextPart textReport = mReport[0] as TextPart;

            Debug.Assert(textReport != null, nameof(textReport) + " != null");
            textReport.ContentTransferEncoding = ContentEncoding.SevenBit;
            var notReport = mReport[1] as MessageDispositionNotification;

            Debug.Assert(notReport != null, nameof(notReport) + " != null");
            notReport.ContentTransferEncoding = ContentEncoding.SevenBit;
            mdn.Headers.Add(HeaderId.Date, As2DateUtil.Rfc822.GetFormat(DateTime.Now));
            mdn.WriteTo(response.Body);
        }
        public void TestArgumentExceptions()
        {
            var report = new MultipartReport("disposition-notification");

            Assert.Throws <ArgumentNullException> (() => new MultipartReport((MimeEntityConstructorArgs)null));
            Assert.Throws <ArgumentNullException> (() => new MultipartReport((string)null));
            Assert.Throws <ArgumentNullException> (() => new MultipartReport(null, new object[0]));
            Assert.Throws <ArgumentNullException> (() => new MultipartReport("disposition-notification", null));

            Assert.Throws <ArgumentNullException> (() => report.ReportType = null);

            Assert.Throws <ArgumentNullException> (() => report.Accept(null));
        }
        /// <summary>
        /// The multipart/report should contain both a text/plain part with textual information and
        /// a message/disposition-notification part that should be examined for error/failure/warning.
        /// </summary>
        /// <returns></returns>
        public MultipartReport GetMultipartReport()
        {
            try
            {
                MultipartReport bodyPart = this.GetSignedMultiPart()[0] as MultipartReport;
                if (bodyPart == null)
                {
                    throw new InvalidOperationException(
                              "The first body part of the first part of the signed message is not a multipart/report");
                }

                return(bodyPart);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Unable to retrieve the multipart/report : " + e.Message, e);
            }
        }
        /// <summary>
        /// Return the fist part which have the given contentType
        /// </summary>
        /// <param name="contentType">the mime type to look for</param>
        /// <returns></returns>
        private MimeEntity GetPartFromMultipartReport(string contentType)
        {
            try
            {
                MultipartReport multipartReport = this.GetMultipartReport();
                for (int t = 0; t < multipartReport.Count; t++)
                {
                    MimeEntity bp = multipartReport[t];
                    if (ContainsIgnoreCase(bp.ContentType.MimeType, contentType))
                    {
                        return(bp);
                    }
                }
            }
            catch (Exception)
            {
                Log.Error("Failed to locate part of multipart/report of type " + contentType);
            }

            return(null);
        }
        public void TestParamCtor()
        {
            var report = new MultipartReport("disposition-notification", new MimePart());

            Assert.AreEqual(1, report.Count);
        }
Beispiel #7
0
 protected internal override void VisitMultipartReport(MultipartReport report)
 {
     MultipartReport++;
     base.VisitMultipartReport(report);
 }