Lotus Notes - 将电子邮件导出到纯文本文件

发布于 2024-08-22 06:05:23 字数 2306 浏览 7 评论 0原文

我正在设置一个 Lotus Notes 帐户来接受来自客户端的电子邮件,并自动将每封电子邮件保存为纯文本文件以供另一个应用程序处理。

因此,我尝试在 Lotus 中创建我的第一个代理,以自动将电子邮件导出为文本。

有没有标准的、最佳实践的方法来做到这一点?

我已经创建了一个非常有效的 LotusScript Agent。但是,存在一个错误 - 一旦备忘录正文超过 32K 个字符,它就会开始插入额外的 CR/LF 对。

我正在使用 Lotus Notes 7.0.3。

这是我的脚本:

 Sub Initialize
 On Error Goto ErrorCleanup
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim doc As NotesDocument
 Dim uniqueID As Variant 
 Dim curView As NotesView
 Dim docCount As Integer
 Dim notesInputFolder As String 
 Dim notesValidOutputFolder As String
 Dim notesErrorOutputFolder As String 
 Dim outputFolder As String
 Dim fileNum As Integer
 Dim bodyRichText As NotesRichTextItem
 Dim bodyUnformattedText As String
 Dim subjectText As NotesItem

 '''''''''''''''''''''''''''''''''''''''''''''''''''''''
 'INPUT OUTPUT LOCATIONS 
 outputFolder = "\\PASCRIA\CignaDFS\CUser1\Home\mikebec\MyDocuments\"
 notesInputFolder = "IBEmails" 
 notesValidOutputFolder = "IBEmailsDone"
 notesErrorOutputFolder="IBEmailsError"
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''

 Set db = session.CurrentDatabase
 Set curview = db.GetView(notesInputFolder ) 
 docCount = curview.EntryCount
 Print "NUMBER OF DOCS "  & docCount
 fileNum = 1
 While (docCount > 0)
  'set current doc to 
  Set doc = curview.GetNthDocument(docCount)

  Set bodyRichText = doc.GetFirstItem( "Body" )
  bodyUnformattedText = bodyRichText.GetUnformattedText()
  Set subjectText = doc.GetFirstItem("Subject")
  If subjectText.Text = "LotusAgentTest" Then
   uniqueID = Evaluate("@Unique")
   Open "\\PASCRIA\CignaDFS\CUser1\Home\mikebec\MyDocuments\email_" & uniqueID(0) & ".txt" For Output As fileNum
   Print #fileNum, "Subject:" & subjectText.Text
   Print #fileNum, "Date:" & Now
   Print #fileNum, bodyUnformattedText
   Close fileNum
   fileNum = fileNum + 1
   Call doc.PutInFolder(notesValidOutputFolder)
   Call doc.RemoveFromFolder(notesInputFolder)
  End If
  doccount = doccount-1
 Wend
 Exit Sub
    ErrorCleanup: 
     Call sendErrorEmail(db,doc.GetItemValue("From")(0))
     Call doc.PutInFolder(notesErrorOutputFolder)
     Call doc.RemoveFromFolder(notesInputFolder)
    End Sub

更新 显然 32KB 问题并不一致 - 到目前为止,只有一份文档在 32K 之后开始获得额外的回车符。

I am setting up a Lotus Notes account to accept emails from a client, and automatically save each email as a plain text file to be processed by another application.

So, I'm trying to create my very first Agent in Lotus to automatically export the emails to text.

Is there a standard, best practices way to do this?

I've created a LotusScript Agent that pretty much works. However, there is a bug - once the Body of the memo exceeds 32K characters, it starts inserting extra CR/LF pairs.

I am using Lotus Notes 7.0.3.

Here is my script:

 Sub Initialize
 On Error Goto ErrorCleanup
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim doc As NotesDocument
 Dim uniqueID As Variant 
 Dim curView As NotesView
 Dim docCount As Integer
 Dim notesInputFolder As String 
 Dim notesValidOutputFolder As String
 Dim notesErrorOutputFolder As String 
 Dim outputFolder As String
 Dim fileNum As Integer
 Dim bodyRichText As NotesRichTextItem
 Dim bodyUnformattedText As String
 Dim subjectText As NotesItem

 '''''''''''''''''''''''''''''''''''''''''''''''''''''''
 'INPUT OUTPUT LOCATIONS 
 outputFolder = "\\PASCRIA\CignaDFS\CUser1\Home\mikebec\MyDocuments\"
 notesInputFolder = "IBEmails" 
 notesValidOutputFolder = "IBEmailsDone"
 notesErrorOutputFolder="IBEmailsError"
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''

 Set db = session.CurrentDatabase
 Set curview = db.GetView(notesInputFolder ) 
 docCount = curview.EntryCount
 Print "NUMBER OF DOCS "  & docCount
 fileNum = 1
 While (docCount > 0)
  'set current doc to 
  Set doc = curview.GetNthDocument(docCount)

  Set bodyRichText = doc.GetFirstItem( "Body" )
  bodyUnformattedText = bodyRichText.GetUnformattedText()
  Set subjectText = doc.GetFirstItem("Subject")
  If subjectText.Text = "LotusAgentTest" Then
   uniqueID = Evaluate("@Unique")
   Open "\\PASCRIA\CignaDFS\CUser1\Home\mikebec\MyDocuments\email_" & uniqueID(0) & ".txt" For Output As fileNum
   Print #fileNum, "Subject:" & subjectText.Text
   Print #fileNum, "Date:" & Now
   Print #fileNum, bodyUnformattedText
   Close fileNum
   fileNum = fileNum + 1
   Call doc.PutInFolder(notesValidOutputFolder)
   Call doc.RemoveFromFolder(notesInputFolder)
  End If
  doccount = doccount-1
 Wend
 Exit Sub
    ErrorCleanup: 
     Call sendErrorEmail(db,doc.GetItemValue("From")(0))
     Call doc.PutInFolder(notesErrorOutputFolder)
     Call doc.RemoveFromFolder(notesInputFolder)
    End Sub

