Skip to main content
 
developerWorks
AIX and UNIX
Information Mgmt
Lotus
New to Lotus
Products
How to buy
Downloads
Live demos
Technical library
Training
Support
Forums & community
Events
Rational
Tivoli
WebSphere
Java™ technology
Linux
Open source
SOA and Web services
Web development
XML
My developerWorks
About dW
Submit content
Feedback



developerWorks  >  Lotus  >  Forums & community  >  IBM Lotus Notes/Domino 8.5 Forum (includes Lotus Notes Traveler)

IBM Lotus Notes/Domino 8.5 Forum (includes Lotus Notes Traveler)

Sign in to participate Previous Next
Subject: Convert richtext into MIME
Feedback Type: Question
Product Area: iNotes - Full mode
Technical Area: Application Development
Platform: Linux server
Release: 8.5.2
Reproducible: Not applicable

Hallo,

Customising this agent :

http://cdn.ttgtmedia.com/searchDomino/downloads/Exportemail.txt

I made it works on iNotes in this way (still beta version not clean code),
=========================================
%REM
Agent esportaemlweb
Created Aug 11, 2011 by Marco Tiraferri/RICCIONE
Description: Comments For Agent
%END REM



Option Public
'Option Declare
Option Declare
%%include "LSCONST.LSS"

'Export Email:



Dim CONVERT_DB_SERVER As String
Dim CONVERT_DB_NAME As String
Dim CONVERT_FORM As String
Dim CONVERT_FIELD As String
Dim CONVERT_TOFIELD As String
Dim OUTFILENAME As String
Dim crlf As String
Dim SaveTempDoc As Integer
Dim fileNum As Integer
Dim msgid As Variant 'mt

Dim doc As NotesDocument
Dim nstream As NotesStream
Dim x As String
Dim count As Integer
Dim b As String

'** ShellExecute will open a file using the registered file association on the computer.
'** If it returns a value of greater than 32 then the call was successful; otherwise
'** it should return one of the error codes below. The parameters are:
'** hwnd = an active window handle, or 0
'** operation = "edit", "explore", "find", "open", or "print"
'** fileName = a file or directory name
'** parameters = if fileName is an executable file, the command line parameters
'** to pass when launching the application, or "" if no parameters
'** are necessary
'** directory = the default directory to use, or "" if you don't care
'** displayType = one of the displayType constants listed below
Declare Function ShellExecute Lib "shell32" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal operation As String, ByVal fileName As String, _
ByVal parameters As String, ByVal directory As String, ByVal displayType As Long) As Long

'** FindExecutable will determine the executable file that is set up to open a particular
'** file based on the file associations on this computer. If it returns a value of greater than
'** 32 then the call was successful; otherwise it should return one of the error codes
'** below. The parameters are:
'** fileName = the full path to the file you are trying to find the association for
'** directory = the default directory to use, or "" if you don't care
'** retAssociation = the associated executable will be returned as this parameter,
'** with a maximum string length of 255 characters (you will want
'** to pass a String that's 256 characters long and trim the
'** null-terminated result)
Declare Function FindExecutable Lib "shell32" Alias "FindExecutableA" _
(ByVal fileName As String, ByVal directory As String, ByVal retAssociation As String) As Long

'** constants for the displayType parameter
Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Const SW_NORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3
Const SW_MAXIMIZE = 3
Const SW_SHOWNOACTIVATE = 4
Const SW_SHOW = 5
Const SW_MINIMIZE = 6
Const SW_SHOWMINNOACTIVE = 7
Const SW_SHOWNA = 8
Const SW_RESTORE = 9
Const SW_SHOWDEFAULT = 10
Const SW_MAX = 10

'** possible errors returned by ShellExecute
Const ERROR_OUT_OF_MEMORY = 0 'The operating system is out of memory or resources.
Const ERROR_FILE_NOT_FOUND = 2 'The specified file was not found.
Const ERROR_PATH_NOT_FOUND = 3 'The specified path was not found.
Const ERROR_BAD_FORMAT = 11 'The .exe file is invalid (non-Microsoft Win32? .exe or error in .exe image).
Const SE_ERR_FNF = 2 'The specified file was not found.
Const SE_ERR_PNF = 3 'The specified path was not found.
Const SE_ERR_ACCESSDENIED = 5 'The operating system denied access to the specified file.
Const SE_ERR_OOM = 8 'There was not enough memory to complete the operation.
Const SE_ERR_SHARE = 26 'A sharing violation occurred.
Const SE_ERR_ASSOCINCOMPLETE = 27 'The file name association is incomplete or invalid.
Const SE_ERR_DDETIMEOUT = 28 'The DDE transaction could not be completed because the request timed out.
Const SE_ERR_DDEFAIL = 29 'The DDE transaction failed.
Const SE_ERR_DDEBUSY = 30 'The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed.
Const SE_ERR_NOASSOC = 31 'There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
Const SE_ERR_DLLNOTFOUND = 32 'The specified dynamic-link library (DLL) was not found.

