// Values returns all values associated with the given key. // It is case insensitive; CanonicalMIMEHeaderKey is // used to canonicalize the provided key. To use non-canonical // keys, access the map directly. // The returned slice is not a copy. public static slice <@string> Values(this MIMEHeader h, @string key) { if (h == null) { return(null); } return(h[CanonicalMIMEHeaderKey(key)]); }
// Get gets the first value associated with the given key. // It is case insensitive; CanonicalMIMEHeaderKey is used // to canonicalize the provided key. // If there are no values associated with the key, Get returns "". // To use non-canonical keys, access the map directly. public static @string Get(this MIMEHeader h, @string key) { if (h == null) { return(""); } var v = h[CanonicalMIMEHeaderKey(key)]; if (len(v) == 0L) { return(""); } return(v[0L]); }
// Del deletes the values associated with key. public static void Del(this MIMEHeader h, @string key) { delete(h, CanonicalMIMEHeaderKey(key)); }
// Set sets the header entries associated with key to // the single element value. It replaces any existing // values associated with key. public static void Set(this MIMEHeader h, @string key, @string value) { h[CanonicalMIMEHeaderKey(key)] = new slice <@string>(new @string[] { value }); }
// Add adds the key, value pair to the header. // It appends to any existing values associated with key. public static void Add(this MIMEHeader h, @string key, @string value) { key = CanonicalMIMEHeaderKey(key); h[key] = append(h[key], value); }
public MIMEHeader Parse(string source) { string str; MIMEHeader header = new MIMEHeader(); Regex regex = new Regex("\r\n[ \\t]+"); StringReader reader = new StringReader(regex.Replace(source, " ")); header.ContentType = new ContentType(); while ((str = reader.ReadLine()) != null) { Match match = MailMessageRFCDecoder.regArgument.Match(str); if (match.Success) { switch (match.Groups[1].Value.ToLower()) { case "mime-version": { Version version = this.ParseMimeVersion(str); if ((version.Major != 1) || (version.Minor != 0)) { throw new Exception("MIME version is not 1.0"); } continue; } case "date": { header.Date = this.ParseDate(str).ToLocalTime(); continue; } case "from": { header.From = this.ParseFrom(str); continue; } case "sender": { header.Sender = this.ParseSender(str); continue; } case "reply-to": { header.ReplyTo = this.ParseReplyTo(str); continue; } case "to": { header.To = this.ParseTo(str); continue; } case "cc": { header.CarbonCopies = this.ParseCarbonCopies(str); continue; } case "bcc": { header.BlindedCarbonCopies = this.ParseBlindCarbonCopies(str); continue; } case "message-id": { header.MessageID = this.ParseMessageID(str); continue; } case "in-reply-to": { header.InReplyTo = this.ParseInReplyTo(str); continue; } case "references": { header.References = this.ParseReferences(str); continue; } case "subject": { header.Subject = this.ParseSubject(str); continue; } case "comments": { header.Comments = this.ParseComments(str); continue; } case "keywords": { header.Keywords = this.ParseKeywords(str); continue; } case "content-disposition": { header.ContentDisposition = this.ParseContentDisposition(str); continue; } case "content-id": { header.ContentID = this.ParseContentID(str); continue; } case "resent-date": { header.ResentDate = this.ParseDate(str); continue; } case "resent-from": { header.ResentFrom = this.ParseFrom(str); continue; } case "resent-sender": { header.ResentSender = this.ParseSender(str); continue; } case "resent-to": { header.ResentTo = this.ParseTo(str); continue; } case "resent-cc": { header.ResentCarbonCopies = this.ParseCarbonCopies(str); continue; } case "resent-bcc": { header.ResentBlindedCarbonCopies = this.ParseBlindCarbonCopies(str); continue; } case "resent-message-id": { header.ResentMessageID = this.ParseMessageID(str); continue; } case "return-path": { header.ReturnPath = this.ParseReturnPatch(str); continue; } case "received": { if (string.IsNullOrEmpty(header.Received)) { header.Received = str.Substring(9).Trim(); } continue; } case "content-type": { header.ContentType = this.ParseContentType(str); continue; } case "content-transfer-encoding": { header.ContentTransferEncoding = this.ParseContentTransferEncoding(str); continue; } case "content-description": { header.ContentDescription = this.ParseContentDescription(str); continue; } case "importance": { header.Importance = this.ParseImportance(str); continue; } } DictionaryExtenders.SmartAdd(header.ExtraHeaders, match.Groups[1].Value, match.Groups[2].Value); } } return(header); }