如何解决由于交换同步问题,MailItem 被解密后是否可以更改?
我在 VSTO 插件中有代码来解密 Outlook 16 客户端中的电子邮件。电子邮件帐户位于 MS Excahnge。完整代码如下,但我希望这段代码不会让人感到意外。我没有创建电子邮件的副本。我注意到有时当我解密电子邮件时,它会自动再次加密。在其他时候,电子邮件的正文会在我解密的电子邮件中消失。
我相信这是因为 Exchange 的同步问题,但我不确定,我也不明白同步问题是什么。我认为其中许多电子邮件的副本最终会出现在 Sync Issues 文件夹中。
电子邮件是否未从服务器完全下载?或者 Outlook 是否再次“重新同步”旧电子邮件,错误地看到电子邮件中的差异(因为客户端通过解密更改了电子邮件)并因此再次下载电子邮件?
我的问题是我该如何解决这个问题?我需要等待什么或如何确保我在本地对电子邮件所做的更改正确同步到服务器?
下面是我的代码。我基本上利用 MailItem.PropertyAccessor 和 PR_Security_FLAGS 将值设置为 0。因此,我调用下面的函数 SetExtendedPropertyDecryptValue,传入一个 MmailItem 对象和 PR_Security_FLAGS 值。然后将该属性设置为 SECFLAG_NONE。
Const PR_Security_FLAGS As String = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"
Const SECFLAG_NONE = &H0
Const SECFLAG_ENCRYPTED = &H1
Const SECFLAG_SIGNED = &H2
Const SECFLAG_ENCRYPTED_SIGNED = &H3
Const SECFLAG_BITWISE = &H3
Private Function SetExtendedPropertyDecryptValue(ByVal aMailItem As Outlook.MailItem,ByVal aProperty As String) As Boolean
Dim uFlag As Long
GetExtendedPropertyValue(aMailItem,aProperty,uFlag)
If (uFlag And SECFLAG_BITWISE) = SECFLAG_NONE Then
Return True
Else
Return SetExtendedPropertyValue(aMailItem,PR_Security_FLAGS,uFlag And SECFLAG_NONE)
End If
End Function
Private Function GetExtendedPropertyValue(ByVal aMailItem As Outlook.MailItem,ByVal aProperty As String,ByRef res As Object) As Boolean
Dim oPropAcc As Outlook.PropertyAccessor = nothing
Try
oPropAcc = DirectCast(aMailItem.PropertyAccessor,Outlook.PropertyAccessor)
res = oPropAcc.GetProperty(aProperty)
Return True
Catch ex As System.Exception
'logging goes here
Finally
If Not oPropAcc Is nothing Then
Runtime.InteropServices.Marshal.ReleaseComObject(oPropAcc)
oPropAcc = nothing
End If
End Try
Return False
End Function
Private Function SetExtendedPropertyValue(ByVal aMailItem As Outlook.MailItem,ByVal value As Integer) As Boolean
Dim oPropAcc As Outlook.PropertyAccessor = nothing
Try
oPropAcc = DirectCast(aMailItem.PropertyAccessor,Outlook.PropertyAccessor)
oPropAcc.SetProperty(aProperty,value)
Return True
Catch ex As System.Exception
'logging goes here
Finally
If Not oPropAcc Is nothing Then
Runtime.InteropServices.Marshal.ReleaseComObject(oPropAcc)
oPropAcc = nothing
End If
End Try
Return False
End Function
解决方法
当您添加或删除任何其他标志时,尽量保留现有的安全标志。因此,如果您想对其进行解密,则无需删除 SECFLAG_SIGNED 标志。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。