Declare Function GetActiveWindow Lib "user32.dll" () As Long

' // BrowseInfo stucture
Type BROWSEINFO
hwndOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type


' // BrowseFlags constants
Const BIF_BROWSEFORCOMPUTER = 1000
Const BIF_BROWSEFORPRINTER = 2000
Const BIF_DONTGOBELOWDOMAIN = 2
Const BIF_RETURNFSANCESTORS = 8
Const BIF_RETURNONLYFSDIRS = 1
Const BIF_STATUSTEXT = 4

Const MAX_SIZE = 255

' // Win32 function to browse for a folder, rather than a file or files
Declare Function BrowseFolderDlg Lib "shell32.dll" Alias "SHBrowseForFolder" (lpBrowseInfo As BROWSEINFO) As Long

' // Win32 function that returns the path of the folder selected
Declare Function GetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDList" (ByVal PointerToIDList As Long, ByVal pszPath As String) As Long


Sub Initialize
On Error GoTo test_errore
Dim s As New NotesSession
Dim db As NotesDatabase
Dim oDocCtx As NotesDocument 'mt
Dim dc As NotesDocumentCollection
Dim body As NotesItem
Dim rtitem As NotesRichTextItem
Dim mimebits As Variant
Dim n As Integer


Dim unids As String 'mt
Dim unidArray As Variant 'mt
Dim msgid As Variant 'mt
Dim expdir$ , filename$, result& 'mt

crlf = Chr(13) & Chr(10)
'Dim mime As NotesMIMEEntity, mime2 As NotesMIMEEntity

'** this is a form that has a rich text field that is set to store contents
'** in MIME format
CONVERT_FORM = "MimeConvert"


'** this is the field on the form mentioned above that stores rich text
'** as MIME
CONVERT_TOFIELD="MimeRichTextField"
CONVERT_FIELD = "Body"


MsgBox "inizio 6 su forms85_x"

'** do you want to save the temporary doc after you're done with it
'** (True) or delete it (False)?
SaveTempDoc = False
'expdir$=BrowseForFolder() 'mt da commentare x win!!

Dim risposta As Integer

'risposta = Shell("mkdir /usr/local/notesdata/eml/pluto")



Dim mime As NotesMIMEEntity
Dim subj As String
Set nstream=s.CreateStream

Set oDocCtx = s.DocumentContext 'mt
unids = oDocCtx.GetItemValue("unid")(0) 'mt
MsgBox "elenco unid:" + unids 'mt
unidArray = Split(unids, ",") 'mt
Set db = oDocCtx.ParentDatabase 'mt
MsgBox "database attivo:" + db.Filename 'mt
Print "database attivo:" + db.Filename 'mt
Print "path: database attivo:" + db.Filepath
Print "database server attivo:" + db.Server
Dim nomeserver As NotesName
Set nomeserver = s.Createname(db.Server )
Dim nomedb As string
nomedb = Replace(db.filepath, "/", "\\")
'Set db = s.CurrentDatabase 'mt
Print db.Title 'mt
Dim cartella As string
cartella = getMailFileUser(nomeserver.Abbreviated,nomedb)

If UBound(unidarray) > 20 Then
Print "<alert>Al massimo selezionare 20 messaggi</alert>"
Exit Sub
End If

If cartella Like "ERRORE*" Then
Print "<alert>ERRORE!! percorso cartella errato! Contattare amministratore di sistema.("+ cartella +")</alert>"
Exit sub
End If
Print "sono dopo getmail files cartella: " + cartella
'risposta = Shell("mkdir -p /usr/local/notesdata/eml/" + cartella )
'Print "risposta dalla creazione cartella:" + CStr(risposta)
'expdir$="/usr/local/notesdata/eml/" + cartella + "/" 'mt
'cartella = "aaera"
expdir$=LCase("/mnt/emlarc/" + cartella + "_nt/Desktop/eml") 'mt
Print "path cartella:" + expdir$
risposta = Shell("mkdir -p " + expdir$ )
If risposta = 33 Then
Print "creata la cartella:" + expdir$ + " risultato:" + CStr(risposta)
Else
Print "<alert> errore creando la cartella:" + expdir$ + " risultato:" + CStr(risposta) + "</alert>"
End if
'expdir$=BrowseForFolder()

s.ConvertMime = False ' Do not convert MIME to rich text|
n=0
ForAll Z In unidArray 'mt
print "unid attivo =" + Z 'mt
Set doc = db.GetDocumentByUNID(Z) 'mt
Print "sono qui!!:" + doc.Httpurl 'mt
'Set dc = db.UnprocessedDocuments 'mt
'Set doc = dc.GetFirstDocument 'mt

'n=0 'mt
'While Not(doc Is Nothing) 'mt


Print "esportazione msg numero:" + CStr(n)
Dim pdate As String
Print "---a"
pdate = Format(doc.PostedDate(0), "yyyy-mm-dd_hh.nn")
Print "---b"
Dim elaborabile As Boolean
Dim subj_originale As String
subj_originale = doc.subject(0)

