gpt4 book ai didi

c# - 解析电子邮件文本回复/转发

转载 作者:可可西里 更新时间:2023-11-01 08:11:07 30 4
gpt4 key购买 nike

我正在使用 c# asp.net 创建一个基于 Web 的电子邮件客户端。

令人困惑的是,各种电子邮件客户端在回复电子邮件时似乎以多种不同方式添加原文。

我想知道的是,是否有某种标准化的方式来消除这个过程的歧义?

谢谢-西奥

最佳答案

我在想:

public String cleanMsgBody(String oBody, out Boolean isReply) 
{
isReply = false;

Regex rx1 = new Regex("\n-----");
Regex rx2 = new Regex("\n([^\n]+):([ \t\r\n\v\f]+)>");
Regex rx3 = new Regex("([0-9]+)/([0-9]+)/([0-9]+)([^\n]+)<([^\n]+)>");

String txtBody = oBody;

while (txtBody.Contains("\n\n")) txtBody = txtBody.Replace("\n\n", "\n");
while (new Regex("\n ").IsMatch(txtBody)) txtBody = (new Regex("\n ")).Replace(txtBody, "\n");
while (txtBody.Contains(" ")) txtBody = txtBody.Replace(" ", " ");

if (isReply = (isReply || rx1.IsMatch(txtBody)))
txtBody = rx1.Split(txtBody)[0]; // Maybe a loop through would be better
if (isReply = (isReply || rx2.IsMatch(txtBody)))
txtBody = rx2.Split(txtBody)[0]; // Maybe a loop through would be better
if (isReply = (isReply || rx3.IsMatch(txtBody)))
txtBody = rx3.Split(txtBody)[0]; // Maybe a loop through would be better

return txtBody;
}

关于c# - 解析电子邮件文本回复/转发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2424382/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com