lotus-notes - Lotusscript:检索电子邮件正文中的图像
问题描述
在我的代理中,我尝试检索当前电子邮件中的所有文件。我附加的代码工作正常,除了电子邮件正文中的图像。我设法检索到附加到电子邮件的所有文件和图像,除了复制并粘贴在电子邮件文本中间的图片。这是我的代码:
Dim session As New NotesSession
Dim doc As NotesDocument
Dim db As NotesDatabase
Dim item As Variant
Dim CurrentDocColl As NotesDocumentCollection
Set db = Session.Currentdatabase
Set CurrentDocColl = db.Unprocesseddocuments
Set doc = CurrentDocColl.Getfirstdocument
While Not doc Is Nothing
Set item = doc.GETFIRSTITEM("Body")
If doc.HasEmbedded Then
ForAll attachment In item.EmbeddedObjects
Call attachment.ExtractFile (pathname & "\" & attachment.Name)
End ForAll
End If
Set doc=CurrentDocColl.Getnextdocument(doc)
Wend
如何检索这些图像?
非常感谢您的帮助
解决方案
我有一个代理做了很多,但它并不短。您需要做的是通过 XML DomParser 运行文档,沿着 DOM 树向下走,当您找到名称中包含“JPEG”或“PNG”的节点(内联图像本身)时,将数据流式传输到文件并保存。该代码是我在网上找到的代理(我再也找不到了,否则我会给予信任)和我所做的工作的组合。您将无法复制/粘贴此示例代码并期望它能够工作,为简洁起见,我删除了一些内容(如声明变量和支持函数)。
Sub Initialize
Dim dxlExp As NotesDXLExporter
Set dxlExp = s.CreateDXLExporter
Call dxlExp.setInput(Doc)
Set DomParser=s.CreateDOMparser()
Call DomParser.Setinput(dxlExp)
Dim dxlImp As NotesDXLImporter
Set dxlImp = s.Createdxlimporter()
Call dxlImp.Setinput(domParser)
Call dxlImp.SetOutput(db)
On Event PostDomParse From DomParser Call DomInputProcessed
Call dxlExp.Process
End Sub
Sub DomInputProcessed(DomParser As NotesDomParser)
Dim DomNode As NotesDomNode
Set DomNode = DomParser.Document
Call walkTree(DomParser, DomNode)
Exit Sub
End Sub
Sub walkTree (DomParser As NotesDOMParser, node As NotesDOMNode)
Select Case node.NodeType
Case DOMNODETYPE_DOCUMENT_NODE: ' If it is a Document node
domParser.Output( "<?xml version='1.0' encoding='utf-8'?>"+LF )
Set child = node.FirstChild ' Get the first node
Dim numChildNodes As Integer
numChildNodes = node.NumberOfChildNodes
While numChildNodes > 0
Set child = child.NextSibling ' Get next node
numChildNodes = numChildNodes - 1
Call walkTree(DOMParser, child)
Wend
Case DOMNODETYPE_DOCUMENTTYPE_NODE: ' It is a <!DOCTYPE> tag
domParser.Output("<!DOCTYPE "+ node.NodeName+ ">" + LF)
Case DOMNODETYPE_TEXT_NODE: ' Plain text node
value = xmlReplace(node.NodeValue)
domParser.Output(value)
Case DOMNODETYPE_ELEMENT_NODE: ' Most nodes are Elements
Select Case node.NodeName
Case "jpeg"
Dim jpegfile As String
' Step 1, write the MIME file
Dim base64node As NotesDOMNode
Set base64Node = node.Firstchild
Dim base64Out As NotesStream
Set base64Out = s.createStream()
Dim bytesWritten As Long
bytesWritten = base64Out.Writetext(base64Node.NodeValue)
' Step 2, Read the MIME file and decode it.
Set db=s.currentdatabase
Set doc=db.createDocument()
Set m=doc.Createmimeentity("Image1")
Call m.setContentFromText(base64Out, "image/jpeg", 1727)
Call m.Decodecontent()
Dim JPEGOut As NotesStream
Set JPEGOut = s.createStream()
jpegFile = RandomFileName(baseDir, ".jpg")
JPEGOut.open(jpegFile)
Call m.Getcontentasbytes(JPEGOut, True)
Call JPEGOut.Close()
attachmentNamesStr = attachmentNamesStr + jpegFile + "~"
' Step 3, remove the jpeg and its child node
' We do this by just not sending anything to the DomParser output.
Case "png"
' Same as JPEG except it's PNG.
End Select
End Select 'node.NodeType
End If 'Not node.IsNull
End Sub
推荐阅读
- javascript - 如何从 Swift 监听 JavaScript 回调?
- c# - 为什么我的验证不起作用?asp.net mvc
- python - 为什么 ndarray 的相同元素在 numpy 中具有不同的 id?
- postman - Strapi 在条目创建期间上传文件
- messagekit - 如何创建和显示最简单的短信?
- excel - 基于其他列创建列
- javascript - 如何在猫鼬中使用基本模式到子模式
- perl - 在 Perl 中检查文件是否处于打开状态
- c# - DateTimeOffset.TryParse 不会在 .Net 5.0 中格式化俄罗斯 RFC 日期,但它可以在 .Net 3.1 中使用。为什么?
- scala - Scala:在单行中调用具有另一个纯函数作为参数(HOF)的纯函数