コード例 #1
0
 /// <include file='../../docs.xml'
 /// path='docs/doc[@name="M:PeterO.Mail.DispositionBuilder.#ctor(PeterO.Mail.ContentDisposition)"]/*'/>
 public DispositionBuilder(ContentDisposition mt) {
   if (mt == null) {
     throw new ArgumentNullException("mt");
   }
   this.parameters = new Dictionary<string, string>(mt.Parameters);
   this.type = mt.DispositionType;
 }
コード例 #2
0
ファイル: Message.cs プロジェクト: peteroupc/MailLib
 /// <include file='../../docs.xml'
 /// path='docs/doc[@name="M:PeterO.Mail.Message.SetHeader(System.Int32,System.String,System.String)"]/*'/>
 public Message SetHeader(int index, string name, string value) {
   if (index < 0) {
     throw new ArgumentException("index (" + index + ") is less than " +
                 "0");
   }
   if (index >= (this.headers.Count / 2)) {
     throw new ArgumentException("index (" + index +
                 ") is not less than " + (this.headers.Count
                 / 2));
   }
   name = ValidateHeaderField(name, value);
   this.headers[index * 2] = name;
   this.headers[(index * 2) + 1] = value;
   if (name.Equals("content-type")) {
     this.contentType = MediaType.Parse(value);
   } else if (name.Equals("content-disposition")) {
     this.contentDisposition = ContentDisposition.Parse(value);
   }
   return this;
 }
コード例 #3
0
ファイル: Message.cs プロジェクト: peteroupc/MailLib
 /// <include file='../../docs.xml'
 /// path='docs/doc[@name="M:PeterO.Mail.Message.RemoveHeader(System.String)"]/*'/>
 public Message RemoveHeader(string name) {
   if (name == null) {
     throw new ArgumentNullException("name");
   }
   name = DataUtilities.ToLowerCaseAscii(name);
   // Remove the header field
   for (int i = 0; i < this.headers.Count; i += 2) {
     if (this.headers[i].Equals(name)) {
       this.headers.RemoveAt(i);
       this.headers.RemoveAt(i);
       i -= 2;
     }
   }
   if (name.Equals("content-type")) {
     this.contentType = MediaType.TextPlainAscii;
   } else if (name.Equals("content-disposition")) {
     this.contentDisposition = null;
   }
   return this;
 }
コード例 #4
0
ファイル: Message.cs プロジェクト: peteroupc/MailLib
 /// <include file='../../docs.xml'
 /// path='docs/doc[@name="M:PeterO.Mail.Message.RemoveHeader(System.Int32)"]/*'/>
 public Message RemoveHeader(int index) {
   if (index < 0) {
     throw new ArgumentException("index (" + index + ") is less than " +
                 "0");
   }
   if (index >= (this.headers.Count / 2)) {
     throw new ArgumentException("index (" + index +
                 ") is not less than " + (this.headers.Count
                 / 2));
   }
   string name = this.headers[index * 2];
   this.headers.RemoveAt(index * 2);
   this.headers.RemoveAt(index * 2);
   if (name.Equals("content-type")) {
     this.contentType = MediaType.TextPlainAscii;
   } else if (name.Equals("content-disposition")) {
     this.contentDisposition = null;
   }
   return this;
 }
コード例 #5
0
ファイル: Message.cs プロジェクト: peteroupc/MailLib
    private void ProcessHeaders(bool assumeMime, bool digest) {
      var haveContentType = false;
      bool mime = assumeMime;
      var haveContentDisp = false;
      string transferEncodingValue = String.Empty;
      for (int i = 0; i < this.headers.Count; i += 2) {
        string name = this.headers[i];
        string value = this.headers[i + 1];
        if (name.Equals("content-transfer-encoding")) {
          int startIndex = HeaderParser.ParseCFWS(value, 0, value.Length, null);
          // NOTE: Actually "token", but all known transfer encoding values
          // fit the same syntax as the stricter one for top-level types and
          // subtypes
          int endIndex = MediaType.SkipMimeTypeSubtype(
            value,
            startIndex,
            value.Length,
            null);
          transferEncodingValue = (
            HeaderParser.ParseCFWS(
              value,
              endIndex,
              value.Length,
              null) == value.Length) ? value.Substring(
  startIndex,
  endIndex - startIndex) : String.Empty;
        }
        mime |= name.Equals("mime-version");
        if (value.IndexOf("=?", StringComparison.Ordinal) >= 0) {
          IHeaderFieldParser parser = HeaderFieldParsers.GetParser(name);
          // Decode encoded words in the header field where possible
          value = parser.DecodeEncodedWords(value);
          this.headers[i + 1] = value;
        }
      }
      this.contentType = digest ? MediaType.MessageRfc822 :
        MediaType.TextPlainAscii;
      var haveInvalid = false;
      var haveContentEncoding = false;
      for (int i = 0; i < this.headers.Count; i += 2) {
        string name = this.headers[i];
        string value = this.headers[i + 1];
        if (mime && name.Equals("content-transfer-encoding")) {
          value = DataUtilities.ToLowerCaseAscii(transferEncodingValue);
          this.headers[i + 1] = value;
          if (value.Equals("7bit")) {
            this.transferEncoding = EncodingSevenBit;
          } else if (value.Equals("8bit")) {
            this.transferEncoding = EncodingEightBit;
          } else if (value.Equals("binary")) {
            this.transferEncoding = EncodingBinary;
          } else if (value.Equals("quoted-printable")) {
            this.transferEncoding = EncodingQuotedPrintable;
          } else if (value.Equals("base64")) {
            this.transferEncoding = EncodingBase64;
          } else {
            // Unrecognized transfer encoding
            this.transferEncoding = EncodingUnknown;
          }
          haveContentEncoding = true;
        } else if (mime && name.Equals("content-type")) {
          if (haveContentType) {
            // DEVIATION: If there is already a content type,
            // treat content type as application/octet-stream
            if (haveInvalid || MediaType.Parse(value, null) == null) {
              this.contentType = MediaType.TextPlainAscii;
              haveInvalid = true;
            } else {
              this.contentType = MediaType.ApplicationOctetStream;
            }
          } else {
            this.contentType = MediaType.Parse(
              value,
              null);
            if (this.contentType == null) {
              this.contentType = digest ? MediaType.MessageRfc822 :
                MediaType.TextPlainAscii;
              haveInvalid = true;
            }
            haveContentType = true;
          }
        } else if (mime && name.Equals("content-disposition")) {
          if (haveContentDisp) {
            string valueExMessage = "Already have this header: " + name;
#if DEBUG
            valueExMessage += "[old=" + this.contentType + ", new=" + value +
              "]";
            valueExMessage = valueExMessage.Replace("\r\n", " ");
#endif
            throw new MessageDataException(valueExMessage);
          }
          this.contentDisposition = ContentDisposition.Parse(value);
          haveContentDisp = true;
        }
      }
      if (this.transferEncoding == EncodingUnknown) {
        this.contentType = MediaType.Parse("application/octet-stream");
      }
      if (!haveContentEncoding && this.contentType.TypeAndSubType.Equals(
        "message/rfc822")) {
        // DEVIATION: Be a little more liberal with rfc822
        // messages with 8-bit bytes
        this.transferEncoding = EncodingEightBit;
      }
      if (this.transferEncoding == EncodingSevenBit) {
        string charset = this.contentType.GetCharset();
        if (charset.Equals("utf-8")) {
          // DEVIATION: Be a little more liberal with UTF-8
          this.transferEncoding = EncodingEightBit;
        } else if (this.contentType.TypeAndSubType.Equals("text/html")) {
          if (charset.Equals("us-ascii") || charset.Equals("ascii") ||
              charset.Equals("windows-1252") || charset.Equals(
                "windows-1251") ||
              (charset.Length > 9 && charset.Substring(0, 9).Equals(
                "iso-8859-"))) {
            // DEVIATION: Be a little more liberal with text/html and
            // single-byte charsets or UTF-8
            this.transferEncoding = EncodingEightBit;
          }
        }
      }
      if (this.transferEncoding == EncodingQuotedPrintable ||
          this.transferEncoding == EncodingBase64 ||
          this.transferEncoding == EncodingUnknown) {
        if (this.contentType.IsMultipart ||
            (this.contentType.TopLevelType.Equals("message") &&
             !this.contentType.SubType.Equals("global") &&
             !this.contentType.SubType.Equals("global-headers") &&
             !this.contentType.SubType.Equals(
               "global-disposition-notification") &&
             !this.contentType.SubType.Equals("global-delivery-status"))) {
          if (this.transferEncoding == EncodingQuotedPrintable) {
            // DEVIATION: Treat quoted-printable for multipart and message
            // as 7bit instead
            this.transferEncoding = EncodingSevenBit;
          } else {
            string exceptText =
              "Invalid content encoding for multipart or message";
#if DEBUG
            exceptText += " [type=" + this.contentType + "]";
#endif
            throw new MessageDataException(exceptText);
          }
        }
      }
    }
コード例 #6
0
   /// <include file='../../docs.xml'
   /// path='docs/doc[@name="M:PeterO.Mail.ContentDisposition.Parse(System.String,PeterO.Mail.ContentDisposition)"]/*'/>
   public static ContentDisposition Parse(
 string dispositionValue,
 ContentDisposition defaultValue) {
     if (dispositionValue == null) {
       throw new ArgumentNullException("dispositionValue");
     }
     ContentDisposition dispo = ParseDisposition(dispositionValue);
     return dispo ?? defaultValue;
   }
コード例 #7
0
    /// <include file='../../docs.xml'
    /// path='docs/doc[@name="M:PeterO.Mail.ContentDisposition.Parse(System.String,PeterO.Mail.ContentDisposition)"]/*'/>
    public static ContentDisposition Parse(
string dispositionValue,
ContentDisposition defaultValue) {
      if (dispositionValue == null) {
        throw new ArgumentNullException("dispositionValue");
      }
      var dispo = new ContentDisposition();
      dispo.parameters = new Dictionary<string, string>();
      return (!dispo.ParseDisposition(dispositionValue)) ? defaultValue : dispo;
    }
コード例 #8
0
 private static ContentDisposition Build(string name) {
   var dispo = new ContentDisposition();
   dispo.parameters = new Dictionary<string, string>();
   dispo.dispositionType = name;
   return dispo;
 }