【问题标题】:Outlook 2k7 Integration (via P/Invoke) - Blocking unsafe attachmentsOutlook 2k7 集成(通过 P/Invoke) - 阻止不安全的附件
【发布时间】:2011-03-01 20:08:43
【问题描述】:

我们目前正在为 C# 软件开发一个插件。此插件提取 PST 文件的内容并将其中的所有项目存储为文本文件(附件除外,附件以其类型存储在与电子邮件相同的文件夹中)。

在我们在带有 Outlook 2K7 的 Windows 7 上对其进行测试之前,它一直可以正常工作。在装有 Outlook 2000 的机器上运行相同的先前作业后,我们注意到有超过 12,000 个文件丢失。这些文件原来是附件(主要是 URL)

我们发现问题在于 Outlook 2K7 会阻止具有特定扩展名的附件。如果您在 Outlook 本身中打开电子邮件,您会在顶部看到一个蓝条,说明“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;
}

【问题讨论】:

    标签: c# outlook pinvoke outlook-2007


    【解决方案1】:

    只要把它放在这里,以防其他人遇到同样的问题。 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();
        }
    

    【讨论】:

      猜你喜欢
      • 2017-12-01
      • 2016-10-02
      • 1970-01-01
      • 2010-10-17
      • 1970-01-01
      • 1970-01-01
      • 2017-12-13
      • 2013-11-15
      • 1970-01-01
      相关资源
      最近更新 更多