MIssing text with GetFormattedText

A Mail-In Database receives an e-mail, then a scheduled agent running on the server writes the contents of the Body field in a file on the hard disk. This is made using the GetFormattedText method.The problem is in the formatting of the file: all the blank spaces at the start of each line of the e-mails are missing in the files on hard disk.

I don’t use trim and the code worked fine on R5.

Subject: RE: MIssing text with GetFormattedText

There doesn’t seem to have been a change in GetFormattedText. The button below (which you can see if you read this forum with the Notes client) is fetching the spaces with no problem (it changes them to * for display purposes).

Possibly the spaces are getting stripped at some other point in your code.


a line

a line with a space at the start

spaces at start and end

the end

Subject: RE: MIssing text with GetFormattedText

OK, thank you, but I use a scheduled agent running on the server, and if I use a UiDoc work all fine, but I don’t use FrontEnd in Scheduled Agent.

The problem may be a bad conversion on server 6. (on Server 5 is OK ! )?

Subject: RE: MIssing text with GetFormattedText

The GetFormattedText method is implemented exactly the same on the Domino server and Notes client. It’s the same code. If there are spaces going missing, they are going missing at some other point. Have you looked at the emails you are getting to make sure the spaces are really there in the Notes database? Have you debugged your agent to see what values it’s really reading? Do you want to maybe post some code?

Subject: RE: MIssing text with GetFormattedText

This is the code (on Scheduled agent):

	...declaration........





	Set s = New NotesSession



	........



	If DocTme.TMEMime(0) = "1" Then 'DocTme is document Profile

		ConvertToMime = True

	Else

		ConvertToMime = False

	End If

	Call ConvertiBody(DocMail, ConvertToMime) 'I've Tried to REM this code , but it doesn't work.

	

		

	'Raccoglie il body della mail in arrivo

	Set BodyItem = doc.GetFirstItem( "Body" )

	TestoCompleto = BodyItem.GetFormattedText( False, 200 ) 'this looses spaces



	Call CreaFileDaTesto(DirectoryDiLavoroTmp,DirectoryDiLavoroTmp + SepDir + "File." + 				EstensioneFile , TestoCompleto , "Allegato.txt", Mittente, SepDir,  EstensioneFile)

Function CreaFileDaTesto(DirectoryDiLavoroTmp As String,NomeFile As String,TestoFile As String,NomeAllegati As String, Mittente As String,SepDir As String, EstensioneFile As String ) As Integer

	NumeroFile = Freefile()

	Open NomeFile For Output As NumeroFile 'Charset = "Windows-1252"

	

	On Error Goto ErroreNumeroFile

	

	Print #NumeroFile , TestoFile

	Close #NumeroFile

exit function

Sub ConvertiBody(MailDoc As NotesDocument, ConvertToMime As Integer )

'Se la mail è di tipo MIME, la converte in rich text ' If mail is Mime , Convert to RichtText (for avoid crash of server)

'Utilizzata per mail di solo tipo testo



Dim s As New NotesSession



Dim BodyDocArrivato As NotesItem

Dim BodyNewDoc As NotesRichTextItem

Dim TestoBody As String

Dim mime As NotesMIMEEntity



If ConvertToMime Then

	s.convertMime = True 

Else

	s.convertMime = False

End If





On Error Goto ErroreGenerale

	

Set BodyDocArrivato = MailDoc.GetFirstItem("Body")

If BodyDocArrivato.Type = MIME_PART Then 'enr

	

	Set mime = BodyDocArrivato.GetMimeEntity

	TestoBody = mime.ContentAsText

	Set BodyNewDoc = New NotesRichTextItem(MailDoc,"BodyTmp")

	Call BodyNewDoc.AppendText(TestoBody)

	Call MailDoc.RemoveItem("Body")

	Call MailDoc.CopyItem(BodyNewDoc,"Body")

	Call MailDoc.RemoveItem("BodyTmp")

	Call MailDoc.save(True,False)

Else 

	Print "Non è un documento di tipo MIME" 'The mail isn't Mime Format

End If 



Exit Sub

ErroreGenerale:

Print "Routine: ConvertiBody " + "Errore alla linea: " + Cstr(Erl()) + " " + "numero: "+ Cstr(Err) + " " + "Tipo: " + Error$

Resume fine

fine:

Print "Non è stato possibile ricavare il testo della mail"

End Sub

and a simple action on view (in Java) doesn’t work :

import lotus.domino.*;

