按 id 移动邮件列表的邮件
Move an mail of a list of mail by the id
我需要从 class 读取的 5 封邮件列表中移出一封邮件。此邮件已由我创建的逻辑处理并满足创建的条件。问题是它移动了那 5 封电子邮件,其中一些不符合条件。如果满足条件的邮件成功将数据输入数据库,则必须将其移至处理过的邮件文件夹,否则将其移至错误文件夹。
这是接收电子邮件的class
int bufferLength = 5;
int indiceMail = 0;
string from = "mail@gmail.com>";
do
{
emailList.getEmails(bufferLength);
while(indiceMail<emailList.emails.Count)
{
indiceMail++;
}
Console.WriteLine("Reading: {0}", emailList.emails.Count);
}while (emailList.MoreAvailable);
这就是移动邮件的条件
string bodyMail = emailList.emails[indiceMail].body;
match3 = Regex.Match(bodyMail, @"(?<=Status:) (\S+\b)");
statuscompare = match3.Value;
List<String> statusList = new List<string> { "i2", "i3", "i4", "i8" };
bool ex = false;
foreach (string item1 in statusList)
{
if (item1.Contains(statuscompare.Trim()))
{
ex = true;
if (item1.Contains("i4"))
{
bool moveEmail = false;
foreach (Email item in emailList.emails)
{
if (emailList.emails[indiceMail].body.Contains("i4"))
{
// if (item.body.Contains(item1))
//{
moveEmail = true;
emailList.moveMail(item.id, emailList.config.PathSuccess);
break;
// }
}
if (moveEmail)
{
continue;
}
}
}
}
}
这是 class 移动邮件的一部分
public void moveMail(string emailId, string folderPath)
{
string folderId = getMailFolderId(folderPath);
EmailMessage message = EmailMessage.Bind(service, emailId);
message.Move(folderId);
}
处理错误的电子邮件后,将标志 'emailbool' 设置为 false,这会将所有其他电子邮件移至 PathSuccess。不确定 emailbool 实际上是如何服务于任何目的的,除了确保只有一封来自所有人的电子邮件进入错误路径。
foreach (Email item in emailList.emails)
{
// This IF statement will either be true of false for ALL items.
if (!Cmmd.Parameters["p_retorno"].Value.ToString().Equals("0"))
{
emailList.moveMail(item.id, emailList.config.PathError);
}
else
{
emailList.moveMail(item.id, emailList.config.PathSuccess);
}
}
编辑:
对于您发布的新代码,请尝试将所有包含来自 statusList 的任何字符串的电子邮件移动到其正文中。
// This will move all emails that have one or more statusList in their body
foreach (Email item in emailList.emails)
{
if (statusList.Where(x => item.body.Contains(x)).Count > 0)
{
emailList.moveMail(item.id, emailList.config.PathSuccess);
break; // This statement will stop processing of any other emails.
}
}
我需要从 class 读取的 5 封邮件列表中移出一封邮件。此邮件已由我创建的逻辑处理并满足创建的条件。问题是它移动了那 5 封电子邮件,其中一些不符合条件。如果满足条件的邮件成功将数据输入数据库,则必须将其移至处理过的邮件文件夹,否则将其移至错误文件夹。
这是接收电子邮件的class
int bufferLength = 5;
int indiceMail = 0;
string from = "mail@gmail.com>";
do
{
emailList.getEmails(bufferLength);
while(indiceMail<emailList.emails.Count)
{
indiceMail++;
}
Console.WriteLine("Reading: {0}", emailList.emails.Count);
}while (emailList.MoreAvailable);
这就是移动邮件的条件
string bodyMail = emailList.emails[indiceMail].body;
match3 = Regex.Match(bodyMail, @"(?<=Status:) (\S+\b)");
statuscompare = match3.Value;
List<String> statusList = new List<string> { "i2", "i3", "i4", "i8" };
bool ex = false;
foreach (string item1 in statusList)
{
if (item1.Contains(statuscompare.Trim()))
{
ex = true;
if (item1.Contains("i4"))
{
bool moveEmail = false;
foreach (Email item in emailList.emails)
{
if (emailList.emails[indiceMail].body.Contains("i4"))
{
// if (item.body.Contains(item1))
//{
moveEmail = true;
emailList.moveMail(item.id, emailList.config.PathSuccess);
break;
// }
}
if (moveEmail)
{
continue;
}
}
}
}
}
这是 class 移动邮件的一部分
public void moveMail(string emailId, string folderPath)
{
string folderId = getMailFolderId(folderPath);
EmailMessage message = EmailMessage.Bind(service, emailId);
message.Move(folderId);
}
处理错误的电子邮件后,将标志 'emailbool' 设置为 false,这会将所有其他电子邮件移至 PathSuccess。不确定 emailbool 实际上是如何服务于任何目的的,除了确保只有一封来自所有人的电子邮件进入错误路径。
foreach (Email item in emailList.emails)
{
// This IF statement will either be true of false for ALL items.
if (!Cmmd.Parameters["p_retorno"].Value.ToString().Equals("0"))
{
emailList.moveMail(item.id, emailList.config.PathError);
}
else
{
emailList.moveMail(item.id, emailList.config.PathSuccess);
}
}
编辑:
对于您发布的新代码,请尝试将所有包含来自 statusList 的任何字符串的电子邮件移动到其正文中。
// This will move all emails that have one or more statusList in their body
foreach (Email item in emailList.emails)
{
if (statusList.Where(x => item.body.Contains(x)).Count > 0)
{
emailList.moveMail(item.id, emailList.config.PathSuccess);
break; // This statement will stop processing of any other emails.
}
}