Help Me! MIME in HELL!

HELP!!!

I’ve been digging around the forum and have found TONS of info on MIME, but I have not been able to figure out what I am doing wrong!

I have a script (lotusscript) that gets the mimeentities from two documents, (nme1 and nme2), creates a mime entity in a third document (nme3) - all named “Body” btw. - it then copies the root of nme1 into nme3 using nme1.getentityastext(stream) and nme3.setcontentsfromtext(stream), and the headervalsandparams in similar fashion.

Then I go into a loop of nme1 = nme1.GetNextEntity(SEARCH_DEPTH) and nme3 = nme3.createchildentity and copy the contents and headers as above.

This seems to work well for plain text and text/html.

The problem is when I encounter inline images.

while looping through the items, I check for contenttype = “image”, and if I find it, decode the object and encode it with ENC_BASE64. This should allow the images to display, but it appears to garble the image. ( I get the red x instead of the image)

This is what the image looks like in the original document (body is set to save as MIME):

"–=related 006302C305256FAC=

Content-Type: image/gif

Content-ID: <_1_06CF73B006CF7268006302C305256FAC>

Content-Transfer-Encoding: base64

R0lGODlhMwHLAOcAAP///4CYsEhgeAAAAIiguMDI2HCIoICQoICAgLCYgBggIMDAwDBASHh4eAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/

Pz8/WT8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8DPz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/

Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/

Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/

Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/

Pz …"