import java.io.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {



	try {

		Session session = getSession();

		AgentContext agentContext = session.getAgentContext();



		// (Your code goes here) 

		Database dbThis = agentContext.getCurrentDatabase();

		DocumentCollection docs = agentContext.getUnprocessedDocuments();



		Document note = docs.getFirstDocument();

		

		RichTextItem rtBody = (RichTextItem)(note.getFirstItem("Body"));

		

		BufferedInputStream bis = new BufferedInputStream(rtBody.getInputStream());

		int c = 0;

		

		while ((c = bis.read()) != -1) {

			System.out.println(c);

			//System.out.print(".");

		}

		

			

		

	} catch(Exception e) {

		e.printStackTrace();

	}

}

}

Subject: RE: MIssing text with GetFormattedText

For Andre Guirard: Do you have news about the Problem?This problem happens only to me?

Subject: Missing text with GetFormattedText

I’m waiting for you to answer my other questions.

It would also help if you’d say whether the email came from the internet and whether it’s stored in MIME format.

If this is an issue preventing you from doing what you need to do, you should contact Lotus Support and send them a sample database. There’s not really a good alternative to GetFormattedText. If you use the MIME classes you can get the original HTML from a MIME message and parse it yourself, but that’s not really a lot of fun.

Subject: RE: Missing text with GetFormattedText

These are the questions:

Have you looked at the emails you are getting to make sure the spaces are really there in the Notes database?

Yes, I have. If I check the proprierties of document from view, the body has the spaces, and if I open the mail in the client , there are the spaces too.

Have you debugged your agent to see what values it’s really reading? Yes, I have. The getformattedtext and this script don’t work:

Dim rtnav As NotesRichTextNavigator

Dim rtrange As NotesRichTextRange





Set rtnav = BodyItem.CreateNavigator

Set rtrange = BodyItem.CreateRange



Print "Testo NAvigatore"

rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH)

Dim A As Integer

A = 0

Do

	A = A+1

	Call rtrange.SetBegin(rtnav)

	Print Cstr(A) & "-" rtrange.TextParagraph & "-"

Loop While rtnav.FindNextElement(RTELEM_TYPE_TEXTPARAGRAPH)

In the debbugger I don’t see the spaces.

Do you want to maybe post some code? I inserted it in the Previous Post.

I have tried to send the mail from several account from internet and client (outlook, thundirdbird, …), but the problem doesn’t disappear.

This is a mail (example of some proprierties):

Field Name: Body

Data Type: MIME Part

Data Length: 156 bytes

Seq Num: 1

Dup Item ID: 0

Field Flags: SIGN SEAL

"Content-Transfer-Encoding: 7bit

Content-Type: text/plain; charset=ISO-8859-15; format=flowed

3 spaces

 4 spaces

1 spaces

"

Field Name: $NoteHasNativeMIME

Data Type: Text

Data Length: 1 bytes

Seq Num: 1

Dup Item ID: 0

Field Flags: SUMMARY

“1”

Field Name: MIME_Version

Data Type: RFC822 Text

Data Length: 36 bytes

Seq Num: 1

Dup Item ID: 0

Field Flags: SUMMARY

RFC822 Type: TEXT

RFC822 Flags: STRICT

Native Value:

“1.0”

RFC822 Header Name:

“MIME-Version”

RFC822 Header Delimiter:

": "

RFC822 Header Body:

31 2E 30 0D 0A 1.0…

Field Name: X_Accept_Language

Data Type: RFC822 Text

Data Length: 75 bytes

Seq Num: 1

Dup Item ID: 0

Field Flags:

RFC822 Type: TEXT

RFC822 Flags: STRICT

Native Value:

“it, it-it, en-us, en”

RFC822 Header Name:

“X-Accept-Language”

RFC822 Header Delimiter:

": "

RFC822 Header Body:

69 74 2C 20 69 it, i

74 2D 69 74 2C t-it,

20 65 6E 2D 75 en-u

73 2C 20 65 6E s, en

0D 0A …

Subject: RE: Missing text with GetFormattedText

I confirm that leading spaces are getting stripped when you access a plain-text MIME entity using a NotesRichTextItem.

As a workaround, since the MIME entity is plain text, it’s very simple to access the data using the MIME classes instead – it’s probably even more efficient since you’re eliminating a translation step.

session.ConvertMime = False

…

Dim mime As NotesMimeEntity

Set mime = doc.GetMIMEEntity("Body")

Msgbox {"} & mime.ContentAsText & {"}

I don’t know what all emails you will be processing; if there’s some variety you will have to add extra logic to detect what you’re processing, whether it’s multipart, etc. But when I try it on an email that I sent myself, this code doesn’t remove any spaces.