예제 #1
0
 private string unencode_line(Mime.encoding enc, string line)
 {
     if (enc == Mime.encoding.base64)
     {
         return(clib.decode_base64(line, this.textenc));
     }
     return(enc == Mime.encoding.quoted ? clib.decode_quoted_printable(line, this.textenc) : line);
 }
예제 #2
0
 private void set_transfer(string bf)
 {
     bf = bf.ToLower();
     this.current_encoding = Mime.encoding.none;
     if (bf.Contains("quoted"))
     {
         this.current_encoding = Mime.encoding.quoted;
     }
     if (!bf.Contains("base64"))
     {
         return;
     }
     this.current_encoding = Mime.encoding.base64;
 }
예제 #3
0
        private void decode_body(int linei, string line)
        {
            bool isend;

            if (this.is_boundary(line, out isend))
            {
                this.attach_done();
                this.form_done();
                this.current_encoding = Mime.encoding.none;
                this.content_type     = "";
                this.intextpart       = false;
                this.inhtmlpart       = false;
                this.inattachpart     = false;
                this.ismsgheader      = false;
                this.ismsgpart        = false;
                this.part_subj        = "";
                this.part_from        = "";
                if (isend)
                {
                    return;
                }
                this.inmimeheader = true;
            }
            else if (this.inmimeheader)
            {
                if (line.Length == 0)
                {
                    if (this.content_type == "")
                    {
                        this.decode_part_header("Content-Type: text/plain");
                    }
                    if (!this.inattachpart && this.content_type.IndexOf("rfc822", StringComparison.OrdinalIgnoreCase) > 0)
                    {
                        this.decode_part_header(string.Format(" name=test_{0}.eml", (object)this.msgi++));
                    }
                }
                this.decode_part_header(line);
            }
            else
            {
                if (this.gobble_indent && line.Length > 0)
                {
                    int startIndex = 0;
                    while (startIndex < line.Length && line[startIndex] == '>')
                    {
                        ++startIndex;
                    }
                    if (startIndex < line.Length)
                    {
                        if (line[startIndex] == ' ')
                        {
                            ++startIndex;
                        }
                    }
                    try
                    {
                        line = line.Substring(startIndex);
                    }
                    catch
                    {
                    }
                }
                this.gobble_indent = false;
                if (this.current_encoding != Mime.encoding.none)
                {
                    if (line.Length > 0)
                    {
                        line = this.unencode_line(this.current_encoding, line);
                    }
                }
                else if (this.intextpart && this.isflowed)
                {
                    int length = line.Length;
                    if (length > 0)
                    {
                        if (line[length - 1] != ' ')
                        {
                            line += "\r\n";
                        }
                        else
                        {
                            this.gobble_indent = true;
                        }
                    }
                    else
                    {
                        line += "\r\n";
                    }
                }
                else
                {
                    line += "\r\n";
                }
                if (this.inform)
                {
                    if (this.attach_stream != null)
                    {
                        byte[] buffer = clib.string_to_byte(line);
                        this.attach_stream.Write(buffer, 0, ((IEnumerable <byte>)buffer).Count <byte>());
                    }
                    else
                    {
                        this.form_val.Append(line);
                    }
                }
                else if (this.intextpart)
                {
                    this.text.Append(line);
                }
                else if (this.inhtmlpart)
                {
                    this.html.Append(line);
                }
                if (this.ismsgheader)
                {
                    if (line == "\r\n")
                    {
                        this.ismsgheader = false;
                        if (this.ismsgpart && this.html.Length > 0)
                        {
                            this.html.Append(string.Format("<hr><p><a href=\"{0}\">Click to Open Attached Email Message</a></p>", (object)clib.to_url(this.part_fname), (object)clib.web_encode(this.part_subj.Substring(0, clib.min(100, this.part_subj.Length))), (object)clib.web_encode(clib.nice_email(this.part_from))));
                        }
                    }
                    if (line.StartsWith("Subject: "))
                    {
                        this.part_subj = line.Substring(9);
                    }
                    if (line.StartsWith("From: "))
                    {
                        this.part_from = line.Substring(6);
                    }
                }
                if (this.inattachpart)
                {
                    byte[] buffer = clib.string_to_byte(line);
                    if (this.fout != null)
                    {
                        this.fout.Write(buffer, 0, ((IEnumerable <byte>)buffer).Count <byte>());
                    }
                }
            }
        }