日本語のMail Messagesの”Subject”と”Body”が文字化けします

こんにちは
UiPath Studio 2025.0.167STS Community editionのユーザーです。

“Get POP3 Mail Messages”アクティビティで取得したメール30通をList<MailMessages>に入れて、For EachアクティビティをcurrentMailMesaagesで回して、データテーブルに行追加して
最後にDate,Subject,BodyをExcelにWriteRangeしたところ、日本語にも関わらず、一部のSubject,Bodyが文字化けしました。

生成AIに相談して、invoke methodでエンコーディングプロバイダを呼び出した後、For Eachアクティビティで下記の代入アクティビティを実行してみても効果はありませんでした。

currentMailMessage.Subject = System.Text.Encoding.GetEncoding("shift_jis").GetString(System.Text.Encoding.Default.GetBytes(currentMailMessage.Subject))
currentMailMessage.Body = System.Text.Encoding.GetEncoding("shift_jis").GetString(System.Text.Encoding.Default.GetBytes(currentMailMessage.Body))

良い対策はありませんか?

こんにちは

上記のデータをみた感じ、文字コードがiso-2022-jpぽいのて、こちらでデコードしてみてください。

おはようございます。
iso-2022-jpで試したら、Shift-Jisで文字化けしたテキストは正常に表示されましたが、
Shift-Jisで正常に表示されたテキストが文字化けしました。(下図参照)両方のコードが混在しているようです。

String変数の内容からどちらの文字コードであるかを識別するアルゴリズムをご紹介ください。
下記を見るとmacを除けば日本語で対応が必要なコードは下記くらいでしょうか?
“shift_jis”、“iso-2022-jp”、“EUCJP”、“UTF8”

続報です。

currentMailMessage.Bodyが“shift_jis”、“iso-2022-jp”、“EUCJP”、“UTF8”の文字コードかチェックする4つの条件分岐を入れて
該当すれば、currentMailMessage.BodyとcurrentMailMessage.Subjectを該当文字コードに変換するアルゴリズムをFor Eachアクティビティ内に追加してワークフローをデバッグした
ところ、currentMailMessage.BodyはすべてExcelで読める状態になりましたが、currentMailMessage.Subjectの一部がまだ文字化けしています。(添付画像参照)

2点質問します。
1.currentMailMessage.BodyとcurrentMailMessage.Subjectで文字コードが異なるケースがあるのでしょうか?

2.下記2つの構文は正しいでしょうか?

・条件分岐アクティビティで、currentMailMessage.Subjectの文字コードが“shift_jis”であればTrueになる条件文

currentMailMessage.Subject = System.Text.Encoding.GetEncoding("shift_jis").GetString(System.Text.Encoding.Default.GetBytes(currentMailMessage.Subject))

・代入アクティビティでcurrentMailMessage.Subjectの文字コードを“shift_jis”にエンコードする構文

currentMailMessage.Subject=System.Text.Encoding.GetEncoding("shift_jis").GetString(System.Text.Encoding.Default.GetBytes(currentMailMessage.Subject))

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.