本文整理汇总了C#中MailMessage.AddCustomHeader方法的典型用法代码示例。如果您正苦于以下问题:C# MailMessage.AddCustomHeader方法的具体用法?C# MailMessage.AddCustomHeader怎么用?C# MailMessage.AddCustomHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MailMessage
的用法示例。
在下文中一共展示了MailMessage.AddCustomHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DumpMapiProperties
private void DumpMapiProperties(IMessage inMsg, MailMessage outMsg)
{
String header, body;
//Get the original transport headers, and parse them out
String xportHdrs = MapiUtils.GetStringProperty(inMsg, Tags.PR_TRANSPORT_MESSAGE_HEADERS);
if (xportHdrs == null) {
return;
}
//Each header line consists of the header, whitespace, colon, whitespace, value
Regex hdrLineRex = new Regex(@"
(?# Match single- and multi-line SMTP headers )
(?<header> (?# The header element... )
[a-z0-9\-]+ (?# consists of letters, numbers, or hyphens.)
) (?# the header is followed by...)
\s*:\s* (?# ...optional whitespace, a colon, additional optional whitespace...)
(?<value> (?# ...and the value of the header, which is ...)
.*? (?# ...any character, possibly spanning multiple lines...)
)
(?=\r\n\S|\n\S|\z)(?# ...delimited by the start of another line w/ non-whitespace, or the end of the string)
",
RegexOptions.IgnoreCase | //Obviously, case-insensitive
RegexOptions.Multiline | //Need to match potentially multi-line SMTP headers
RegexOptions.Singleline | //and . matches newlines as well
RegexOptions.IgnorePatternWhitespace //Ignore the pattern whitespace included for readability
);
foreach (Match match in hdrLineRex.Matches(xportHdrs)) {
if (match.Success) {
header = match.Groups["header"].Value;
body = match.Groups["value"].Value;
//If this header isn't one of the built-in ones that will be generated automatically
//by OpenSmtp.net
if (header.ToLower() != "to" &&
header.ToLower() != "from" &&
header.ToLower() != "reply-to" &&
header.ToLower() != "date" &&
header.ToLower() != "subject" &&
header.ToLower() != "cc" &&
header.ToLower() != "bcc" &&
header.ToLower() != "mime-version" &&
header.ToLower() != "content-type" &&
header.ToLower() != "content-transfer-encoding") {
//OpenSmtp isn't smart enough to recognize multi-line header values, and wants to
//quoted-printable them because of the CR/LF control chars. So, straighten multi-line values out
body = Regex.Replace(body, @"\r\n\s+|\n\s+", " ");
outMsg.AddCustomHeader(header, body);
}
}
}
//Now dump all of the MAPI properties as X- headers just in case they're needed
Tags[] propIds;
inMsg.GetPropList(0, out propIds);
foreach (Tags propId in propIds) {
//Skip properties that are too big or redundant
if (propId == Tags.ptagBody ||
propId == Tags.ptagBodyHtml ||
propId == Tags.ptagHtml ||
propId == Tags.PR_BODY ||
propId == Tags.PR_BODY_HTML ||
propId == Tags.PR_RTF_COMPRESSED ||
propId == Tags.PR_TRANSPORT_MESSAGE_HEADERS) {
continue;
}
header = String.Format("X-{0}", propId);
try {
Value val = MapiUtils.GetProperty(inMsg, propId);
if (val is MapiBinary) {
//Binary values aren't good for much
continue;
}
if (val == null) {
body = "<null>";
} else {
body = val.ToString();
//Cannot have line breaks in SMTP headers, so if there are any, escape them
body = body.Replace("\n", @"\n");
body = body.Replace("\r", @"\r");
body = body.Replace("\t", @"\t");
}
outMsg.AddCustomHeader(header, body);
} catch (MapiException e) {
outMsg.AddCustomHeader("X-Exception", String.Format("Error getting property: {0}", e.Message));
}
}
}
示例2: AddMessage
public void AddMessage(IMessage msg)
{
//Check the msg class. If this is a non-delivery report, I don't know how to handle that
String msgClass = MapiUtils.GetStringProperty(msg, Tags.PR_MESSAGE_CLASS);
if (msgClass == "REPORT.IPM.Note.NDR") {
return;
}
//A maildir is a folder full of files named thusly:
// [timestamp].[uniqueid].[hostname]
//
// timestamp is simply the total seconds of the message time stamp
// uniqueid is some system-generated ID that is unique within the namespace
// of the hostname and timestamp.
// hostname is the name of the host delivering the mail.
//
// since we're bulk-loading messages and can assume no other source is
// submitting them, cop out on the uniqueid and just use a randomly-seeded, increasing counter
//
// In addition, for msgs in 'cur' (which all of these are), the file name can be followed by the following:
// (source: http://cr.yp.to/proto/maildir.html)
//When you move a file from new to cur, you have to change its name from uniq to uniq:info. Make sure to preserve the uniq string, so that separate messages can't bump into each other.
//
//info is morally equivalent to the Status field used by mbox readers. It'd be useful to have MUAs agree on the meaning of info, so I'm keeping a list of info semantics. Here it is.
//
//info starting with "1,": Experimental semantics.
//
//info starting with "2,": Each character after the comma is an independent flag.
//
// * Flag "P" (passed): the user has resent/forwarded/bounced this message to someone else.
// * Flag "R" (replied): the user has replied to this message.
// * Flag "S" (seen): the user has viewed this message, though perhaps he didn't read all the way through it.
// * Flag "T" (trashed): the user has moved this message to the trash; the trash will be emptied by a later user action.
// * Flag "D" (draft): the user considers this message a draft; toggled at user discretion.
// * Flag "F" (flagged): user-defined flag; toggled at user discretion.
//
//New flags may be defined later. Flags must be stored in ASCII order: e.g., "2,FRS".
//
// From empirical study of Courier-IMAP Maildirs, there's also a 'S=whatever' before the flags. So:
// whatever:2,S=12345,RS.
//
// Apparently this makes it faster for Courier to get messages sizes for quota enforcement purposes. However
//tbird at least don't seem to know what to do w/ this, so I won't include size info.
//
//The contents of each file are in standard RFC 2822 format.
//TODO: Use PR_MSG_STATUS for R, D, T, F
DateTime recvTime = MapiUtils.GetSysTimeProperty(msg, Tags.ptagMsgDeliveryTime);
int size = MapiUtils.GetLongProperty(msg, Tags.PR_MESSAGE_SIZE);
int flags = MapiUtils.GetLongProperty(msg, Tags.PR_MESSAGE_FLAGS);
bool read = ((flags & (int)MAPI33.WellKnownValues.PR_MESSAGE_FLAGS.Read) != 0);
bool draft = ((flags & (int)MAPI33.WellKnownValues.PR_MESSAGE_FLAGS.Unsent) != 0);
//Update the unique id
_lastUniqueId += 1 + new Random().Next(100);
String name = recvTime.Ticks.ToString();
name += ".";
name += _lastUniqueId.ToString();
name += ".";
name += System.Net.Dns.GetHostName();
//LAME: Colons in filenames aren't supported coz the path canonicalizer is too lazy to know the difference
//between an alt data stream and just a plain colon. Bogus.
name += ";2,";
//name += "S=" + size.ToString() + ","; tbird doesn't know what to do w/ this
if (read) {
name += "S";
}
if (draft) {
name += "D";
}
//Create a message object
MailMessage outMsg = new MailMessage();
outMsg.Date = recvTime;
//Depending upon the message class, use different logic to populate the message
if (msgClass == "IPM.Note") {
ProcessMailMessage(msg, outMsg);
} else if (msgClass == "IPM.Contact") {
ProcessContact(msg, outMsg);
return; //TODO: don't skip
} else if (msgClass == "IPM.Calendar") {
ProcessAppointment(msg, outMsg);
return; //TODO: don't skip
} else if (msgClass == "IPM.Task") {
ProcessTask(msg, outMsg);
return; //TODO: don't skip
} else if (msgClass == "IPM.StickyNote") {
ProcessNote(msg, outMsg);
return; //TODO: don't skip
} else {
ProcessUnknownMsgClass(msg, outMsg);
return; //TODO: don't skip
}
outMsg.AddCustomHeader("X-ConvertedFromMapi",
String.Format("Adam Nelson's Mapi to Maildir Converter. {0}", DateTime.Now.ToString()));
//.........这里部分代码省略.........