您的位置:首页 > 编程语言 > C#

parsing eml files with c#

2009-05-22 15:21 357 查看
using System;
using System.IO;
using System.Text.RegularExpressions;

namespace parse.eml
{
class Email
{
string _path,_to,_from,_subject,_urls;

public Email(string path)
{
_path = path;
string fc = new StreamReader(path).ReadToEnd();
_from = Regex.Matches(fc, "From: (.+)")[0].ToString();
_to = Regex.Matches(fc, "To: (.+)")[0].ToString();
_subject = Regex.Matches(fc, "Subject: (.+)")[0].ToString();
_urls = string.Empty;
foreach (Match m in Regex.Matches(fc,@"https?://([a-zA-Z\.]+)/"))
{
_urls += m.ToString() + ' ';
}
}

public void show()
{
Console.WriteLine(
"{0}\n\t{1}\n\t{2}\n\t{3}\n\t{4}",
_path, _to, _from, _subject, _urls);
}

}

class Program
{
static void Main(string[] args)
{
foreach (string f in Directory.GetFiles(".", "*.eml"))
{
Email e = new Email(f);
e.show();
}
}
}
}

test?

[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: