Exemple #1
0
        /**
         * builds mail/news body with uuencoded attachments
         */
        public static string BuildBodyWithUUEncodedInsertions(string body, string charset, params string[] fullnames)
        {
            if (fullnames.Length == 0)
            {
                return(EscapeSinglePeriodsAndTranslateToCharset(body, charset));
            }
            StringBuilder bodyBuilder = StringBuilderPool.Alloc();

            try
            {
                bodyBuilder.Append(body);
                foreach (string fullname in fullnames)
                {
                    FileStream fs = OpenAttachment(fullname);
                    if (fs != null)
                    {
                        bodyBuilder.Append("\r\nbegin 777 ");
                        bodyBuilder.Append(Path.GetFileName(fullname));
                        byte[] bytes = new byte[_UULinePreferredLen];
                        int    read;
                        while ((read = fs.Read(bytes, 0, bytes.Length)) > 0)
                        {
                            bodyBuilder.Append("\r\n");
                            bodyBuilder.Append(UUParser._UUAlphabet[read]);
                            bodyBuilder.Append(UUParser.Encode(bytes, read));
                        }
                        bodyBuilder.Append("\r\n`\r\nend");
                    }
                }
                return(EscapeSinglePeriodsAndTranslateToCharset(bodyBuilder.ToString(), charset));
            }
            finally
            {
                StringBuilderPool.Dispose(bodyBuilder);
            }
        }
Exemple #2
0
        private void ProcessSinglePlainBody(string[] lines)
        {
            string filename = string.Empty;
            bool   inBody   = true;
            int    partLen  = 0;
            string line;

            for (int i = 0; i < lines.Length; ++i)
            {
                line = lines[i].TrimEnd('\r');
                if (inBody && line.StartsWith("begin"))
                {
                    string[] attachHeaders = line.TrimEnd(' ').Split(' ');
                    if (attachHeaders.Length > 2)
                    {
                        string fattr   = attachHeaders[1];
                        bool   fattrOk = fattr.Length >= 3;
                        if (fattrOk)
                        {
                            for (int j = 0; j < fattr.Length; ++j)
                            {
                                if (!(fattrOk = Char.IsDigit(fattr[j])))
                                {
                                    break;
                                }
                            }
                        }
                        if (fattrOk)
                        {
                            filename = attachHeaders[2];
                            for (int j = 3; j < attachHeaders.Length; ++j)
                            {
                                filename += attachHeaders[j];
                            }
                            inBody  = false;
                            partLen = 0;
                            continue;
                        }
                    }
                }
                else if (!inBody && line.StartsWith("end"))
                {
                    if (_partBuilder.Length > 0)
                    {
                        if (partLen > 0)
                        {
                            byte[] bytes = UUParser.Decode(_partBuilder.ToString());
                            if (partLen > bytes.Length)
                            {
                                partLen = bytes.Length;
                            }
                            MessagePart attachment = new MessagePart(bytes, partLen, filename);
                            attachment.PartType = MessagePartTypes.Inline;
                            _parts.Add(attachment);
                        }
                        _partBuilder.Length = 0;
                    }
                    inBody = true;
                    continue;
                }
                if (inBody)
                {
                    _bodyBuilder.Append(line);
                    _bodyBuilder.Append("\r\n");
                }
                else
                {
                    if (line.Length > 1 && line[0] != '`')
                    {
                        partLen += UUParser._UUAlphabet.IndexOf(line[0]);
                        _partBuilder.Append(line, 1, line.Length - 1);
                    }
                }
            }
        }