简体   繁体   English

将元数据附加到Windows资源管理器“详细信息”视图中可见的Outlook msg文件?

[英]Attach metadata to outlook msg file that is visible in Windows Explorer Details view?

I have found ways to use C# to extract information from outlook *.msg files, such as sender, subject, recipients, etc. 我发现了使用C#从Outlook * .msg文件中提取信息的方法,例如发件人,主题,收件人等。

I would like to save this information as metadata (properties?) that can be viewed and sorted as columns in Windows Explorer details view. 我想将此信息另存为元数据(属性?),可以在Windows资源管理器详细信息视图中将其查看和排序为列。

1: Do msg files already have properties I can use for this purpose? 1:味精文件是否已经具有可以用于此目的的属性?

2: If so, is there an easy way to set these properties using C#? 2:如果是,是否有使用C#设置这些属性的简便方法?

3: If not, is there a way to register custom properties for msg files, and then set them programatically? 3:如果没有,是否可以注册msg文件的自定义属性,然后以编程方式设置它们?

If it comes to option 3, I found the following guide to creating shell extensions: http://www.codeproject.com/Articles/830/The-Complete-Idiot-s-Guide-to-Writing-Shell-Extens 如果涉及选项3,我发现了以下有关创建Shell扩展的指南: http : //www.codeproject.com/Articles/830/The-Complete-Idiot-s-Guide-to-Writing-Shell-Extens

But I haven't started reading it yet, because I'm not sure it's necessary, nor am I sure it would work as a solution. 但是我还没有开始阅读它,因为我不确定它是否必要,也不确定它是否可以作为解决方案。

Thanks! 谢谢!

[ETA some follow-up based on additional research] [ETA基于其他研究的一些后续行动]

Apparently starting with Windows Vista, all properties displayed in Windows Explorer Detail view must be stored within the file itself. 显然,从Windows Vista开始,Windows资源管理器“详细信息”视图中显示的所有属性都必须存储在文件本身中。

Reading and writing of these properties in Windows Explorer is facilitated through "Property Handlers." 通过“属性处理程序”可以在Windows资源管理器中读取和写入这些属性。

In Windows XP, an alternate option was available through "Column Handler" shell extensions, which allowed metadata to be stored outside of the file and viewed as columns in Windows Explorer. 在Windows XP中,可通过“列处理程序” shell扩展使用替代选项,该扩展允许将元数据存储在文件外部并在Windows资源管理器中视为列。 This option was removed beginning in Vista, supposedly because of concerns with losing metadata associated with files when they are transported or stored in a non-NTFS partition. 从Vista开始就删除了此选项,可能是由于担心在文件传输或存储在非NTFS分区中时丢失与文件关联的元数据。 The third party file manager Explorer2 still supports Windows-XP style column handlers in Windows Vista and 7, but it is not possible to view or edit this metadata in Windows Explorer. 第三方文件管理器Explorer2在Windows Vista和7中仍支持Windows-XP样式列处理程序,但无法在Windows Explorer中查看或编辑此元数据。

As far as I can tell, the Outlook *.msg file format does not have any properties associated with it by default in Windows 7. It may be possible to write a property handler for the file type, but doing so is beyond my skill set. 据我所知,在Windows 7中,默认情况下,Outlook * .msg文件格式没有与之关联的任何属性。可能可以为文件类型编写属性处理程序,但是这样做超出了我的技能范围。

i have the same probem, no solution yet but a product (outlook addin, no other stuff installed)messagesave has an advanced option to save data for them to be presented/understood by explorer: author, comments(recipient list), category(A if attachment exists). 我有相同的探针,但是没有解决方案,但是产品(outlook addin,未安装其他东西)messagesave具有高级选项,可以保存数据以供资源管理器显示/理解:作者,评论(收件人列表),类别(A)如果存在附件)。 i see a binary diff of the output of two .msg files (with and without the 'save data' option) and the diff is all over the place. 我看到两个.msg文件(带有和不带有'save data'选项)的输出的二进制差异,并且差异遍布整个地方。 so i am looking at the .msg format spec to see if there's anything I can do there. 因此,我正在查看.msg格式规范,以查看是否可以执行任何操作。 the .msg file can be viewed in explorer columns even w/o the messagesave installed, and on a flash fat32 drive. 即使未安装messageave,也可以在浏览器列中查看.msg文件,也可以在fat32驱动器上查看。 so i guess it's indeed stored in the mapi property but i don't know which ones which explorer looks at... 所以我想它确实存储在mapi属性中,但是我不知道哪个浏览器正在查看...

