2011-03-01 7 views
0

現在、C#でソフトウェア用のプラグインを開発中です。このプラグインは、PSTファイルの内容を抽出し、その中のすべての項目をテキストファイルとして保存します(添付ファイルは電子メールと同じフォルダにその種類として格納されます)。Outlook 2k7統合(P/Invoke経由) - 安全でない添付ファイルをブロックする

Windows 7(Outlook 2K7)でテストするまで問題なく動作しています。以前の同じジョブをOutlook 2000を搭載したマシンで実行したところ、12,000を超えるファイルが見つからなかったことがわかりました。これらのファイルは添付ファイル(ほとんどのURL)であることが判明しました

Outlook 2K7が添付ファイルを特定の拡張子でブロックすることが問題であることがわかりました。 Outlook自体で電子メールを開くと、上部に青いバーが表示され、「潜在的に安全でない可能性のある添付ファイルへのアクセスがブロックされました」と電子メール内のすべての添付ファイルが表示されます。

これらの添付ファイルをOutlookでブロックしないでプログラムで取得する方法はありますか?

我々は添付ファイルを保存するために使用するコードは次のとおりです。他の誰が同じ問題に遭遇した場合に

private void saveAttachment(ref object oEmail, StoreInfo currentStoreInfo, string sEmailID, string sExportPath) 
{ 

    int iAttachCount = 0; 
    object oAttach = null; 
    oAttach = getNextAttachment(oEmail, ref iAttachCount); 

    while (oAttach != null) 
    { 
     saveAttachment(sEmailID, sExportPath, oAttach); 
     oAttach = getNextAttachment(oEmail, ref iAttachCount); 
    } 

} 

private object getNextAttachment(object oEmail, ref int iAttachCount) 
{ 
    object oAttach = null; 

    try 
    { 
     iAttachCount++; 
     oAttach = GetProperty(oEmail, "Attachments", new object[] { iAttachCount }); 
    } 
    catch //(Exception ex) 
    { 
     // There was no attachment to be gotten 
     oAttach = null; 
    } 
    return oAttach; 
} 

答えて

0

はただ、ここでこれを置きます。 Outlook 2K7には、特定の拡張子を持つ添付ファイルへのアクセスをブロックするLevel1ファイルタイプの機能があります。

ただし、これらのファイルへのアクセスを許可するようにレジストリを変更することはできます。セキュリティのために変更する前の状態に戻すようにしてください。

private void SetLevel1RemoveValues() 

    { 
     // Get the base key for the current user HKEY_CURRENT_USER 
     Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, ""); 
     // Get the security key from the registry 
     Microsoft.Win32.RegistryKey subKey = regKey.OpenSubKey("Software\\Microsoft\\Office\\" + sCurrentOutlookVersion + ".0\\Outlook\\Security", true); 

     // If the Outlook\Security key doesn't exit, create one 
     if (subKey == null) 
      subKey = regKey.CreateSubKey("Software\\Microsoft\\Office\\" + sCurrentOutlookVersion + ".0\\Outlook\\Security"); 

     // Loop through each Value in the registry to see if the Level1Remove key already exists. 
     string[] sValues = subKey.GetValueNames(); 

     bool bHasLevel1RemoveKey = false; 
     foreach (string sValue in sValues) 
      if (sValue == "Level1Remove") 
       bHasLevel1RemoveKey = true; 

     // If the key already exists, store the data so we can reset it later 
     if (bHasLevel1RemoveKey) 
      sPrevLevel1RemoveValues = subKey.GetValue("Level1Remove").ToString(); 
     else 
      sPrevLevel1RemoveValues = ""; 

     // Create an array of all Level 1 Extensions 
     string[] level1Extensions = new string[] { ".ade", ".adp", ".app", ".asp", ".bas", ".bat", 
      ".cer", ".chm", ".cmd", ".com", ".cpl", ".crt", ".csh", ".exe", ".fxp", ".gadget", 
      ".hlp", ".hta", ".inf", ".ins", ".isp", ".its", ".js", ".jse", ".ksh", ".lnk", 
      ".mad", ".maf", ".mag", ".mam", ".maq", ".mar", ".mas", ".mat", ".mau", ".mav", ".maw", 
      ".mda", ".mdb", ".mde", ".mdt", ".mdw", ".mdz", ".msc", ".msi", ".msp", ".mst", ".ops", 
      ".pcd", ".pif", ".pfr", ".prg", ".pst", ".reg", ".scf", ".scr", ".sct", ".shb", ".shs", 
      ".tmp", ".url", ".vb", ".vbe", ".vbs", ".vsmacros", ".vss", ".vst", ".vsw", 
      ".ws", ".wsc", ".wsf", ".wsh" }; 

     // Set the value in the registry to the list of all Level 1 extensions so we can extract them 
     subKey.SetValue("Level1Remove", string.Join(";", level1Extensions)); 

     // Close (and save) the values 
     subKey.Close(); 
     regKey.Close(); 
    } 
関連する問題