Exemple #1
0
        // ---------------------- LoadEmail ---------------------------
        private void LoadEmail(SocketExchange InEx, Int64 InMailDropPosition)
        {
            // tell the server we want to read the message.
            InEx.Send("retr " + InMailDropPosition + PopConstants.CrLf);

            InEx.ExpectedResponseCodes =
                new ExpectedResponseCodes(PopConstants.Ok, PopConstants.Error);
            InEx.SendReceive("retr " + InMailDropPosition + PopConstants.CrLf);
            InEx.ThrowIfUnexpectedResponse( );

            // -ERR response. no such message number.
            if (InEx.ResponseCode == PopConstants.Error)
            {
            }

            else
            {
                // for now, receive SSL link messages in the same thread.
                if (InEx.ConnectedSecureSocket != null)
                {
                    StringBuilder mail = null;
                    mail = ReceiveMessage_SameThread(InEx);
                    InEx.LoadResponseMessage(mail.ToString( ));
                }

                // receive in a background thread.
                else
                {
                    StartReceive(InEx);
                    InEx.LoadResponseMessage(mSockThreadState.sb.ToString( ));
                }
            }

            // parse email ...
            mParts = MimeCommon.MessagePartSplitter(InEx.ResponseMessage);

            string[] lines = MimeCommon.MessageLineSplitter(InEx.ResponseMessage);

            mAttachments = null;
            MimeAttachment attach = (MimeAttachment)Attachments.FirstAttachment( ).Current;

            if (attach != null)
            {
                attach.SaveAs("c:\\apress\\attachment.txt");
            }

//      if (1 == 2)
//        DumpHeader(InEx, InMailDropPosition);

            for (int ix = 0; ix < lines.Length; ++ix)
            {
                InEx.Logger.AddMessage(NetworkRole.Server, lines[ix]);
            }
            ParseEmail(lines);

            // remove reading pop3State ...
            mSockThreadState = null;
        }
Exemple #2
0
        // Adds an entry to the collection.
        public void Add(string InPropertyName, string InPropertyValue)
        {
            string propertyName = InPropertyName.ToLower( );

            // decode any encoded-word encoded values in the property value string.
            string propertyValue =
                MimeCommon.DecodeHeaderString_EncodedOnly(InPropertyValue);

            this.BaseAdd(propertyName, propertyValue);
        }
Exemple #3
0
        // ------------------------------ LoadMessageLines ----------------------------
        // load the message lines of the part.
        public void LoadMessageLines(string InStream, int InStreamBx, int InLineCx)
        {
            int Ex = InStreamBx - 1;

            mMessageLines = new string[InLineCx];
            for (int Ix = 0; Ix < InLineCx; ++Ix)
            {
                int           Bx = Ex + 1;
                IntStringPair rv = MimeCommon.ScanEndLine(InStream, Bx);
                Ex = rv.a;
                mMessageLines[Ix] = rv.b;
            }
        }
        // ------------------------ CalcLineCode --------------------------------
        // calc the LineCode of the mime message line.  see the MimeLineCode enum.
        public static MimeLineCode CalcLineCode(
            string InLine, string InBdryText)
        {
            MimeLineCode code = MimeLineCode.None;

            // a part boundary line
            if ((InLine.Length > 2) &&
                (InLine.Substring(0, 2) == "--") &&
                (InBdryText != null))
            {
                string beginBdry = "--" + InBdryText;
                string endBdry   = beginBdry + "--";
                if ((InLine.Length >= endBdry.Length) &&
                    (InLine.Substring(0, endBdry.Length) == endBdry))
                {
                    code = MimeLineCode.PartEndBdry;
                }
                else if ((InLine.Length >= beginBdry.Length) &&
                         (InLine.Substring(0, beginBdry.Length) == beginBdry))
                {
                    code = MimeLineCode.PartBdry;
                }
            }

            // check for the remaining line codes.
            if (code != MimeLineCode.None)
            {
            }

            else if (InLine.Length == 0)
            {
                code = MimeLineCode.None;
            }

            // a property line starts with non blank, then that word ends with ":"
            else if ((MimeCommon.CharIsWhitespace(InLine[0]) == false) &&
                     (ScanPropertyNameDelimChar(InLine).ResultChar == ':'))
            {
                code = MimeLineCode.Property;
            }

            else
            {
                code = MimeLineCode.Text;
            }

            return(code);
        }