' Print "<alert> Nome Form: '" + doc.Form(0) + "'</alert>"
Select Case doc.Form(0)
Case "Memo", "Delivery Report" :
elaborabile = True
If doc.subject(0) ="" Then
subj="No subject"
Else
subj=validatefilename(doc.subject(0))
End If
' Call doc.ReplaceItemValue("Subject", "ARCHIVIATO: " + subj)
' Call doc.Save(true, true)

Case "NonDelivery Report" :
elaborabile = True
If doc.FailureReason(0) ="" Then
subj="No subject"
Else
subj=validatefilename(doc.FailureReason(0))
End If
Call doc.ReplaceItemValue("FailureReason", "ARCHIVIATO: " + subj)
Call doc.Save(True, True)
Case "Return Receipt":
elaborabile = False
Print "<alert>Documento di tipo: '" + doc.Form(0) + "' non archiviabile.</alert>"
Case Else:
elaborabile = false
Print "<alert>Documento di tipo: '" + doc.Form(0) + "' non gestito, segnala al ced</alert>"
End Select

If elaborabile Then

'OUTFILENAME=expdir$ & "\" & subj & " - " & doc.NoteID & ".eml" 'mt

Dim subj100 As String
subj100 = Left$(subj, 100)
OUTFILENAME=expdir$ & "/" & pdate & "_" & subj100 & " - " & doc.NoteID & ".eml" 'mt
Print "file da creare:" + OUTFILENAME
fileNum% = FreeFile
fileName$ = + OUTFILENAME
Print "filenum:" + CStr(fileNum%) + " nome file:" + filename$

If doc.HasItem( "Body" ) Then
n=n+1
Open filename$ For Output As fileNum%
Set body = doc.GetFirstItem("Body")
Print "body:" + body.text

Print "------------body type: " + CStr( body.type)
If body.Type = MIME_PART Then
Print " body di tipo MIME_PART ok!------------2"
Set mime = body.GetMimeEntity
mimebits=getmultipartmime(mime)
Print #fileNum%, mimebits
Else
Print " body di NON tipo MIME_PART merda!------------3"
' Call GetRichTextAsHtmlFile(doc, CONVERT_FIELD, OUTFILENAME, True)
End If
Print "------------4"
' Print " test questo dovrebbe modificare oggetto:" + subj
' If doc.Form(0) = "Memo" then
' Call doc.ReplaceItemValue("Subject", "ARCHIVIATO: " + subj)
' Call doc.Save(true, true)
' End if
Call doc.ReplaceItemValue("Subject", "ARCHIVIATO: " + subj)
Call doc.Save(True, True)
Print "oggetto dopo il cambio:" + doc.subject(0)
Close fileNum%


If doc.subject(0) = subj Then
Print "<alert>il messaggio: '" + subj + "' del " + pdate + " stato archiviato senza modificarne l'oggetto.</alert>"
End If
Else
Print "<alert> ERRORE!! il messaggio: '" + subj +"' non era valido per l'archiviazione </alert>"


End if
End If
'Kill filename$
' Set doc = dc.GetNextDocument(doc) 'mt
'Wend 'mt
End ForAll 'mt

'fileName$ = "c:\program files\horizon\horizondmsave.exe"
If isfile(fileName$) Then
' Print "dopo 1"
' result& = ShellExecute(0, "open", fileName$, "DIR=c:\export", "", SW_SHOW)
' Else
' Print "dopo 2"
print "<alert>" + CStr(n) & " messaggi sono stati esportati nella cartella eml </alert>"
Else
Print "<alert>" +" problemi in esportazione: verifica " + filename$ + "</alert>"
End If
Exit sub
test_errore:
Print "<alert>ERRORE!!" + Error & Chr(13) + " Modulo: " & CStr( GetThreadInfo(1) ) & ", Linea: " & CStr( Erl ) + "</alert>"
Error Err, Error & Chr(13) + " Module: " & CStr( GetThreadInfo(1) ) & ", Line: " & CStr( Erl )
End Sub

Function GetBoundary (header As String) As String
'** get the boundary from the initial header of a multi-part MIME string
'** normally, the format in Notes is something like:
'** Content-Type: multipart/related; boundary="=_related 0012868C85256E16_="
Dim boundary As String
boundary = StrRight(header, "boundary=""")

