1

IMAP プロトコルを使用して、受信トレイから電子メールを取得します。ここで、MailMessage のリストである Result を RawContent に変換する必要があります。それを OpenPop.Pop3 メッセージに変換するには、しかし、使用すると

var メッセージ = 新しい OpenPop.Mime.Message(rawMessage);

コンテンツにペルシャ語のコンテンツが含まれている場合、たとえば、メール ヘッダーの「差出人」または「宛先」セクションに表示名が「مسعودگبرامی」の場合、それを OpenPop メッセージに変換した後、「????????????」に変換されます。 ??????」

MailMessage から RawMessage を抽出するためのコードは次のとおりです。

private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.NonPublic;
    private static readonly Type MailWriter = typeof(SmtpClient).Assembly.GetType("System.Net.Mail.MailWriter");
    private static readonly ConstructorInfo MailWriterConstructor = MailWriter.GetConstructor(Flags, null, new[] { typeof(Stream) }, null);
    private static readonly MethodInfo CloseMethod = MailWriter.GetMethod("Close", Flags);
    private static readonly MethodInfo SendMethod = typeof(MailMessage).GetMethod("Send", Flags);

    /// <summary>
    /// A little hack to determine the number of parameters that we
    /// need to pass to the SaveMethod.
    /// </summary>
    private static readonly bool IsRunningInDotNetFourPointFive = SendMethod.GetParameters().Length == 3;

    /// <summary>
    /// The raw contents of this MailMessage as a MemoryStream.
    /// </summary>
    /// <param name="self">The caller.</param>
    /// <returns>A MemoryStream with the raw contents of this MailMessage.</returns>
    public static MemoryStream RawMessage(this MailMessage self)
    {
        var result = new MemoryStream();

        var mailWriter = MailWriterConstructor.Invoke(new object[] { result });
        SendMethod.Invoke(self, Flags, null, IsRunningInDotNetFourPointFive ? new[] { mailWriter, true, true } : new[] { mailWriter, true }, null);
        result = new MemoryStream(result.ToArray());
        CloseMethod.Invoke(mailWriter, Flags, null, new object[] { }, null);
        return result;
    }
4

1 に答える 1

0

交換してみる

結果 = 新しい MemoryStream(result.ToArray());

と:

結果 = 新しい MemoryStream(Encoding.UTF8.GetBytes(result.ToArray().ToString()));

それが役に立てば幸い。

于 2016-02-22T05:27:52.133 に答える