Exemple #5
0
        // ------------------------------ LoadPropertyLines ----------------------------
        // load the property lines of the part.
        public void LoadPropertyLines(string InStream, int InStreamBx, int InLineCx)
        {
            int Ex = InStreamBx - 1;

            mPropertyLines = new string[InLineCx];
            for (int Ix = 0; Ix < InLineCx; ++Ix)
            {
                int           Bx = Ex + 1;
                IntStringPair rv = MimeCommon.ScanEndUnfoldedLine(InStream, Bx);
                Ex = rv.a;
                mPropertyLines[Ix] = rv.b;
            }

            // load the property dictionary from the property lines.
            LoadPropertyDictionary( );
        }
Exemple #6
0
        public static string Rfc2047Decode(string encodedValue)
        {
            if (encodedValue == null)
            {
                return(null);
            }
            if (!encodedValue.Contains("=?"))
            {
                return(encodedValue);
            }
            MimeString      str             = new MimeString(encodedValue.Trim());
            MimeStringList  lines           = new MimeStringList(str);
            DecodingOptions decodingOptions = new DecodingOptions(DecodingFlags.Rfc2047);
            DecodingResults decodingResults;
            string          result;

            if (!MimeCommon.TryDecodeValue(lines, 4026531840U, decodingOptions, out decodingResults, out result))
            {
                return(encodedValue);
            }
            return(result);
        }
Exemple #7
0
        /// <summary>Returns the MailMessage as a RFC 822 formatted message</summary>
        public override string ToString()
        {
            StringBuilder         sb = new StringBuilder(60000);
            MimeHeaderLineBuilder lb = new MimeHeaderLineBuilder( );

            lb.Traits.SetEncoderCharSet(charset);

            // reply to email address
            sb.Append(
                MimeCommon.ConcatMessageLine(
                    lb.Traits,
                    "Reply-To:",
                    ReplyTo.ToMimeString(lb.Traits.EncoderCharSet),
                    MimeConstants.CrLf));

            // BgnTemp debug.  an already encoded from email address.
            if (mEncodedFromAddress != null)
            {
                sb.Append(mEncodedFromAddress + MimeConstants.CrLf);
            }
            else
            {
                // EndTemp debug.

                // send from email address
                sb.Append(
                    MimeCommon.ConcatMessageLine(
                        lb.Traits,
                        "From:",
                        From.ToMimeString(lb.Traits.EncoderCharSet),
                        MimeConstants.CrLf));
            }

            // send to email address
            sb.Append(
                MimeCommon.ConcatMessageLine(
                    lb.Traits,
                    "To:",
                    ToRecipients.ToMessageHeaderString(lb.Traits.EncoderCharSet),
                    MimeConstants.CrLf));

//			sb.Append( "Reply-To: " ) ;
//			sb.Append( ReplyTo.ToMimeString( charset )) ;
//			sb.Append( SmtpConstants.CrLf ) ;

//			sb.Append( "From: " + From.ToMimeStringToMessageHeaderString( charset )) ;
//			sb.Append( SmtpConstants.CrLf ) ;
//			sb.Append( "To: " + ToRecipients.ToMessageHeaderString( charset )) ;
//			sb.Append( SmtpConstants.CrLf ) ;

            if (CCRecipients.Count > 0)
            {
                sb.Append("CC: " + CCRecipients.ToMessageHeaderString(charset));
                sb.Append(SmtpConstants.CrLf);
            }

            if (BCCRecipients.Count > 0)
            {
                sb.Append("BCC: " + BCCRecipients.ToMessageHeaderString(charset));
                sb.Append(SmtpConstants.CrLf);
            }

            // message subject line.
            if (Stringer.IsNotEmpty(Subject))
            {
                lb.Clear( );
                lb.Append("Subject: ");
                lb.Append(Subject);
                sb.Append(lb.ToEncodedString( ) + MimeConstants.CrLf);
            }

            // BgnTemp debug.  an already encoded subject line.
            if (mEncodedSubject != null)
            {
                sb.Append(mEncodedSubject + MimeConstants.CrLf);
            }
            // EndTemp debug.

            // send timestamp
            lb
            .Clear( )
            .Append("Date: " + DateTime.Now.ToUniversalTime().ToString("R"));
            sb.Append(lb.ToEncodedString( ) + MimeConstants.CrLf);

            sb.Append(SmtpConfig.X_MAILER_HEADER + "\r\n");

            if (notification)
            {
                if (ReplyTo.FriendlyName != null && ReplyTo.FriendlyName.Length != 0)
                {
                    sb.Append("Disposition-Notification-To: " + MailEncoder.ConvertHeaderToQP(ReplyTo.FriendlyName, charset) + " <" + ReplyTo.Address + ">\r\n");
                }
                else
                {
                    sb.Append("Disposition-Notification-To: <" + ReplyTo.Address + ">\r\n");
                }
            }

            if (priority != null)
            {
                sb.Append("X-Priority: " + priority + "\r\n");
            }

            if (customHeaders != null)
            {
                for (IEnumerator i = customHeaders.GetEnumerator(); i.MoveNext();)
                {
                    MailHeader m = (MailHeader)i.Current;

                    if (m.name.Length >= 0 && m.body.Length >= 0)
                    {
                        sb.Append(m.name + ":" + MailEncoder.ConvertHeaderToQP(m.body, charset) + "\r\n");
                    }
                    else
                    {
                        // TODO: Check if below is within RFC spec.
                        sb.Append(m.name + ":\r\n");
                    }
                }
            }

            sb.Append("MIME-Version: 1.0\r\n");
            sb.Append(GetMessageBody());

            return(sb.ToString());
        }