'** we want everything from the boundary=" to the closing "
If (InStr(boundary, """") > 0) Then
boundary = StrLeft(boundary, """")
End If

If (Len(boundary) > 0) Then
boundary = "--" & boundary
End If

GetBoundary = boundary
End Function
Function isFile(ByVal sFileName As String) As Integer
On Error Resume Next
Dim lFileLength As Long
Const ATTR_NORMAL = 0

isFile = False
If Dir$(sFileName, ATTR_NORMAL) <> "" Then
lFileLength = FileLen(sFileName)
If (lFileLength > 0) Then isFile = True
End If
End Function




Function remsub(substr As String)
Dim mystr As String
Dim a As Integer 'mt
Dim y As Integer 'mt
For a=1 To Len(substr)
y=Asc(Mid$(substr,a,1))
If Not ( y="13" Or y="10") Then
mystr=mystr+Mid$(substr,a,1)
End If
Next
remsub=mystr
End Function
Function GetMultipartMime (mime As NotesMIMEEntity) As String
'** recursively get all the parts of a multi-part MIME entity
Dim child As NotesMIMEEntity
Dim mText As String
Dim boundary As String


count=count+1


boundary = GetBoundary(mime.Headers)

'** DANGER -- ContentAsText truncates large MIME bodies in R5!!!
'** ND6 seems to be okay...
If mime.ContentType<>"text" Then
Call mime.encodecontent(1727)
mText = mText & mime.Headers & crlf & crlf
mText = mText & mime.ContentAsText & crlf
Else
mText = mText & mime.Headers & crlf & crlf
mText = mText & crlf & mime.ContentAsText & crlf
End If

Set child = mime.GetFirstChildEntity
While Not(child Is Nothing)
mText = mText & boundary & crlf
mText = mText & GetMultipartMime(child)
Set child = child.GetNextSibling
Wend

If (Len(boundary) > 0) Then
mText = mText & boundary & "--" & crlf & crlf
End If

GetMultipartMime = mText
End Function
Function BrowseForFolder() As String
print "-test------------------------------------"
Dim pathName1 As String,pathName As String, fileName As String
pathName$ = "/mnt/emlarc/*"
pathName1$ = "/mnt/emlarc/"
fileName$ = Dir$(pathName$, 16)
Dim conta
conta = 0
Do While fileName$ <> ""
conta = conta + 1

fileName$ = Dir$()
print CStr(conta) + " ->" + pathName1$ + fileName$ + " attr: " + CStr(GetFileAttr(pathName1$+filename$))

If conta > 15 Then
print "--test fine1-----------------------------------"
Exit Function
End If
Loop
print "--test fine-----------------------------------"
Exit Function



Dim mBrowseInfo As BROWSEINFO
Dim lngPointerToIDList As Long
Dim lngResult As Long
Dim strPathBuffer As String
Dim strReturnPath As String
Dim vbNullChar As String




MsgBox "-1"
vbNullChar = Chr(0)
MsgBox "-2"
On Error GoTo lblErrs
MsgBox "-3"

mBrowseInfo.hwndOwner = GetActiveWindow()
MsgBox "-4"
' // Set the default folder for the dialog box (0 = My Computer,
' // 5 = My Documents)
mBrowseInfo.pidlRoot = 0
MsgBox "1"
mBrowseInfo.lpszTitle = "Select the folder you wish to use:"
' // Pointer to a buffer that receives the display name
' // of the folder selected by the user
mBrowseInfo.pszDisplayName = String(MAX_SIZE, Chr(0))
' // Value specifying the types of folders to be listed
' // in the dialog box as well as other options
mBrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS

' // Returns a pointer to an item identifier list that
' // specifies the location of the selected folder relative
' // to the root of the name space
lngPointerToIDList = BrowseFolderDlg(mBrowseInfo)
MsgBox "2"
If lngPointerToIDList <> 0& Then
' // Create a buffer
strPathBuffer = String(MAX_SIZE, Chr(0))

' // Now get the selected path
lngResult = GetPathFromIDList(ByVal lngPointerToIDList, ByVal strPathBuffer)
' // And return just that
strReturnPath = Left$(strPathBuffer, InStr(strPathBuffer, vbNullChar) - 1)
End If
MsgBox "3"
BrowseForFolder = strReturnPath

lblEnd:
Exit Function

lblErrs:
MessageBox "<alert>ops!: " & Error$ & " (" & CStr(Err) & ").", 0, "Error, linea " &CStr(Erl) + "</alert>"
Resume lblEnd
End Function
Function GetRichTextAsHtmlString (doc As NotesDocument, _
fieldName As String, isMultiPart As Integer) As String
'** get the contents of the given field as HTML by copying them
'** to a MIME rich text field and reading the MIME field
On Error GoTo ErrorThrower

Dim session As New NotesSession
Dim mText As String
Dim db As NotesDatabase
Dim newDoc As NotesDocument
Dim noteID As String
Dim currentSessionMimeSetting As Integer

Dim rtitem As NotesRichTextItem
Dim rtitem2 As NotesRichTextItem
Dim mimeItem As NotesItem
Dim mime As NotesMIMEEntity
Dim MimeFieldName As String
Print "------------a1"
'** make sure we can actually get the rich text field we want to
'** copy, and make sure it's really rich text (error 13 if it's not)
On Error 13 Resume Next
Set rtitem = doc.GetFirstItem(fieldName)
If (rtitem Is Nothing) Then
Exit Function
End If

'** save the current ConvertMime setting, because we'll change it
'** a couple of times
currentSessionMimeSetting = session.ConvertMime

'** initially set the ConvertMime property to True and create a
'** temporary document, which allows us to treat the MIME field
'** as rich text so we can append some real rich text to it
session.ConvertMime = True

'** create a new document to manipulate the MIME entry with.
Set db =session.CurrentDatabase
'Set db = session.GetDatabase(CONVERT_DB_SERVER, CONVERT_DB_NAME)
Set newDoc = New NotesDocument(db)
Print "------------a2"
'** this document must use a form that already exists in this
'** database, and the MIME field that we create must be the
'** same name as a field that's already on the form as a rich text
'** field that stores its data in MIME format
newDoc.Form = CONVERT_FORM
MimeFieldName = CONVERT_TOFIELD

Set rtitem2 = New NotesRichTextItem(newDoc, MimeFieldName)
Call rtitem2.AppendRTItem(rtitem)
Call newDoc.Save(True, True)
Print "------------a2b"
'** HERE'S THE TRICK: you have to open the temporary doc
'** as a uidoc, and then save and close it.
'** This will convert all the rich text in our MIME field back to
'** MIME format (which is why the field had to exist as a valid
'** MIME field on a valid form in the first place, so Notes will
'** know to convert it back)
noteID = RefreshDocFields(newDoc)
Print "------------a2c; noteID:" + noteID
'** after you've done this, you need to reset the reference for
'** the newDoc variable, so none of the in-memory information
'** about the document will remain
Set newDoc = Nothing

Print "------------a2d"
'** set ConvertMime to False, reopen the temporary doc,
'** and now we can get the rich text contents as HTML
session.ConvertMime = False
Print "------------a2e"
Set newDoc = db.GetDocumentByID(noteID)
Print "------------a2f"
Set mimeItem = newDoc.GetFirstItem(MimeFieldName)
msgbox "------------a2g"
If Not (mimeItem Is Nothing) Then
Print "------------a3"
If (mimeItem.Type = MIME_PART) Then
Set mime = mimeItem.GetMimeEntity
If Not (mime Is Nothing) Then
If (mime.ContentType = "multipart") Then
'** for multi-part MIME, which is anything with graphics,
'** you need to get the various parts one at a time.
'** If you write this to a file, it should be a .mht file so the
'** the browser knows what to do with it.
'** NOTE: there is a bug in R5 where you can't always
'** get the full contents of large sections of multi-part
'** MIME -- if you're dealing with large images, they will
'** often get cropped off at the bottom
isMultipart = True
mText = GetMultipartMime(mime)
Else
'** if we're not dealing with multi-part (thank goodness)
'** we can just grab the HTML contents and go
isMultipart = False
mText = mText & mime.ContentAsText
End If
End If
End If
End If

'** delete or save the temporary doc when we're done (depending on
'** the SaveTempDoc setting)
If SaveTempDoc Then
Set rtitem2 = New NotesRichTextItem(newDoc, "HTMLText")
Call rtitem2.AppendText(mText)
Call newDoc.Save(True, True)
Else
Call newDoc.Remove(True)
End If

'** set the ConvertMIME setting back to whatever it was
'** before we started all this, and exit out
session.ConvertMIME = currentSessionMimeSetting
GetRichTextAsHtmlString = mText
Print "------------a4"
Exit function
ErrorThrower:
Print "<alert>ERRORE!!" + Error & Chr(13) + "Module: " & CStr( GetThreadInfo(1) ) & ", Line: " & CStr( Erl ) + "</alert>"
Error Err, Error & Chr(13) + "Module: " & CStr( GetThreadInfo(1) ) & ", Line: " & CStr( Erl )

End Function
Function WriteHtmlStringToFile (htmlBody As String, _
fileName As String, setFileExtension As Integer, isMultiPart As Integer) As Integer
'** send a NotesStream containing HTML to the specified fileName
'** (if setFileExtension is True, the fileName will automatically have
'** either .htm or .mht appended as the file extension, depending
'** on whether isMultiPart is True (.mht) or False (.htm))
Dim htmlStart As String, htmlEnd As String
Dim msgid As Variant 'mt

'** set our variables, based on isMultiPart and setFileExtension
If Not isMultiPart Then
'** non-multi-part files need opening and closing HTML
htmlStart = "<html><body>"
htmlEnd = "</body></html>"
End If

'fileName = fileName & ".eml"

'** open the file for output
'fileNum = Freefile()
'Open fileName For Output As fileNum
Print #fileNum%,"From: " & getlist("From")
Print #fileNum%,"To: " & getlist("SendTo")
Print #fileNum%,"Cc: " & getlist("CopyTo")
Print #fileNum%, "Bcc: " & getlist("BlindCopyTo")
Print #fileNum%,"Subject: " & doc.subject(0)
Print #fileNum%, "Date: " & Format(doc.posteddate(0), "dd mmm yyyy hh:mm:ss")
msgid=doc.GetItemValue("$MessageID")
Print #fileNum, "Message-ID: " & msgid(0)
If Not ismultipart Then Print #fileNum%, "MIME-Version: 1.0"
If Not ismultipart Then Print #fileNum%,"Content-Type: multipart/alternative;"
If Not ismultipart Then Print #fileNum%, Chr(09) & |boundary="| & CStr(doc.NoteID) & |"|
Print #1, "X-Priority: " & doc.importance(0)
ForAll i In doc.Items
If i.text<>"" Then
If i.name<>"Body" Then
Print #1, "X-Notes-Item: " & i.text & "; name=" & i.name
End If
End If
End ForAll
If Not ismultipart Then Print #fileNum%, crlf & "--" & CStr(doc.NoteID)
If Not ismultipart Then Print #fileNum%,"Content-Type: text/html;"
If Not ismultipart Then Print #fileNum%, Chr(09) & |charset="iso-8859-1"|
If Not ismultipart Then Print #fileNum%, "Content-Transfer-Encoding: quoted-printable" & crlf
If Not ismultipart Then Print #fileNum%, htmlStart
Print #fileNum%, htmlBody
If Not ismultipart Then Print #fileNum%, htmlEnd & crlf
If Not ismultipart Then Print #fileNum%, crlf & "--" & CStr(doc.NoteID) & "--"

'Close #fileNum
WriteHtmlStringToFile = True
Exit Function

processError:
Print "<alert>Error " & Err & ": " & Error$ + "</alert>"
Reset
WriteHtmlStringToFile = False
Exit Function

End Function
Function getMailFileUser(mailserver As String, mailfile As String) As String
On Error GoTo errorthrower
Dim session As New NotesSession

Dim dd As NotesDatabase
Dim utenti As NotesDatabase

Print "server:" + mailserver + " file:" + mailfile
Set utenti = New NotesDatabase("PostaLAN/RICCIONE","riccione\Utenti.nsf")
ForAll candidate_dd In session.AddressBooks
If candidate_dd.Server<>"" And candidate_dd.IsPublicAddressBook Then
Set dd = candidate_dd
Exit ForAll
End If
End ForAll
If dd Is Nothing Then Error 1978,"Failed to find Domino Directory"
If Not dd.IsOpen Then Call dd.Open("","")


Dim userdocs As NotesDocumentCollection
Dim formula As String
formula = {form="Person" & }& _
{@name([CANONICALIZE];MailServer)=@name([CANONICALIZE];"} & mailserver & {") & } &_
{MailFile="} & mailfile & {"}

'formula = {form="Person" & }& _
'{@name([CANONICALIZE];MailServer)=@name([CANONICALIZE];"} & mailserver & {") & } &_
'{MailFile="} & mailfile & {"}

'formula = |MailFile="mail\\pcorso0"|

print "formula su names:" + formula
Set userdocs = dd.Search(formula ,Nothing,0)

If userdocs.Count = 0 Then
formula = {form="Person" & }& _
{MailFile="} & mailfile & {"}

Print "formula su names secondo tentativo:" + formula
Set userdocs = dd.Search(formula ,Nothing,0)
End If

If userdocs.Count = 0 Then
getMailFileUser="ERRORE CARTELLA 1!"
Exit Function
End If

Dim userdoc As NotesDocument
Set userdoc = userdocs.GetFirstDocument
Dim fname As String
Dim nome As String
Dim cognome As String
nome = userdoc.FirstName(0)
cognome = userdoc.LastName(0)
'fname =
' --------------------------

ForAll x In userdoc.FullName
If InStr(x," ") = 0 Then
If Len(fname) = 0 Then
fname = { UtenteNt = "} + x + {" | UtenteNt = "} + UCase(x) +{"}

Else
fname = fname + { | UtenteNt = "} + x + {" | UtenteNt = "} + UCase(x) +{"}
End If

End If

End ForAll
'MsgBox "risultato" + fname

If fname <> "" Then
fname = fname + { | UtenteNt = "} + LCase(userdoc.ShortName(0)) + {" | UtenteNt = "} + UCase(userdoc.ShortName(0)) +{"}
Else
fname = { UtenteNt = "} + LCase(userdoc.ShortName(0)) + {" | UtenteNt = "} + UCase(userdoc.ShortName(0)) +{"}
End If



formula = {CivCognome = "} & UCase(cognome) & {" & }& _
{CivNome = "} & UCase(nome) & {" & } & _
{( } & (fname) & {)}

' -----------------------
'formula = {CivCognome = "TIRAFERRI" & UtenteNt = "CEDTM" | "cedtm" | "zuppa" }
'formula = {CivCognome = "Corso0" & CivNome = "Posta" & ( UtenteNt = "pcorso0" | UtenteNt = "PCORSO0" | UtenteNt = "cocomero" | UtenteNt = "COCOMERO" | UtenteNt = "melone" | UtenteNt = "MELONE" | UtenteNt = "PCorso0" | UtenteNt = "PCORSO0")}

Print "nuova formula:" + formula

If Not utenti.IsOpen Then Call utenti.Open("","")
Set userdocs = utenti.Search(formula ,Nothing,0)
Set userdoc = userdocs.GetFirstDocument
If Not userdoc Is Nothing Then
Dim varutentent, vararchivioeml As String
varutentent = userdoc.UtenteNt(0)
vararchivioeml =userdoc.ArchivioEml(0)

If varutentent = vararchivioeml Or vararchivioeml = "" then
getMailFileUser = varutentent
Else
getMailFileUser = vararchivioeml
End if
Else
getMailFileUser="ERRORE CARTELLA 2"
End If


Exit Function
ErrorThrower:
Print "<alert>ERRORE!!" + Error & Chr(13) + "Module: " & CStr( GetThreadInfo(1) ) & ", Line: " & CStr( Erl ) + "</alert>"
Error Err, Error & Chr(13) + "Module: " & CStr( GetThreadInfo(1) ) & ", Line: " & CStr( Erl )
End Function

Function getlist(Field As String)
Dim values As Variant
Dim out As String
Dim session As New NotesSession
Dim nam As NotesName
Dim c As Integer 'mt
values = doc.GetItemValue( Field )
ForAll v In values
c=c+1
Set nam=session.CreateName(v)
If c>1 Then
out = out +"; "+ nam.abbreviated
Else
out=nam.abbreviated
End If

End ForAll
getlist=out
End Function
Function RefreshDocFields (doc As NotesDocument) As String
'** Refresh the fields on a document, and return the NoteID of
'** the refreshed doc (I don't think this would cause the NoteID
'** to change, but just in case)
On Error Resume Next

'** before we save the uidoc, disable any MIME conversion warnings
'** by setting the MIMEConvertWarning parameter in Notes.ini to 1
Dim session As New NotesSession
Dim oldWarningVal As String
oldWarningVal = session.GetEnvironmentString("MIMEConvertWarning", True)
Call session.SetEnvironmentVar("MIMEConvertWarning", "1", True)

Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = workspace.EditDocument(True, doc)
Call uidoc.Save
RefreshDocFields = uidoc.Document.NoteID
Call uidoc.Close(True)

%REM
'** if you're not running this on a Notes client, you could
'** try to run this in the background by doing everything
'** using the Notes COM objects, although this is totally
'** unsupported and probably riddled with memory leaks
'** if you could actually get it working (plus, it would only
'** work on a Windows server...)
Dim oleSession As Variant
Dim oleDb As Variant
Dim oleDoc As Variant
Dim oleWorkspace As Variant
Dim oleUidoc As Variant

'** first we have to get a handle to the doc as an OLE object
Set oleSession = CreateObject("Notes.NotesSession")
Call oleSession.Initialize
Set oleDb = oleSession.GetDatabase("", doc.ParentDatabase.FilePath)
Set oleDoc = oleDb.GetDocumentByID(doc.NoteID)

'** if we were able to do that, we can open and save it as a UIDoc
'** using COM
If Not (oleDoc Is Nothing) Then
Set oleWorkspace = CreateObject("Notes.NotesUIWorkspace")
Set oleUidoc = oleWorkspace.EditDocument(True, oleDoc)
Call oleUidoc.Save
RefreshDocFields = oleUidoc.Document.NoteID
Call oleUidoc.Close(True)
End If
%END REM

'** reset the MIMEConvertWarning Notes.ini variable and return
Call session.SetEnvironmentVar("MIMEConvertWarning", oldWarningVal, True)

End Function
Function GetRichTextAsHtmlFile (doc As NotesDocument, fieldName As String, fileName As String, setFileExtension As Integer) As Integer
'** convert a rich text field to HTML, and send it to the specified file
'** (if setFileExtension is True, the fileName will automatically have
'** either .htm or .mht appended as the file extension, depending
'** on whether the HTML representation is multi-part or not)
On Error GoTo ErrorThrower
Dim isMultiPart As Integer
Dim htmlBody As String
Print "------------x0"
htmlBody = GetRichTextAsHtmlString(doc, fieldName, isMultiPart)
Print "------------x1"
GetRichTextAsHtmlFile = WriteHtmlStringToFile(htmlBody, fileName, True, isMultiPart)
Print "------------x2"
Exit function
ErrorThrower:
Print "<alert>ERRORE!!" + Error & Chr(13) + "Module: " & CStr( GetThreadInfo(1) ) & ", Line: " & CStr( Erl ) + "</alert>"
Error Err, Error & Chr(13) + "Module: " & CStr( GetThreadInfo(1) ) & ", Line: " & CStr( Erl )

End Function
Function isFolder(ByVal sFolderPath As String) As Integer
Const ATTR_DIRECTORY = 16
isFolder = False
If Dir$(sFolderPath, ATTR_DIRECTORY) <> "" Then isFolder = True
End Function
Function old_getMailFileUser(mailserver As String, mailfile As String) As String
On Error GoTo errorthrower
Dim session As New NotesSession

Dim dd As NotesDatabase
ForAll candidate_dd In session.AddressBooks
If candidate_dd.Server<>"" And candidate_dd.IsPublicAddressBook Then
Set dd = candidate_dd
Exit ForAll
End If
End ForAll
If dd Is Nothing Then Error 1978,"Failed to find Domino Directory"
If Not dd.IsOpen Then Call dd.Open("","")


Dim userdocs As NotesDocumentCollection
Dim formula As String
formula = {form="Person" & }& _
{@name([CANONICALIZE];MailServer)=@name([CANONICALIZE];"} & mailserver & {") & } &_
{MailFile="} & mailfile & {"}

'formula = {form="Person" & }& _
'{@name([CANONICALIZE];MailServer)=@name([CANONICALIZE];"} & mailserver & {") & } &_
'{MailFile="} & mailfile & {"}

'formula = |MailFile="mail\\pcorso0"|


MsgBox formula
Set userdocs = dd.Search(formula ,Nothing,0)

Dim userdoc As NotesDocument
Set userdoc = userdocs.GetFirstDocument
If Not userdoc Is Nothing Then

old_getMailFileUser = userdoc.ShortName(0)
Else
old_getMailFileUser=""
End If

Exit Function
ErrorThrower:
Print "<alert>" + Error & "Module: " & CStr( GetThreadInfo(1) ) & ", Line: " & CStr( Erl ) + "</alert>"
Error Err, Error & Chr(13) + "Module: " & CStr( GetThreadInfo(1) ) & ", Line: " & CStr( Erl )
End Function

Function validatefilename(filename As String)
Dim l As Integer
Dim x As Integer
Dim newname As String

l=Len(filename)

For x = 1 To l

If Mid$(filename,x,1) Like "[-@()~^$#[{}=A-Za-z0-9]" Then
newname=newname+Mid$(filename,x,1)
Else
If Mid$(filename,x,1)=" " Or Mid$(filename,x,1)="]" Or Mid$(filename,x,1)="," Or Mid$(filename,x,1)="'" Or Mid$(filename,x,1)="!" Then
newname=newname+Mid$(filename,x,1)
Else
Print "il carattere >" + Mid$(filename,x,1) "< in pos: " + CStr(x) + " della stringa >" + filename + "> non valido e viene sopprresso"
End If

End If
Next x
Print "validatefilename 1" + newname
validatefilename=newname
End Function

=========================================


It' work's fine for mail incoming from the internet and from other iNotes users, but for mail coming from Notes Clients the richtext field cannot be converted to MIME Format.

In the original version the function :

Function RefreshDocFields (doc As NotesDocument) As String
On Error Resume Next

Dim session As New NotesSession
Dim oldWarningVal As String
oldWarningVal = session.GetEnvironmentString("MIMEConvertWarning", True)
Call session.SetEnvironmentVar("MIMEConvertWarning", "1", True)

Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = workspace.EditDocument(True, doc)
Call uidoc.Save
RefreshDocFields = uidoc.Document.NoteID
Call uidoc.Close(True)
Call session.SetEnvironmentVar("MIMEConvertWarning", oldWarningVal, True)

End Function

Use the NotesUIDocument to open and save the document to have the MIME conversion, but the UI* works only for notes clients... how can i make this conversion work for iNotes Webmail????

Thank's

Marco


Feedback number MTII8R4LCF created by Marco Tiraferri on 02/02/2012

Status: Open
Comments:

Convert richtext into MIME (Marco Tiraferri... 2.Feb.12)
. . LS richtext to mime (Fabrice Papirny... 13.Feb.13)




Printer-friendly

Search this forum


Sign In or Register

 Sign In or Register
Sign in
Forgot your password?
Forgot your user name?
Create new registration

Member Tools


RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS
More Lotus RSS feeds

Resources

 Resources
Forum use and etiquette
Native Notes Access
Web site Feedback

Lotus Support


 Lotus Support
IBM Support Portal - Lotus software
Lotus Support documents
Lotus support by product
Lotus support downloads
Lotus support RSS feeds

Wikis

 Wikis
IBM Composite Applications
IBM Mashup Center
IBM Connections
IBM Docs
IBM Forms
IBM Mobile Connect
IBM Sametime
IBM SmartCloud for Social Business
IBM Web Experience Factory
Lotus Domino
Lotus Domino Designer
Lotus Expeditor
Lotus Foundations
Lotus iNotes
Lotus Instructor Community Courseware
Lotus Notes
Lotus Notes & Domino Application Development
Lotus Notes Traveler
Lotus Protector
Lotus Quickr
Lotus Symphony
IBM Web Content Manager
WebSphere Portal

Lotus Forums


 Lotus Forums
Notes/Domino 9.0
Notes/Domino 8.5 + Traveler
Notes/Domino XPages development forum
Notes/Domino 8
Notes/Domino 6 and 7
Notes/Domino 4 and 5
IBM Connections
IBM Forms
IBM Mobile Connect
IBM Sametime
IBM SmartCloud Notes
IBM Web Content Manager
Lotus Domino Document Manager
Lotus Enterprise Integration
Lotus Expeditor
Lotus Protector
Lotus Quickr
Lotus SmartSuite
Lotus Symphony
Lotus Symphony Developer Toolkit Support
Lotus Workflow