[Csmail-patches] CVS: csmail/src/CSMail ContentDispositionType.cs,NONE,1.1 ChangeLog,1.61,1.62 Conte
Status: Pre-Alpha
Brought to you by:
mastergaurav
From: Gaurav V. <mas...@us...> - 2002-10-30 09:54:19
|
Update of /cvsroot/csmail/csmail/src/CSMail In directory usw-pr-cvs1:/tmp/cvs-serv29562 Modified Files: ChangeLog ContentDisposition.cs MimeBodyPart.cs Added Files: ContentDispositionType.cs Log Message: 2002-10-30 * ContentDisposition.cs : Made a class. Added fancy features. * ContentDispositionType.cs : Replaces ContentDisposition. : Added member "NotDefined". * MimeBodyPart.cs : Disposition { get; set; } - Removed implementation. Will freshen it. --- NEW FILE --- /** * Namespace: CSMail * Enumeration: ContentDispositionType * * Author: Gaurav Vaish * Maintainer: mastergaurav AT users DOT sf DOT net * * (C) Gaurav Vaish (2002) */ namespace CSMail { /// <summary> /// The "Content-Disposition" options. /// </summary> public enum ContentDispositionType { /// <summary> /// Tells /// <M:CSMail.Utils.MimeUtils.SetDisposition(MimePart,ContentDisposition)/> /// to remove the "Content-Disposition" header. NotDefined, /// <summary> /// The current part is an attachment. /// </summary> Attachment, /// <summary> /// The current part is an inline content. /// </summary> Inline } } Index: ChangeLog =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/ChangeLog,v retrieving revision 1.61 retrieving revision 1.62 diff -u -r1.61 -r1.62 --- ChangeLog 25 Oct 2002 10:33:00 -0000 1.61 +++ ChangeLog 30 Oct 2002 09:54:16 -0000 1.62 @@ -1,4 +1,13 @@ +2002-10-30 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * ContentDisposition.cs : Made a class. Added fancy features. + * ContentDispositionType.cs + : Replaces ContentDisposition. + : Added member "NotDefined". + * MimeBodyPart.cs : Disposition { get; set; } - Removed + implementation. Will freshen it. + 2002-10-25 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * InternetAddress.cs : Equals(InternetAddress) - Implemented. Index: ContentDisposition.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/ContentDisposition.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ContentDisposition.cs 5 Sep 2002 05:17:49 -0000 1.2 +++ ContentDisposition.cs 30 Oct 2002 09:54:16 -0000 1.3 @@ -8,20 +8,117 @@ * (C) Gaurav Vaish (2002) */ +using System; +using CSMail.Utils; + namespace CSMail { /// <summary> /// The "Content-Disposition" options. /// </summary> - public enum ContentDisposition + public class ContentDisposition { - /// <summary> - /// The current part is an attachment. - /// </summary> - Attachment, - /// <summary> - /// The current part is an inline content. - /// </summary> - Inline + private ContentDispositionType type; + private ParameterList parameters; + + public ContentDisposition() + { + type = ContentDispositionType.NotDefined; + parameters = new ParameterList(); + } + + public ContentDisposition(string headerLine) + { + if(!headerLine.ToLower().StartsWith("content-disposition")) + throw new ArgumentException("[ContentDisposition] " + + "Value does not start with " + + " \"Content-Disposition:\""); + headerLine = headerLine.Substring(21); + parameters = Parse(headerLine, out type); + } + + public static ParameterList Parse(string headerValue, + out ContentDispositionType cdType) + { + HeaderTokenizer ht = new HeaderTokenizer(headerValue, + Constants.MIMEDelimiters); + HeaderToken token = ht.Next; + if(token.TokenType != HeaderTokenType.Atom) + throw new ParseException("[Parse] The value provided is" + + " illegal"); + cdType = (ContentDispositionType)Enum.Parse( + typeof(ContentDispositionType), + token.Value, true); + string param = ht.Remainder; + ParameterList retVal = null; + if(param != null && param.Trim().Length > 0) + retVal = new ParameterList(param.Trim()); + else + retVal = new ParameterList(); + return retVal; + } + + public ContentDisposition(ContentDispositionType type, + ParameterList parameters) + { + this.type = type; + this.parameters = parameters; + } + + public ContentDispositionType DispositionType + { + get + { + return type; + } + set + { + if(!Enum.IsDefined(typeof(ContentDispositionType), value)) + throw new ArgumentException("[DispositionType]" + + " Illegal value provided."); + type = value; + } + } + + public string FileName + { + get + { + return parameters["FileName"]; + } + set + { + if(value == null || value.Length == 0) + parameters.Remove("FileName"); + else + parameters["FileName"] = value; + } + } + + public ParameterList Parameters + { + get + { + return parameters; + } + set + { + parameters = value; + } + } + + public override string ToString() + { + string retVal = ""; + if(type != ContentDispositionType.NotDefined) + { + retVal = "Content-Disposition: "; + retVal += Enum.Format(typeof(ContentDispositionType), + type, "G").ToLower(); + if(parameters != null) + retVal += ("; " + parameters.ToString()); + } + return retVal; + } } } Index: MimeBodyPart.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/MimeBodyPart.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- MimeBodyPart.cs 9 Oct 2002 07:09:30 -0000 1.9 +++ MimeBodyPart.cs 30 Oct 2002 09:54:16 -0000 1.10 @@ -155,25 +155,15 @@ /// <summary> /// Gets or sets the value of "Content-Disposition" header. /// </summary> - /// <remarks> - /// I will changed the implementation to read from or - /// write to the headers of this part, and not as a part - /// of the PartState. - /// </remarks> public override ContentDisposition Disposition { get { - object o = PartState["Disposition"]; - if(o != null) - return (ContentDisposition)o; - return ContentDisposition.Inline; + throw new NotImplementedException(); } set { - if(!Enum.IsDefined(typeof(ContentDisposition), value)) - throw new ArgumentException("[Disposition] Value cannot be set"); - PartState["Disposition"] = value; + throw new NotImplementedException(); } } |