public static void ConstructBodyDisposition(StructureBuilder builder, MIME_Entity entity, MIME_Encoding_EncodedWord wordEncoder) { if (entity.ContentDisposition != null && entity.ContentDisposition.Parameters.Count > 0) { builder.SpaceNBracket().AppendQuoted(entity.ContentDisposition.DispositionType.ToUpperInvariant()); if (entity.ContentDisposition.Parameters.Count > 0) { builder.SpaceNBracket(); bool first = true; foreach (MIME_h_Parameter parameter in entity.ContentDisposition.Parameters) { if (String.IsNullOrEmpty(parameter.Name)) { continue; } // For the first item, don't add SP. if (first) { first = false; } else { builder.Append(" "); } builder.AppendQuoted(parameter.Name.ToUpperInvariant()).SpaceNQuoted(wordEncoder.Encode(parameter.Value)); } builder.EndBracket(); } else { builder.AppendNil(); } builder.EndBracket(); } else { builder.AppendNil(); } }
public static void ConstructEnvelope(StructureBuilder builder, Mail_Message entity) { // date, subject, from, sender, reply-to, to, cc, bcc, in-reply-to, and message-id var wordEncoder = new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.B, Encoding.UTF8); wordEncoder.Split = false; builder.Append("ENVELOPE").SpaceNBracket(); // date try { if (entity.Date != DateTime.MinValue) { builder.Append(TextUtils.QuoteString(MIME_Utils.DateTimeToRfc2822(entity.Date))); } else { builder.Append("NIL"); } } catch { builder.Append("NIL"); } // subject if (entity.Subject != null) { builder.Append(" " + TextUtils.QuoteString(wordEncoder.Encode(entity.Subject))); //string val = wordEncoder.Encode(entity.Subject); //builder.Append(" {").Append(val.Length).Append("}\r\n").Append(val); } else { builder.AppendNil(); } // from if (entity.From != null && entity.From.Count > 0) { builder.Append(" "); ConstructAddresses(builder, entity.From.ToArray(), wordEncoder); } else { builder.AppendNil(); } // sender // NOTE: There is confusing part, according rfc 2822 Sender: is MailboxAddress and not AddressList. if (entity.Sender != null) { builder.SpaceNBracket(); ConstructAddress(builder, entity.Sender, wordEncoder); builder.EndBracket(); } else { builder.AppendNil(); } // reply-to if (entity.ReplyTo != null) { builder.Append(" "); ConstructAddresses(builder, entity.ReplyTo.Mailboxes, wordEncoder); } else { builder.Append(" NIL"); } // to if (entity.To != null && entity.To.Count > 0) { builder.Append(" "); ConstructAddresses(builder, entity.To.Mailboxes, wordEncoder); } else { builder.Append(" NIL"); } // cc if (entity.Cc != null && entity.Cc.Count > 0) { builder.Append(" "); ConstructAddresses(builder, entity.Cc.Mailboxes, wordEncoder); } else { builder.AppendNil(); } // bcc if (entity.Bcc != null && entity.Bcc.Count > 0) { builder.Append(" "); ConstructAddresses(builder, entity.Bcc.Mailboxes, wordEncoder); } else { builder.AppendNil(); } // in-reply-to if (entity.InReplyTo != null) { builder.Append(" ").Append(TextUtils.QuoteString(wordEncoder.Encode(entity.InReplyTo))); } else { builder.AppendNil(); } // message-id if (entity.MessageID != null) { builder.Append(" ").Append(TextUtils.QuoteString(wordEncoder.Encode(entity.MessageID))); } else { builder.AppendNil(); } builder.EndBracket(); }