コード例 #1
0
        //internal virtual IAsyncResult BeginSend(BaseWriter writer, bool sendEnvelope, AsyncCallback callback, object state)
        //{
        //    this.PrepareHeaders(sendEnvelope);
        //    writer.WriteHeaders(this.Headers);
        //    if (this.Content != null)
        //    {
        //        return this.Content.BeginSend(writer, callback, state);
        //    }
        //    LazyAsyncResult result = new LazyAsyncResult(this, state, callback);
        //    IAsyncResult result2 = writer.BeginGetContentStream(new AsyncCallback(this.EmptySendCallback), new EmptySendContext(writer, result));
        //    if (result2.CompletedSynchronously)
        //    {
        //        writer.EndGetContentStream(result2).Close();
        //    }
        //    return result;
        //}

        //internal void EmptySendCallback(IAsyncResult result)
        //{
        //    Exception exception = null;
        //    if (!result.CompletedSynchronously)
        //    {
        //        EmptySendContext asyncState = (EmptySendContext)result.AsyncState;
        //        try
        //        {
        //            asyncState.writer.EndGetContentStream(result).Close();
        //        }
        //        catch (Exception exception2)
        //        {
        //            exception = exception2;
        //        }
        //        catch
        //        {
        //            exception = new Exception(SR.GetString("net_nonClsCompliantException"));
        //        }
        //        asyncState.result.InvokeCallback(exception);
        //    }
        //}

        //internal virtual void EndSend(IAsyncResult asyncResult)
        //{
        //    if (asyncResult == null)
        //    {
        //        throw new ArgumentNullException("asyncResult");
        //    }
        //    if (this.Content != null)
        //    {
        //        this.Content.EndSend(asyncResult);
        //    }
        //    else
        //    {
        //        LazyAsyncResult result = asyncResult as LazyAsyncResult;
        //        if ((result == null) || (result.AsyncObject != this))
        //        {
        //            throw new ArgumentException(SR.GetString("net_io_invalidasyncresult"));
        //        }
        //        if (result.EndCalled)
        //        {
        //            throw new InvalidOperationException(SR.GetString("net_io_invalidendcall", new object[] { "EndSend" }));
        //        }
        //        result.InternalWaitForCompletion();
        //        result.EndCalled = true;
        //        if (result.Result is Exception)
        //        {
        //            throw ((Exception)result.Result);
        //        }
        //    }
        //}

        internal void PrepareEnvelopeHeaders(bool sendEnvelope)
        {
            this.EnvelopeHeaders[MailHeaderInfo.GetString(MailHeaderID.XSender)] = this.From.ToEncodedString();
            this.EnvelopeHeaders.Remove(MailHeaderInfo.GetString(MailHeaderID.XReceiver));
            foreach (MailAddress address in this.To)
            {
                this.EnvelopeHeaders.Add(MailHeaderInfo.GetString(MailHeaderID.XReceiver), address.ToEncodedString());
            }
            foreach (MailAddress address2 in this.CC)
            {
                this.EnvelopeHeaders.Add(MailHeaderInfo.GetString(MailHeaderID.XReceiver), address2.ToEncodedString());
            }
            foreach (MailAddress address3 in this.Bcc)
            {
                this.EnvelopeHeaders.Add(MailHeaderInfo.GetString(MailHeaderID.XReceiver), address3.ToEncodedString());
            }
        }
コード例 #2
0
 internal void PrepareHeaders(bool sendEnvelope)
 {
     this.Headers[MailHeaderInfo.GetString(MailHeaderID.MimeVersion)] = "1.0";
     this.Headers[MailHeaderInfo.GetString(MailHeaderID.From)]        = this.From.ToEncodedString();
     if (this.Sender != null)
     {
         this.Headers[MailHeaderInfo.GetString(MailHeaderID.Sender)] = this.Sender.ToEncodedString();
     }
     else
     {
         this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Sender));
     }
     if (this.To.Count > 0)
     {
         this.Headers[MailHeaderInfo.GetString(MailHeaderID.To)] = this.To.ToEncodedString();
     }
     else
     {
         this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.To));
     }
     if (this.CC.Count > 0)
     {
         this.Headers[MailHeaderInfo.GetString(MailHeaderID.Cc)] = this.CC.ToEncodedString();
     }
     else
     {
         this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Cc));
     }
     if (this.replyTo != null)
     {
         this.Headers[MailHeaderInfo.GetString(MailHeaderID.ReplyTo)] = this.ReplyTo.ToEncodedString();
     }
     else
     {
         this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.ReplyTo));
     }
     if (this.priority == MailPriority.High)
     {
         this.Headers[MailHeaderInfo.GetString(MailHeaderID.XPriority)]  = "1";
         this.Headers[MailHeaderInfo.GetString(MailHeaderID.Priority)]   = "urgent";
         this.Headers[MailHeaderInfo.GetString(MailHeaderID.Importance)] = "high";
     }
     else if (this.priority == MailPriority.Low)
     {
         this.Headers[MailHeaderInfo.GetString(MailHeaderID.XPriority)]  = "5";
         this.Headers[MailHeaderInfo.GetString(MailHeaderID.Priority)]   = "non-urgent";
         this.Headers[MailHeaderInfo.GetString(MailHeaderID.Importance)] = "low";
     }
     else if (this.priority != ~MailPriority.Normal)
     {
         this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.XPriority));
         this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Priority));
         this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Importance));
     }
     this.Headers[MailHeaderInfo.GetString(MailHeaderID.Date)] = MailBnfHelper.GetDateTimeString(DateTime.Now, null);
     if ((this.subject != null) && (this.subject != string.Empty))
     {
         this.Headers[MailHeaderInfo.GetString(MailHeaderID.Subject)] = MimeBasePart.EncodeHeaderValue(this.subject, this.subjectEncoding, MimeBasePart.ShouldUseBase64Encoding(this.subjectEncoding));
     }
     else
     {
         this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Subject));
     }
 }