Update
Apparently the 32KB issue isn't consistent - so far, it's just one document that starts getting extra carriage returns after 32K.

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

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

发布评论

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

评论(3

绝對不後悔。 2024-08-29 06:05:23

关于 32Kb 的事情,而不是这样:

Set bodyRichText = doc.GetFirstItem( "Body" )

...您可能需要考虑迭代电子邮件文档中的所有“正文”字段。在处理大量富文本时,Domino 将所述内容“分块”到多个富文本字段中。检查您正在处理的一些文档:当您查看文档属性时,您可能会看到“正文”字段的多个实例。

With regards the 32Kb thing, instead of this:

Set bodyRichText = doc.GetFirstItem( "Body" )

... you might want to consider iterating all "Body" fields in the email document. When dealing with large amounts of rich text, Domino "chunks" said content into multiple rich text fields. Check some documents you're processing: you may well see multiple instances of the "Body" field when you look at document properties.

生生漫 2024-08-29 06:05:23

我不确定是什么导致了 32K 错误,但我知道 Lotus Notes 中的 32K 或 64K 顺序有很多限制,所以也许您遇到了其中之一。我无法想象什么会增加额外的 CR/LF。也许您可以尝试在 NotesRichTextItem 类上使用 GetFormattedText 方法,看看它是否效果更好?

它更复杂,但您也可以使用 NotesRichTextNavigator 类来迭代备忘录中的所有段落,一次输出一个段落。以这种方式分解输出可能会消除 CR/LF 问题。

最后,我总是建议 Midas 的 LSX 来处理 Lotus Notes 中的富文本。他们销售一个附加组件,可以让您更好地控制富文本字段。

至于最佳实践,当我阅读您的代码时,我想到的一个是循环构造。更有效的方法是获取视图中的第一个文档,对其进行处理,然后获取下一个文档并检查它是否等于 Nothing。这会将循环设置为按索引顺序运行视图,并且无需每次都通过索引搜索来查找第 N 个文档。它还可以让您免去维护计数器的麻烦。要点如下:

Set doc = curview.GetFirstDocument()
While Not (doc Is Nothing)

    'Do processing here...

    Set doc = curview.GetNextDocument(doc)
Wend

I'm not sure what is causing the 32K bug, but I know there are lots of limitations in the order of 32K or 64K within Lotus Notes, so perhaps you're running into one of those. I can't imagine what would add extra CR/LFs. Perhaps you could try using the GetFormattedText method on the NotesRichTextItem class and see if it fares better?

It's more complicated, but you might also be able to use the NotesRichTextNavigator class to iterate through all the paragraphs in the memo, outputting them one at a time. Breaking up the output that way might eliminate the CR/LF problem.

Lastly I always suggest Midas' LSX for dealing with rich text in Lotus Notes. They sell an add-on that gives you much more control over rich text fields.

As for best practices, one that comes to mind when I read your code is the looping construct. It is more efficient to get the first document in a view, process it, and then get the next doc and check whether it is equal to Nothing. That sets the loop to run through the view in index order, and eliminates the need to search through the index to find the Nth document each time. It also saves you from maintaining a counter. The gist is as follows:

Set doc = curview.GetFirstDocument()
While Not (doc Is Nothing)

    'Do processing here...

    Set doc = curview.GetNextDocument(doc)
Wend
倦话 2024-08-29 06:05:23

外部电子邮件很可能以 MIME 形式出现。因此,您可以检查 document.hasMime,然后使用 mime 类来获取内容。那么你就没有 64k 的限制。示例位于帮助中 - 如果您需要代码,请回复。

The external eMail most likely comes in as MIME. So you could check the document.hasMime and then use the mime classes to get to the content. Then you don't have a 64k limit. Samples are in the help - or reply if you want code.

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