示例#1
0
        /// <summary>
        /// Does period handling.
        /// </summary>
        /// <param name="strm">Input stream.</param>
        /// <param name="add_Remove">If true add periods, else removes periods.</param>
        /// <param name="setStrmPosTo0">If true sets stream position to 0.</param>
        /// <returns></returns>
        public static MemoryStream DoPeriodHandling(Stream strm, bool add_Remove, bool setStrmPosTo0)
        {
            MemoryStream replyData = new MemoryStream();

            byte[] crlf = new byte[] { (byte)'\r', (byte)'\n' };

            if (setStrmPosTo0)
            {
                strm.Position = 0;
            }

            StreamHelper r = new StreamHelper(strm, null);

            byte[] line = r.ReadLine();

            // Loop through all lines
            while (line != null)
            {
                if (line.Length > 0)
                {
                    if (line[0] == (byte)'.')
                    {
                        /* Add period Rfc 2821 4.5.2
                         * -  Before sending a line of mail text, the SMTP client checks the
                         * first character of the line.  If it is a period, one additional
                         * period is inserted at the beginning of the line.
                         */
                        if (add_Remove)
                        {
                            replyData.WriteByte((byte)'.');
                            replyData.Write(line, 0, line.Length);
                        }

                        /* Remove period Rfc 2821 4.5.2
                         * If the first character is a period , the first characteris deleted.
                         */
                        else
                        {
                            replyData.Write(line, 1, line.Length - 1);
                        }

                        break;
                    }
                    else
                    {
                        replyData.Write(line, 0, line.Length);
                    }
                }

                replyData.Write(crlf, 0, crlf.Length);

                // Read next line
                line = r.ReadLine();
            }

            replyData.Position = 0;

            return(replyData);
        }
示例#2
0
        /// <summary>
        /// Scans invalid CR or LF combination in stream. Returns true if contains invalid CR or LF combination.
        /// </summary>
        /// <param name="strm">Stream which to check.</param>
        /// <returns>Returns true if contains invalid CR or LF combination.</returns>
        public static bool ScanInvalid_CR_or_LF(Stream strm)
        {
            StreamHelper lineReader = new StreamHelper(strm, null);

            byte[] line = lineReader.ReadLine();
            while (line != null)
            {
                foreach (byte b in line)
                {
                    // Contains CR or LF. It cannot conatian such sumbols, because CR must be paired with LF
                    // and we currently reading lines with CRLF combination.
                    if (b == 10 || b == 13)
                    {
                        return(true);
                    }
                }

                line = lineReader.ReadLine();
            }

            return(false);
        }
示例#3
0
		/// <summary>
		/// Does period handling.
		/// </summary>
		/// <param name="strm">Input stream.</param>
		/// <param name="add_Remove">If true add periods, else removes periods.</param>
		/// <param name="setStrmPosTo0">If true sets stream position to 0.</param>
		/// <returns></returns>
		public static MemoryStream DoPeriodHandling(Stream strm,bool add_Remove,bool setStrmPosTo0)
		{			
			MemoryStream replyData = new MemoryStream();

			byte[] crlf = new byte[]{(byte)'\r',(byte)'\n'};

			if(setStrmPosTo0){
				strm.Position = 0;
			}

			StreamHelper r = new StreamHelper(strm, null);
			byte[] line = r.ReadLine();

			// Loop through all lines
			while(line != null){

				if(line.Length > 0){
					if(line[0] == (byte)'.'){
						/* Add period Rfc 2821 4.5.2
						   -  Before sending a line of mail text, the SMTP client checks the
						   first character of the line.  If it is a period, one additional
						   period is inserted at the beginning of the line.
						*/
						if(add_Remove){
							replyData.WriteByte((byte)'.');
							replyData.Write(line,0,line.Length);
						}
						/* Remove period Rfc 2821 4.5.2
						 If the first character is a period , the first characteris deleted.							
						*/
						else{
							replyData.Write(line,1,line.Length-1);
						}

                        break;
					}
					else{
						replyData.Write(line,0,line.Length);
					}
				}					

				replyData.Write(crlf,0,crlf.Length);

				// Read next line
				line = r.ReadLine();
			}

			replyData.Position = 0;

			return replyData;
		}
示例#4
0
		/// <summary>
		/// Scans invalid CR or LF combination in stream. Returns true if contains invalid CR or LF combination.
		/// </summary>
		/// <param name="strm">Stream which to check.</param>
		/// <returns>Returns true if contains invalid CR or LF combination.</returns>
		public static bool ScanInvalid_CR_or_LF(Stream strm)
		{
			StreamHelper lineReader = new StreamHelper(strm, null);
			byte[] line = lineReader.ReadLine();
			while(line != null){
				foreach(byte b in line){
					// Contains CR or LF. It cannot conatian such sumbols, because CR must be paired with LF
					// and we currently reading lines with CRLF combination.
					if(b == 10 || b == 13){
						return true;
					}
				}

				line = lineReader.ReadLine();
			}

			return false;
		}