代码之家  ›  专栏  ›  技术社区  ›  mbeckish

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

  •  2
  • mbeckish  · 技术社区  · 16 年前

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

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

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

    我已经创建了一个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。

    3 回复  |  直到 16 年前
        1
  •  3
  •   Ben    16 年前

    关于32Kb的东西,而不是这个:

    Set bodyRichText = doc.GetFirstItem( "Body" )
    

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

        2
  •  2
  •   Ken Pespisa    16 年前

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

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

    最后,我总是建议使用Midas的LSX来处理Lotus Notes中的富文本。他们销售的附加组件可以让您对富文本字段有更多的控制权。

    至于最佳实践,我在阅读您的代码时想到的是循环构造。在视图中获取第一个文档,对其进行处理,然后获取下一个文档并检查它是否等于零,这样效率更高。它将循环设置为按索引顺序遍历视图,并消除了每次搜索索引以查找第n个文档的需要。它还使您不必维护计数器。要点如下:

    Set doc = curview.GetFirstDocument()
    While Not (doc Is Nothing)
    
        'Do processing here...
    
        Set doc = curview.GetNextDocument(doc)
    Wend
    
        3
  •  1
  •   stwissel    16 年前

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