Exemple #8
0
        public static string Rfc2047Encode(string value, Encoding encoding)
        {
            EncodingOptions encodingOptions = new EncodingOptions(Charset.GetCharset(encoding));

            return(MimeCommon.EncodeValue(value, encodingOptions, ValueEncodingStyle.Normal).ToString());
        }
Exemple #9
0
 internal static bool IsEncodingRequired(string value, bool allowUTF8 = false)
 {
     return(MimeCommon.IsEncodingRequired(value, allowUTF8));
 }
        // ---------------------- LoadEmail ---------------------------
        private void LoadEmail(SocketExchange InEx, System.Int64 InMailDropPosition)
        {
            // tell the server we want to read the message.
            InEx.Send("retr " + InMailDropPosition + PopConstants.CrLf);

            InEx.ExpectedResponseCodes =
                new ExpectedResponseCodes(PopConstants.Ok, PopConstants.Error);
            InEx.SendReceive("retr " + InMailDropPosition + PopConstants.CrLf);
            InEx.ThrowIfUnexpectedResponse( );

            // -ERR response. no such message number.
            if (InEx.ResponseCode == PopConstants.Error)
            {
            }

            else
            {
                // for now, receive SSL link messages in the same thread.
                if (InEx.ConnectedSecureSocket != null)
                {
                    StringBuilder mail = null;
                    mail = ReceiveMessage_SameThread(InEx);
                    InEx.LoadResponseMessage(mail.ToString( ));
                }

                // receive in a background thread.
                else
                {
                    StartReceive(InEx);
                    InEx.LoadResponseMessage(mSockThreadState.sb.ToString( ));
                }
            }

            // parse email ...
            mParts = MimeCommon.MessagePartSplitter(InEx.ResponseMessage);

            string[] lines = MimeCommon.MessageLineSplitter(InEx.ResponseMessage);
            if (1 == 2)
            {
                mParts = MimeCommon.MessagePartSplitter(lines);
            }

            mAttachments = null;
            MimeAttachment attach = (MimeAttachment)Attachments.FirstAttachment( ).Current;

            if (attach != null)
            {
                attach.SaveAs("c:\\apress\\attachment.txt");
            }

            if (1 == 2)
            {
                // dump the header lines of the top part.
                InEx.Logger.AddMessage(NetworkRole.Server, "--- start header line dump ---");
                MimeTopPart topPart = ( MimeTopPart )mParts.GetTopPart( );
                for (int Ix = 0; Ix < topPart.PropertyLines.Length; ++Ix)
                {
                    InEx.Logger.AddMessage(NetworkRole.Server, topPart.PropertyLines[Ix]);
                }
                for (int Ix = 0; Ix < topPart.MessageLines.Length; ++Ix)
                {
                    InEx.Logger.AddMessage(NetworkRole.Server, topPart.MessageLines[Ix]);
                }
                InEx.Logger.AddMessage(NetworkRole.Server, "--- end of header line dump ---");

                // dump the lines of each part.
                foreach (MimeMessagePart part in mParts)
                {
                    InEx.Logger.AddMessage(NetworkRole.Server, "** message part **");
                    InEx.Logger.AddMessage(NetworkRole.Server, "** property lines **");
                    foreach (string line in part.PropertyLines)
                    {
                        InEx.Logger.AddMessage(NetworkRole.Server, line);
                    }
                    InEx.Logger.AddMessage(NetworkRole.Server, "** message lines **");
                    foreach (string line in part.MessageLines)
                    {
                        InEx.Logger.AddMessage(NetworkRole.Server, line);
                    }
                }
                InEx.Logger.AddMessage(NetworkRole.Server, "---- end of parts ----------");
            }

            for (int ix = 0; ix < lines.Length; ++ix)
            {
                InEx.Logger.AddMessage(NetworkRole.Server, lines[ix]);
            }
            ParseEmail(lines);

            // remove reading pop3State ...
            mSockThreadState = null;
        }