vb.net - 由于交换同步问题,MailItem 可以在解密后更改吗?
问题描述
我在 VSTO 插件中有代码来解密 Outlook 16 客户端中的电子邮件。电子邮件帐户是 MS Excahnge。完整的代码如下,但我希望这段代码没有意外。我没有创建电子邮件的副本。我注意到有时当我解密一封电子邮件时,它会自动再次加密。在其他时候,电子邮件的正文会在我解密的电子邮件中消失。
我相信这是因为交换的同步问题,但我不确定,我也不明白同步问题到底是什么。我认为其中许多电子邮件的副本最终都位于“同步问题”文件夹中。
电子邮件是否未从服务器完全下载?或者 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 aProperty As String, 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 标志。
推荐阅读
- tensorflow - 重新训练 object_detection 未训练
- cakephp - Cakephp 3.7.4 Auth哈希密码不起作用
- java - 供应商接口中的 get() 在哪里实现?
- c++ - 在 Windows 10 上合成语音:缺少 Scenario_SynthesizeText.xaml.h
- javascript - 如何使用正则表达式匹配和替换所有不是数字或破折号的字符作为第一个字符?
- javascript - VS Code:将逗号分隔的变量声明重构为每行一个变量
- perl - 添加@INC 的路径,但不在 Perl 脚本中
- windows - 在 Windows 上使用 anaconda 安装 gTTS 包
- java - TestFX 中是否有测试选择框选择的功能?
- javascript - 如何将 javascript 注入 HTMLhelper 文本字段