CDO.Messageで日本語ファイル名が文字化け 解決編

文字化けの原因はこちら。
http://d.hatena.ne.jp/m-tanaka/20070528


でも、CDO上で文字化けしていても、OWA上で見ると文字化けしていないので、
どこかに、文字化けしていない情報があるのではないかと思って調べていたところ、
WebDAVでファイル名を取得すると文字化けしていないことが判明。

方法はこちら


//接続用のXMLHttpオブジェクトを生成
interop.msxml3.XMLHTTP30 oXMLHttp = new interop.msxml3.XMLHTTP30();

//The WebDAVX-MS-ENUMATTS Method is used to enumerate the attachments of an e-mail message.
//The X-MS-ENUMATTS Method will return different properties on each e-mail message attachment, depending on how the message was sent.
//The following table lists the attachment properties returned for different messages.
//http://msdn2.microsoft.com/en-us/library/aa126042.aspx

//attachmentInfoUrl:EMLファイルのURL
oXMLHttp.open("X-MS-ENUMATTS", attachmentInfoUrl, false, user, password);

oXMLHttp.setRequestHeader("Depth", "1");
oXMLHttp.setRequestHeader("Content-type", "xml");
oXMLHttp.send(null);

//WebDAVからの結果を取得
//例)
//
//
//
// http://hostname/Exchange/exchange.test1/Inbox/bb.EML/ファイル名.xls
//
// HTTP/1.1 200 OK
//
// xls
// captio~1.xls
// 1
// -1
// application/vnd.ms-excel
// 515648
// 0
// ファイル名.xls
// ファイル名.xls
//

//

//

//

string s = oXMLHttp.responseText;

//DOMアクセスのためのオブジェクトを作成し、取得結果をロードする
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(s);

XmlNamespaceManager nsmgr = new XmlNamespaceManager (xmlDoc.NameTable);
nsmgr.AddNamespace ("e", "urn:schemas:httpmail:");
nsmgr.AddNamespace ("a", "DAV:");

//指定された番号のノードの下のノードを取得する
int attachmentNodeNum = attachmentCount + 1;
XmlNode node = xmlDoc.SelectSingleNode("//a:response[" + attachmentNodeNum +"]//e:attachmentfilename",nsmgr);

WriteLog("InnerText \r\n" + node.InnerText);

//取得したノードのInnerTextがファイル名