Outlook 2k7 集成(通过 P/Invoke)- 阻止不安全附件

发布于 2024-10-19 13:22:16 字数 1155 浏览 4 评论 0原文

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

在我们在 Windows 7 和 Outlook 2K7 上对其进行测试之前,它一直运行没有问题。在装有 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;
}

We're currently developing a plug-in for a piece of software in C#. This plug-in extracts the contents of a PST file and stores all items in it as text files (with the exception of attachments, which are stored as their type in the same folder as the email).

It has been working without issue until we tested it on Windows 7 w/ Outlook 2K7. After running the same previous job on a machine with Outlook 2000 on it, we noticed that there were over 12,000 files missing. These files turned out to be attachments (mostly URLs)

We found that the issue is that Outlook 2K7 blocks attachments with specific extensions. If you open the email in Outlook itself, you see a blue bar at the top stating "Outlook blocked access to the following potentially unsafe attachments" and all the attachments in the emails.

Is there a way to programmatically get these attachments without Outlook blocking them?

The code we use to save the attachments is:

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别念他 2024-10-26 13:22:16

只是将其放在这里以防其他人遇到同样的问题。 Outlook 2K7 具有 1 级文件类型功能,可阻止访问具有特定扩展名的附件。

但是,您可以更改注册表以允许访问这些文件。请记住为了安全起见将其设置回修改之前的状态。

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();
    }

Just putting this on here in case anybody else runs into the same issue. Outlook 2K7 has a Level1 file type feature that blocks access to attachments with specific extensions.

However, you can change the registry to allow access to these files. Just remember to set it back to the way it was prior to you modifying it for security's sake.

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();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文