2010-02-18 178 views
2

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

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

有没有一个标准的,最佳实践的方式来做到这一点?

我创建了一个几乎可以工作的LotusScript代理。但是,有一个错误 - 一旦备忘录正文超过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获得额外的回车。

回答

2

我不确定是什么导致了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 
+0

谢谢你。顺便说一下,你有没有遇到过一个在线示例脚本来保存电子邮件到文本文件?我发现的所有示例都涉及将附件保存到文件,而不是电子邮件的正文。 – mbeckish 2010-02-18 20:19:16

+0

我没有,但我只是做了一个快速搜索,发现了几个例子。一个看起来像使用Notes的DXL功能:http://tech.niques.info/projects/lotus-notes-email-export/另一个是用Perl编写的,但可能有一些逻辑可以提取http:// www.perlmonks.org/?node_id=136382 – 2010-02-19 14:34:06

3

至于32kB的事情,而不是这样的:

Set bodyRichText = doc.GetFirstItem("Body") 

...你可能要考虑的电子邮件文档中遍历所有“身体”领域。处理大量富文本时,Domino“块”将内容说成多个富文本字段。检查一下您正在处理的文档:查看文档属性时,您可能会看到“正文”字段的多个实例。

+0

谢谢本 - 我会检查出来的。 – mbeckish 2010-02-19 19:12:07

1

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

相关问题