All of the other MIME stuff looks fine - it’s as if only the image data is damaged (the cid: is different from doc to doc, but matches up within each document.

I will post the source as a follow-up (this post is long enough already)

Subject: Help Me! MIME in HELL!

Sub Initialize On Error Goto errorhandler

Dim pathname As String	

Dim s As New NotesSession	

s.ConvertMime = False

Dim alog As NotesLog

Set alog = New NotesLog("SendMarketingMail in " & s.CurrentDatabase.FilePath & " on " & s.CurrentDatabase.Server)

Call alog.OpenNotesLog(s.CurrentDatabase.Server, "agentlog.nsf")

Call alog.LogAction("Starting Agent")



Dim con As New ODBCConnection

Dim qry As New ODBCQuery

Dim res As New ODBCResultSet

Dim dc As NotesDocumentCollection

Dim db As NotesDatabase

Dim upass As NotesDatabase

Dim dt As New NotesDateTime(Today)

''

Call dt.AdjustDay(1)

''

Dim doc As NotesDocument

Dim view As NotesView

Dim updoc As NotesDocument	

Dim maildoc As NotesDocument

Dim report As NotesDocument

Dim ni As NotesItem

Dim sentcount As Long

Dim invalidcount As Long

Dim myvar As Variant

Dim ttorg1 As String

Dim body As NotesRichTextItem

Dim rti As NotesRichTextItem

Dim CANSPAM As NotesRichTextItem

Dim ttorg2 As String

Dim pcode As String

Dim prodcount As Long

Dim OOD As NotesDocument

Dim oodc As NotesDocumentCollection	

Dim oot As NotesRichTextItem

Dim rpt As NotesRichTextItem

Dim hvp As String

Dim email As String

Dim st As notesitem

Dim stream As NotesStream

Dim nmh As NotesMimeHeader

Dim CType As String	

Dim Encoding As Integer

‘’‘’‘’‘’‘’‘’’

Dim nme As NotesMimeEntity

Dim nmb As NotesMimeEntity

Dim nma As NotesMimeEntity

Dim nmf As NotesMimeEntity

‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’

Set upass = s.GetDatabase(s.CurrentDatabase.Server, "ZUS\Registration.nsf", False)

Set view = upass.GetView("Agent/Broker\All\By Producer Code")

Set db = s.CurrentDatabase

Set dc = db.Search(|@date(SendDate) = @date(@texttotime("| & dt.DateOnly & |")) & MMSent != "Yes"|,Nothing,0)

Set doc = dc.GetFirstDocument

alog.LogAction(dc.Count & " mailings scheduled for today")

While Not (doc Is Nothing)

	Set maildoc = db.CreateDocument

	maildoc.principal = "ZIBS@zisinternet.com"

	Set report = db.CreateDocument

	report.form = "SendReport"

	report.Subject = doc.subject

	report.toselection = doc.toselection

	report.senton = Evaluate(|@Texttotime("| & dt.DateOnly & |")|)

	Set oodc = db.Search(|Form = "CANSPAM" & Source = "| & doc.source(0) & |"|, Nothing,0)

	Set ood = oodc.GetFirstDocument

	

	'''''''''''''''''' MIME CODING ---- MAIN BODY

	Set stream = s.CreateStream

	Set nme = doc.GetMIMEEntity

	Call nme.DecodeContent

	CType = nme.ContentType

	If Not (nme.ContentSubType = "") Then

		CType = CType & "/" & nme.ContentSubType

	End If		

	Encoding = nme.Encoding

	Call nme.GetContentAsText(stream)		

	Set nmb = maildoc.CreateMIMEEntity("Body")

	Forall h In nme.HeaderObjects

		Set nmh = nmb.GetNthHeader(h.headername)

		If (nmh Is Nothing) Then

			Set nmh = nmb.CreateHeader(h.headername)

		End If

		hvp = h.getheadervalandparams

		Call nmh.SetHeaderValAndParams(hvp)

	End Forall

	Call nmb.SetContentFromText(stream,CTYPE,Encoding)

	If nmb.ContentType ="image" Then

		Call nmb.EncodeContent(ENC_BASE64)

	End If

	nmb.Preamble = nme.Preamble

	Set nmf = nme.GetNextEntity(SEARCH_DEPTH)

	Set stream = Nothing

	While Not (nmf Is Nothing)

		Set stream = s.CreateStream

		Call nmf.DecodeContent

		Set nma = nmb.CreateChildEntity

		CType = nmf.ContentType

		If Not (nmf.ContentSubType = "") Then

			CType = CType & "/" & nmf.ContentSubType

		End If		

		Encoding = nmf.Encoding

		Call nmf.GetContentAsText(stream)

		Call nma.SetContentFromText(stream,CTYPE,Encoding)

		Forall h In nmf.HeaderObjects

			Set nmh = nma.GetNthHeader(h.headername)

			If (nmh Is Nothing) Then

				Set nmh = nma.CreateHeader(h.headername)

			End If

			hvp = h.getheadervalandparams

			Call nmh.SetHeaderValAndParams(hvp)

		End Forall

		If nma.ContentType ="image" Then

			Call nma.EncodeContent(ENC_BASE64)

		End If

		Set nmf = nmf.GetNextEntity(SEARCH_DEPTH)

		Set stream = Nothing

	Wend

‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’

Beyond Here, nothing interesting happens

‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’

	prodcount = 0

	invalidcount = 0

	sentcount = 0

	Set nmh = nme.GetNthHeader("From")

	If (nmh Is Nothing) Then		

		Set nmh = nme.CreateHeader("From")

	End If

	Call nmh.SetHeaderVal("zibs@zisinternet.com")

	Set nmh = nme.GetNthHeader("Replyto")

	If (nmh Is Nothing) Then		

		Set nmh = nme.CreateHeader("Replyto")

	End If

	Call nmh.SetHeaderVal("zibs@zisinternet.com")

	Set nmh = nme.GetNthHeader("Subject")

	If (nmh Is Nothing) Then		

		Set nmh = nme.CreateHeader("Subject")

	End If

	Call nmh.SetHeaderVal(doc.subject(0) & " ADV")

	Set nmh = nme.GetNthHeader("Cc")

	If (nmh Is Nothing) Then		

		Set nmh = nme.CreateHeader("Cc")

	End If

	Call nmh.SetHeaderVal(doc.EnterCopyTo(0))

	report.entersendto = doc.entersendto

	If Not doc.EnterCopyTo(0) = "" Then

’ Call maildoc.send(False)

	End If

	Call nmh.SetHeaderVal("")

	

	'determine if this is an AS400 based mailing or a custom mailing

	If doc.ToSelection(0) = "Custom" Then

		alog.LogAction("Sending mail to custom recipient list")

		Set ni = doc.GetFirstItem("EnterSendTo")

		Forall recipients In ni.Values

’ need to add reporting ??

			myvar = Evaluate(|@DbLookup("":"";"USCNJA02":"mail\\ZIBS Opt-Out.nsf";"SMTPORIGINATOR";@lowercase("| & recipients & |");"SMTPOriginator";[FAILSILENT])|)

			If Not myvar(0) = "" Then

				InvalidCount = InvalidCount + 1

				Call rpt.AppendText("Opt-Out Filtered: " & email)

				Call rpt.AddNewline(1)

			Else

				sentcount = sentcount + 1

				maildoc.sendto = recipients

				Call maildoc.send(False)

			End If

		End Forall

		Call maildoc.remove(True)

	Else

		report.agentorgs = doc.agentorgs

		report.agentstates = doc.agentstates

		Set qry.Connection = con

		Set res.Query = qry

		Call con.ConnectTo("AS400","USER","PSW")

		If con.IsConnected Then

			Set ni = doc.GetFirstItem("Agentorgs")

			Set st = doc.GetFirstItem("AgentStates")

			Forall States In st.Values

				Forall recipients In ni.Values

					qry.SQL = |SELECT * FROM HBIDATA.HBPROD HBPROD, HBIDATA.PRODEXT PRODEXT, HBIDATA.TABORG2 TABORG2 WHERE TABORG2.TTORG1 = PRODEXT.XTORG1 AND TABORG2.TTORG2 = PRODEXT.XTORG2 AND PRODEXT.XTPRODNU = HBPROD.HBPROD_NUMBER AND ((HBPROD.HBPROD_STATE_CODE='| & states &|') AND (TABORG2.TTORGDESC='| & recipients &|') AND (HBPROD.HBPROD_MAIL_CODE='1'))|

					If res.Execute Then

						If res.IsResultSetAvailable Then

							Call res.FirstRow

							Do

								prodcount = prodcount + 1

								pcode = res.GetValue("XTPRODNU")

								Set dc = view.GetAllDocumentsByKey(pcode,True)

								If dc.Count = 0 Then

									InvalidCount = InvalidCount + 1

									Call rpt.AppendText("Producer: " & pcode & " no entry in U>Pass")

									Call rpt.AddNewline(1)

’ Are they not registered?

’ call addEMUpdateLetter(pcode, “”)

								End If

								Set updoc = dc.GetFirstDocument

								While Not (updoc Is Nothing)

									email = updoc.email(0)

									If Not email = "" Then

										myvar = Evaluate(|@DbLookup("":"";"USCNJA02":"mail\\ZIBS Opt-Out.nsf";"SMTPORIGINATOR";@lowercase("| & email & |");"SMTPOriginator";[FAILSILENT])|)

										If Not myvar(0) = "" Then

											InvalidCount = InvalidCount + 1

											Call rpt.AppendText("Producer: " & pcode & " Invalid e-mail address: " & email & " ")

											Call rpt.AppendDocLink(updoc,"U>Pass Document")

											Call rpt.AddNewline(1)

’ call addEMUpdateLetter(pcode, email)

										Else

											myvar = Evaluate(|@ValidateInternetAddress([ADDRESS821];"| & email & |")|)

											If myvar(0) = "" Then

’ maildoc.sendto = email

												sentcount = sentcount + 1

												Print Cstr(sentcount) & " " & email

’ Call maildoc.send(False)

											Else

												InvalidCount = InvalidCount + 1

												Call rpt.AppendText("Producer: " & pcode & " Invalid e-mail address: " & email & " ")

												Call rpt.AppendDocLink(updoc,"U>Pass Document")

												Call rpt.AddNewline(1)

’ call addEMUpdateLetter(pcode, email)

											End If

										End If

									Else

										InvalidCount = InvalidCount + 1

										Call rpt.AppendText("Producer: " & pcode & " No e-mail address found ")

										Call rpt.AddNewline(1)

									End If

									Set updoc = dc.GetNextDocument(updoc)

								Wend

							Loop While res.NextRow

						End If

					Else

					End If

				End Forall

			End Forall

		Else

		End If

		Call maildoc.Remove(True)

	End If

	report.sentcount = sentcount

	report.invalidcount = invalidcount

	report.prodcount = prodcount

	Call report.ComputeWithForm(False,False)

	Call report.MakeResponse(doc)

	Call report.Save(True,False)

	doc.mmsent = "Yes"

	Call doc.Save(True,False)

	Set doc = dc.GetNextDocument(doc)

Wend

EOA:

s.ConvertMime = True

Exit Sub

errorhandler:

alog.LogAction("Error" & Str(Err) & ": " & Error$ & " on line " & Erl)

Resume EOA

End Sub

Subject: This won’t help you but…

… all I could picture from your subject was some poor pantomime silently gesturing for help from inside a burning, shrinking ‘box’. :slight_smile:

Subject: RE: This won’t help you but…

I needed that - I haven’t laughed in at least a day (which is precisely how long I’ve been working on this)

Subject: Help Me! MIME in HELL!

OK - so I can get the image to display in Notes now - but the router gives:

Error transferring to gateway; SMTP Protocol Returned a Permanent Error 556 null byte in data

Subject: RE: Help Me! MIME in HELL!

OMG!!!

After I got it to display in notes, I realized I’d commented out the encode - this caused the null byte error.

I’ll post cleaned up code for all who are interested later…

TGIF.

Subject: Help Me! MIME in HELL!

Hi Peter, Every Body Post his ques for Help. So Please Mension the suitable subject line.

So That Some Body Help u?

Not Like That?

Help Me! MIME in HELL!

Subject: RE: Help Me! MIME in HELL!

I thought it was kinda funny, and you could tell it was MIME related.