2009-08-12 19 views
6

Outlookのmsgファイルから内容を読み込む必要があります。現在、私はCodeProject.comプロジェクトのクラスを使用しています。これは、VSTOとOutlookをサーバーにデプロイすることができないためです。Outlook APIなしでOutlook MSGファイルから受信日を読み取るにはどうすればよいですか?

このクラスは、To、From、CC、Subject、Bodyなど、日付情報(Received DateやSent Dateなど)以外のmsgファイルから必要なものを取得します。

MSDNのmsgファイルを取得する方法については、実際には(実際には、実際には低レベルの)documentationがありますが、このプロジェクトの範囲を少し超えていて、日付はまったくありません。

理想的には私が今使っているクラス(以前に言及したCodeProjectのOutlookStorage.cs)をドロップインで置き換えたり、既存のクラスを少し修正することができます。変更するには、受け取った日付の正しい4文字の16進小数点識別子が必要です。たとえば、SubjectはPR_SUBJECT = "0037"、BodyはPR_BOY = "1000"と表示されます。

答えて

2

私はあなたが望むようにライブラリを作ってくれると思っています。それはあなたが望むものではないかもしれません。その周りにいくつかのVBスクリプトは、翻訳される可能性のあるmsgファイルから基本的な情報を取得します。あなたの2つのポストを組み合わせること

1

thisからヒントを得た:

string fullFileName = "c:\message.msg"; 
DateTime dateRevieved = new DateTime(); 

StreamReader sr = new StreamReader(fullFileName, Encoding.Default); 
string full = sr.ReadToEnd(); 

string date; 
int iStart; 
int iLast; 

string caption; 

//This -should- handle all manner of screwage 
//The ONLY way it would not is if someone guessed the -exact- to-the-second 
//time that they send the message, put it in their subject in the right format 
while (true) {  //not an infinite loop, I swear! 

    caption = "Date:"; 
    if (full.IndexOf("Date:") > -1) { //full shortens with each date is removed 
     string temp = ""; 

     iStart = full.LastIndexOf(caption); 
     temp = full.Remove(0, iStart + caption.Length); 
     full = full.Substring(0, iStart); 

     iLast = temp.IndexOf("\r\n"); 
     if (iLast < 0) { 
      date = temp; 
     } else { 
      date = temp.Substring(0, iLast); 
     } 

     date = date.Trim(); 

     if (date.Contains(subject) || subject.Contains(date)) { 
      continue; //would only happen if someone is trying to screw me 
     } 

     try { 
      dateRevieved = DateTime.Parse(date); //will fail if not a date 
      break; //if not a date breaks out of while loop 
     } catch { 
      continue; //try with a smaller subset of the msg 
     } 
    } else { 
     break; 
    } 
} 

これは、あなたが何かこのlovely projectを使用して、MSGファイルから他のものを得ることができる方法に比べてハックの一種です。それでも、私はそれを投げ捨てたものすべてに立ち向かいました。そして、注記したように、ちょうど2番目の日付を適切な形式で件名に記入することです。

1

私は、次の解決策を示唆している:修正するには

を、私が受け取った日付の正しい4文字の16進数の小道具の識別子が必要になります。たとえば、SubjectはPR_SUBJECT = "0037"、BodyはPR_BOY = "1000"と表示されます。

"007D"を探します。

受信したデータの2番目の投稿に投稿した方法を使用して、同じ(日付)文字列が件名の中にあるときに問題を解消します。


私は、この方法は、内部の電子メール上で動作するようには思えないことを言及する必要があります:私は同僚から受け取ったメールには、何のsubstg1.0_007Dxxxx-プロパティはありません。

ここで、日付はsubstg1.0_0047xxxxに隠れているようです。

すべてベスト!あなたがCodeProjectのからOutlookStorage.csを使用している場合は、以下を追加し

INNO

7

private const string PR_RECEIVED_DATE="007D"; 
private const string PR_RECEIVED_DATE_2 = "0047"; 

... 

/// <summary> 
/// Gets the date the message was received. 
/// </summary> 
public DateTime ReceivedDate 
{ 
    get 
    { 
     if (_dateRevieved == DateTime.MinValue) 
     { 
      string dateMess = this.GetMapiPropertyString(OutlookStorage.PR_RECEIVED_DATE); 
      if (String.IsNullOrEmpty(dateMess)) 
      { 
       dateMess = this.GetMapiPropertyString(OutlookStorage.PR_RECEIVED_DATE_2); 
      } 
      _dateRevieved = ExtractDate(dateMess); 
     } 
     return _dateRevieved; 
     //return ExtractDate(dateMess); 
    } 
} 

private DateTime _dateRevieved = DateTime.MinValue; 

private DateTime ExtractDate(string dateMess) 
{ 
    string matchStr = "Date:"; 

    string[] lines = dateMess.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); 
    foreach (string line in lines) 
    { 
     if (line.StartsWith(matchStr)) 
     { 
      string dateStr = line.Substring(matchStr.Length); 
      DateTime response; 
      if (DateTime.TryParse(dateStr, out response)) 
      { 
       return response; 
      } 
     } 
    } 
    return DateTime.MinValue;     
} 
関連する問題