【发布时间】:2019-01-29 15:42:40
【问题描述】:
我有一封电子邮件的 MIME 内容的 Base-64 编码字符串。电子邮件本身包含一个 .p7m 附件。
是否可以使用 Mimekit 解析 mime 内容并提取附件?
谢谢!
【问题讨论】:
标签: c# exchangewebservices mimekit
我有一封电子邮件的 MIME 内容的 Base-64 编码字符串。电子邮件本身包含一个 .p7m 附件。
是否可以使用 Mimekit 解析 mime 内容并提取附件?
谢谢!
【问题讨论】:
标签: c# exchangewebservices mimekit
我并不完全清楚您要做什么,但听起来您只有消息的一个子集(即 MIME 部分之一的 base64 编码内容)。
如果您只想获取原始的smime.p7m 文件附件(这是您拥有的base64 blob 内部的内容),那么您真正需要做的就是调用File.WriteAllBytes ("smime.p7m", Convert.FromBase64String(base64))。
但如果您想执行某些操作(例如解密或验证签名),则需要获取ApplicationPkcs7Mime 表示:
ApplicationPkcs7Mime pkcs7;
using (var stream = new MemoryStream ()) {
byte[] buffer;
// write the Content-Type header
buffer = Encoding.ASCII.GetBytes ("Content-Type: application/pkcs7-mime; name=smime.p7m\r\n");
stream.Write (buffer, 0, buffer.Length);
// write the Content-Type header
buffer = Encoding.ASCII.GetBytes ("Content-Type: application/pkcs7-mime; name=smime.p7m\r\n");
stream.Write (buffer, 0, buffer.Length);
// write the header termination sequence
buffer = Encoding.ASCII.GetBytes ("\r\n");
stream.Write (buffer, 0, buffer.Length);
// write the base64 encoded content
buffer = Encoding.ASCII.GetBytes (base64);
stream.Write (buffer, 0, buffer.Length);
// rewind the stream
stream.Position = 0;
pkcs7 = (ApplicationPkcs7Mime) MimeEntity.Load (stream);
}
现在您可以使用所有 ApplicationPkcs7Mime API。
【讨论】: