Пример #1
0
        /// <summary>
        /// Parses body from the specified stream
        /// </summary>
        /// <param name="owner">Owner MIME entity.</param>
        /// <param name="defaultContentType">Default content-type for this body.</param>
        /// <param name="stream">Stream from where to read body.</param>
        /// <returns>Returns parsed body.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b>, <b>defaultContentType</b> or <b>stream</b> is null reference.</exception>
        /// <exception cref="ParseException">Is raised when any parsing errors.</exception>
        protected static new MIME_b Parse(MIME_Entity owner,MIME_h_ContentType defaultContentType,SmartStream stream)
        {
            if(owner == null){
                throw new ArgumentNullException("owner");
            }
            if(defaultContentType == null){
                throw new ArgumentNullException("defaultContentType");
            }
            if(stream == null){
                throw new ArgumentNullException("stream");
            }
            if(owner.ContentType == null || owner.ContentType.Param_Boundary == null){
                throw new ParseException("Multipart entity has not required 'boundary' paramter.");
            }

            MIME_b_MultipartMixed retVal = new MIME_b_MultipartMixed(owner.ContentType);
            ParseInternal(owner,owner.ContentType.TypeWithSubtype,stream,retVal);

            return retVal;
        }
Пример #2
0
        private void updateMessage(Mail_Message m)
        {
            if (from != null)
                m.From = Mail_t_MailboxList.Parse(from.getString("account"));
            m.To = Mail_t_AddressList.Parse(txtTo.Text);
            if (!String.IsNullOrWhiteSpace(txtSubject.Text))
                m.Subject = txtSubject.Text;
            if (!String.IsNullOrWhiteSpace(txtCc.Text))
                m.Cc = Mail_t_AddressList.Parse(txtCc.Text.Trim());

            if (Receipt.IsChecked == true)
            {
                m.DispositionNotificationTo = Mail_t_MailboxList.Parse(from.getString("account"));
            }
            if (Importance.IsChecked == true)
            {
                m.Priority = "urgent";
            }

            string sHtmlText = htmlEditor.ContentHtml;
            List<string> sUrlList = getHtmlImageUrlList(sHtmlText);

            if (sUrlList.Count > 0 || attachments.Children.OfType<AttachmentItem>().Count() > 0)
            {
                //--- multipart/mixed -------------------------------------------------------------------------------------------------
                MIME_h_ContentType contentType_multipartMixed = new MIME_h_ContentType(MIME_MediaTypes.Multipart.mixed);
                contentType_multipartMixed.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');
                MIME_b_MultipartMixed multipartMixed = new MIME_b_MultipartMixed(contentType_multipartMixed);
                m.Body = multipartMixed;

                //--- multipart/alternative -----------------------------------------------------------------------------------------
                MIME_Entity entity_mulipart_alternative = new MIME_Entity();
                MIME_h_ContentType contentType_multipartAlternative = new MIME_h_ContentType(MIME_MediaTypes.Multipart.alternative);
                contentType_multipartAlternative.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');
                MIME_b_MultipartAlternative multipartAlternative = new MIME_b_MultipartAlternative(contentType_multipartAlternative);
                entity_mulipart_alternative.Body = multipartAlternative;
                multipartMixed.BodyParts.Add(entity_mulipart_alternative);

                //--- text/plain ----------------------------------------------------------------------------------------------------
                MIME_Entity entity_text_plain = new MIME_Entity();
                MIME_b_Text text_plain = new MIME_b_Text(MIME_MediaTypes.Text.plain);
                entity_text_plain.Body = text_plain;
                text_plain.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, txtEditor.Text);
                multipartAlternative.BodyParts.Add(entity_text_plain);

                // Create attachment etities: --- applactation/octet-stream -------------------------
                foreach (AttachmentItem item in attachments.Children.OfType<AttachmentItem>())
                {
                    multipartMixed.BodyParts.Add(Mail_Message.CreateAttachment(item.File));
                }

                foreach (string url in sUrlList)
                {
                    MIME_Entity img_entity = Mail_Message.CreateImage(url);
                    string contentID = Guid.NewGuid().ToString().Replace("-", "$");
                    img_entity.ContentID = "<" + contentID + ">";
                    sHtmlText = sHtmlText.Replace(url, "cid:" + contentID);
                    multipartMixed.BodyParts.Add(img_entity);
                }

                //--- text/html ------------------------------------------------------------------------------------------------------
                MIME_Entity entity_text_html = new MIME_Entity();
                MIME_b_Text text_html = new MIME_b_Text(MIME_MediaTypes.Text.html);
                entity_text_html.Body = text_html;
                text_html.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, sHtmlText);
                multipartAlternative.BodyParts.Add(entity_text_html);
            }
            else
            {
                //--- multipart/alternative -----------------------------------------------------------------------------------------
                MIME_h_ContentType contentType_multipartAlternative = new MIME_h_ContentType(MIME_MediaTypes.Multipart.alternative);
                contentType_multipartAlternative.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');
                MIME_b_MultipartAlternative multipartAlternative = new MIME_b_MultipartAlternative(contentType_multipartAlternative);
                m.Body = multipartAlternative;

                //--- text/plain ----------------------------------------------------------------------------------------------------
                MIME_Entity entity_text_plain = new MIME_Entity();
                MIME_b_Text text_plain = new MIME_b_Text(MIME_MediaTypes.Text.plain);
                entity_text_plain.Body = text_plain;
                text_plain.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, txtEditor.Text);
                multipartAlternative.BodyParts.Add(entity_text_plain);

                //--- text/html ------------------------------------------------------------------------------------------------------
                MIME_Entity entity_text_html = new MIME_Entity();
                MIME_b_Text text_html = new MIME_b_Text(MIME_MediaTypes.Text.html);
                entity_text_html.Body = text_html;
                text_html.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, sHtmlText);
                multipartAlternative.BodyParts.Add(entity_text_html);
            }
        }