本文整理汇总了C#中Attachment.SetBody方法的典型用法代码示例。如果您正苦于以下问题:C# Attachment.SetBody方法的具体用法?C# Attachment.SetBody怎么用?C# Attachment.SetBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attachment
的用法示例。
在下文中一共展示了Attachment.SetBody方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseMime
private static void ParseMime(Stream reader, string boundary, ref int maxLength, ICollection<Attachment> attachments, Encoding encoding, char? termChar)
{
var maxLengthSpecified = maxLength > 0;
string data,
bounderInner = "--" + boundary,
bounderOuter = bounderInner + "--";
do {
data = reader.ReadLine(ref maxLength, encoding, termChar);
} while (data != null && !data.StartsWith(bounderInner));
while (data != null && !data.StartsWith(bounderOuter) && !(maxLengthSpecified && maxLength == 0)) {
data = reader.ReadLine(ref maxLength, encoding, termChar);
var a = new Attachment { Encoding = encoding };
var part = new StringBuilder();
// read part header
while (!data.StartsWith(bounderInner) && data != string.Empty && !(maxLengthSpecified && maxLength == 0)) {
part.AppendLine(data);
data = reader.ReadLine(ref maxLength, encoding, termChar);
}
a.RawHeaders = part.ToString();
// header body
// check for nested part
var nestedboundary = a.Headers.GetBoundary();
if (!string.IsNullOrEmpty(nestedboundary)) {
ParseMime(reader, nestedboundary, ref maxLength, attachments, encoding, termChar);
} else {
data = reader.ReadLine(ref maxLength, a.Encoding, termChar);
var body = new StringBuilder();
while (!data.StartsWith(bounderInner) && !(maxLengthSpecified && maxLength == 0)) {
body.AppendLine(data);
data = reader.ReadLine(ref maxLength, a.Encoding, termChar);
}
a.SetBody(body.ToString());
attachments.Add(a);
}
}
}
示例2: ParseMime
private void ParseMime(TextReader reader, string boundary)
{
string data,
bounderInner = "--" + boundary,
bounderOuter = bounderInner + "--";
do {
data = reader.ReadLine();
} while (data != null && !data.StartsWith(bounderInner));
while (data != null && !data.StartsWith(bounderOuter)) {
data = reader.ReadLine();
var a = new Attachment();
var part = new StringBuilder();
// read part header
while (!data.StartsWith(bounderInner) && data != string.Empty) {
part.AppendLine(data);
data = reader.ReadLine();
}
a.RawHeaders = part.ToString();
// header body
data = reader.ReadLine();
var body = new StringBuilder();
while (data != null && !data.StartsWith(bounderInner)) {
body.AppendLine(data);
data = reader.ReadLine();
}
// check for nested part
string nestedboundary = a.Headers.GetBoundary();
if (!string.IsNullOrEmpty(nestedboundary)) {
using (var nestedReader = new System.IO.StringReader(body.ToString()))
ParseMime(nestedReader, nestedboundary);
} else { // nested
a.SetBody(body.ToString());
Attachments.Add(a);
}
}
}
示例3: ParseMime
private void ParseMime(Stream reader, string boundary, int maxLength)
{
var maxLengthSpecified = maxLength > 0;
string data,
bounderInner = "--" + boundary,
bounderOuter = bounderInner + "--";
do {
data = reader.ReadLine(ref maxLength, Encoding);
} while (data != null && !data.StartsWith(bounderInner));
while (data != null && !data.StartsWith(bounderOuter) && (maxLength > 0 || !maxLengthSpecified)) {
data = reader.ReadLine(ref maxLength, Encoding);
var a = new Attachment { Encoding = Encoding };
var part = new StringBuilder();
// read part header
while (!data.StartsWith(bounderInner) && data != string.Empty) {
part.AppendLine(data);
data = reader.ReadLine(ref maxLength, Encoding);
}
a.RawHeaders = part.ToString();
// header body
data = reader.ReadLine(ref maxLength, Encoding);
var body = new StringBuilder();
while (data != string.Empty && !data.StartsWith(bounderInner)) {
body.AppendLine(data);
data = reader.ReadLine(ref maxLength, Encoding);
}
// check for nested part
string nestedboundary = a.Headers.GetBoundary();
if (!string.IsNullOrEmpty(nestedboundary)) {
ParseMime(body.ToString(), nestedboundary);
} else { // nested
a.SetBody(body.ToString());
(a.IsAttachment ? Attachments : AlternateViews).Add(a);
}
}
if (maxLength > 0)
data = reader.ReadToEnd(maxLength, Encoding);
}