Lotusscript 将 base64 编码的字符串保存到文件(DLL)

Lotusscript save base64 encoded string to file (DLL)

[编辑] 我相信我遗漏了我原来的问题。对我来说,问题似乎在于将解码后的 MIMEEntity 的内容传递给流,我想将其写到文件中。无论我如何尝试,我都无法让 Lotus 脚本将二进制数据写入文件。如果有人有任何帮助opinion/suggestion/etc..,我将不胜感激!

[原创] 我有以下代码

Dim a As String
a = "TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" & _
"AAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1v" & _
...
...

Dim session As New NotesSession
Dim stream As NotesStream
Dim doc As NotesDocument
Dim body As NotesMimeEntity
Dim db As NotesDatabase
Set session = New NotesSession

 'Create stream and display properties
Set stream = session.CreateStream

 'check if the file exists
If Not stream.Open("C:\Notes\update.dll") Then
     'if the file doesnot exist then create one and add a time stamp to it
    Dim fileNum As Integer
    fileNum% = Freefile()
    Open "/ww414/notes/ebcdicfile.txt" For Output As fileNum%
    Close fileNum%
     'this should have created the file. see if it existis now
    If Not stream.Open("C:\Notes\update.dll") Then
   'if the file has not been created yet then let the user know of the error that blocks the operation
        Messagebox("Log file Is inaccessible")
    End If
End If

Dim b As NotesStream
Set b = session.CreateStream

Call b.WriteText(a)
'==========================================================


'update file with the b64 decoded content
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
session.ConvertMime = False

Set body = doc.CreateMIMEEntity
Call body.SetContentFromText(b, "", ENC_BASE64)
Call body.DecodeContent
content = body.ContentAsText
Call stream.WriteText(content)

'close stream/file open in memory
Call stream.Close()

问题是,文件已创建,但当涉及到内容时,它只是在其中放入几个字节(而不是 14kb 的实际文件数据)

我检查了很多论坛和可能的解决方案,但其中 none 似乎有效。 例如: https://www.nsftools.com/tips/Base64v14.lss

http://www-10.lotus.com/ldd/nd6forum.nsf/e5f5333619f2996885256a220009508f/a8bb2c21c99f9c4d852571ee005cede9?OpenDocument

https://ghads.wordpress.com/2008/10/17/vbscript-readwrite-binary-encodedecode-base64/

所以,解决方案比我想象的更简单。

This 帮了大忙,因为我的问题的根本原因似乎是将二进制内容写入磁盘。那是因为创建文件的方式不对!创建文件时无法正确输出内容(对于某些 "Lotus reasons"..)

不管怎样,喝杯咖啡休息一下,一切从零开始,对我帮助很大!有效的代码(供将来参考,如果有人需要让这样的东西工作):

Sub Initialize

Dim a As String
a ="BASE64 ENCODED STRING(In my case it was a DLL)" 

Dim session As New NotesSession
Dim stream As NotesStream
Dim doc As NotesDocument
Dim body As NotesMimeEntity
Dim db As NotesDatabase
Set session = New NotesSession

Set stream = session.CreateStream

Dim b As NotesStream
Set b = session.CreateStream

Call b.WriteText(a, EOL_NONE)

Set db = session.CurrentDatabase
Set doc = db.CreateDocument
session.ConvertMime = False

Set mime = doc.CreateMIMEEntity
Call mime.SetContentFromText(b, "application/octet-stream", ENC_BASE64)
Call mime.DecodeContent

If Not(mime Is Nothing) Then
    Set stream = session.CreateStream
    pathname$ = "c:\temp\test.dll"
    If Not stream.Open(pathname$, "binary") Then
        Messagebox pathname$,, "Open failed"
        Goto ExitSub
    End If
    Call mime.GetContentAsBytes(stream)
    Call stream.Close
Else
    Messagebox "Not MIME",, doc.GetItemValue("Subject")(0)
End If  
ExitSub:
    session.ConvertMIME = True ' Restore conversion
End Sub