This is quite old, but I recently ran into the same issue. 这已经很老了,但是我最近遇到了同样的问题。 I am aware of MessageSave ( http://www.techhit.com/messagesave/ ), however, I already have all the msg files created, and I wanted to just add the Author property to them. 我知道MessageSave( http://www.techhit.com/messagesave/ ),但是,我已经创建了所有msg文件,我只想向其添加Author属性。

I finally figured out that the solution is to use DSOFile.dll. 我终于发现解决方案是使用DSOFile.dll。 Opening a msg with DSOFile, and then setting the SummaryProperties.Author property and then subsequently saving the file will set an attribute that Explorer can see and filter on. 使用DSOFile打开msg,然后设置SummaryProperties.Author属性,然后保存文件,将设置资源管理器可以查看和筛选的属性。

While it isn't C# code, here is VBA code that can be used withing Outlook to read a msg, get the Sender, and write it into the Author file property. 虽然不是C#代码,但是这里是可以与Outlook一起使用的VBA代码,以读取味精,获取发件人并将其写入Author文件属性。

You need to get a copy of dsofile.dll form microsoft (they only provide a 32bit version, so if you are using 64-bit Outlook, you'll need a 64-bit version which you can find in google) 您需要从Microsoft获得dsofile.dll的副本(它们仅提供32位版本,因此,如果您使用的是64位Outlook,则需要一个可以在Google中找到的64位版本)

  • then register the DLL with 'regsvr32 ' 然后向regsvr32注册DLL
  • then In VBA, add 'DSO OLE Document Properties Reader' to the References 然后在VBA中,将“ DSO OLE文档属性阅读器”添加到引用中

Finally, here is some code to update the MSG file: 最后,这是一些更新MSG文件的代码:

Function GetSenderSMTPAddress(mail As Outlook.MailItem) As String
    'Converted from VB to VBA from here: http://stackoverflow.com/questions/24361726/how-can-i-get-the-sender-email-address-using-outlook-mailitem-in-vb-net
    Dim PR_SMTP_ADDRESS As String: PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
    If mail Is Nothing Then
        Return
    End If
    If mail.SenderEmailType = "EX" Then
        Dim sender As Outlook.AddressEntry: Set sender = mail.sender
        If Not sender Is Nothing Then
            'Now we have an AddressEntry representing the Sender
            If sender.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry Or sender.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry Then
                'Use the ExchangeUser object PrimarySMTPAddress
                Dim exchUser As Outlook.ExchangeUser: Set exchUser = sender.GetExchangeUser()
                If Not exchUser Is Nothing Then
                    GetSenderSMTPAddress = exchUser.PrimarySmtpAddress
                    Exit Function
                Else
                    GetSenderSMTPAddress = ""
                    Exit Function
                End If
            Else
                GetSenderSMTPAddress = sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)
                Exit Function
            End If
        Else
            GetSenderSMTPAddress = ""
            Exit Function
        End If
    Else
        GetSenderSMTPAddress = mail.SenderEmailAddress
        Exit Function
    End If
End Function

Sub UpdateMsgAttributes(msgFile As String)

    Dim objDSO As Object
    Dim objVariant As Variant
    Dim oNamespace As NameSpace
    Dim strAuthor As String
    Dim item As Outlook.MailItem

    ' Open the msg in Outlook to get the attributes from the MailItem
    '     Use CreateItemFromTemplate instead of OpenSharedItem
    '     because OpenSharedItem puts a lock on the file, and the lock is only
    '     released at an indeterminate time after releasing the mailitem
    ' Set oNamespace = Application.GetNamespace("MAPI")
    ' Set objVariant = oNamespace.OpenSharedItem(msgFile)
    Set objVariant = Application.CreateItemFromTemplate(msgFile)

    If objVariant.Class = olMail Then
        Set item = objVariant
        strAuthor = item.SenderName & " <" & GetSenderSMTPAddress(item) & ">"
    End If
    objVariant.Close olDiscard
    Set objVariant = Nothing

    ' Reopen the msg with DSOFile to edit its attributes
    Set objDSO = CreateObject("DSOFile.OleDocumentProperties")
    objDSO.Open msgFile
    objDSO.SummaryProperties.author = strAuthor
    objDSO.Save

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM