WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Postie

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

UDF to Extract the HTML message from Postie raw output

Keywords:    Extract the HTML message from Postie raw output

Here is a UDF to return the HTML message from a Postie raw file created from kGetMail. The UDF will not return HTML attachments... only the message body if it is HTML.
;***************************************************************************
;** 
;** udfRaw2HtmlMessage - Bill Meek - 07-19-2002
;** 
;** Purpose: Read a Postie raw file and return the HTML message portion 
;** Inputs: Raw file from Postie Extender
;** Outputs: Returns HTML message string or 0 for no message 
;** Revisions: 
;***************************************************************************

#DefineFunction udfRaw2HtmlMessage(rawfile)
   fs=FileSize(rawfile)
   rawbuf=BinaryAlloc(fs)
   BinaryRead(rawbuf, rawfile)
   htmlmessage=0
   startsect=-1
   While @TRUE
      curroffset = startsect+1
      ;find boundary delimiter start location
      startsect=BinaryIndexEx(rawbuf, curroffset, StrCat(@CRLF, "--"), @FWDSCAN, 0)
      ;if boundary not found then break
      If startsect == -1 Then Break
      ;find next boundary delimiter 
      nextsect=BinaryIndexEx(rawbuf, startsect+1, StrCat(@CRLF, "--"), @FWDSCAN, 0)
      If nextsect == -1 Then nextsect = BinaryEODGet(rawbuf)
      ;look between the boundary location for HTML ("Content-Type: text/html")
      htmlloc=BinaryIndexEx(rawbuf, curroffset, "Content-Type: text/html", @FWDSCAN, 0)   
      If htmlloc == -1 Then Break
      If htmlloc >= startsect && htmlloc <= nextsect
         ;see if is attachment
         attachloc=BinaryIndexEx(rawbuf, curroffset, "Content-Disposition: attachment", @FWDSCAN, 0)
         ;if section is attachment then skip
         If attachloc >= startsect && attachloc <= nextsect Then Continue
         ;Find first blank line location
         blloc=BinaryIndexEx(rawbuf, startsect, StrCat(@CRLF, @CRLF), @FWDSCAN, 0)
         ;Find the HTML message text
         htmlmessage=BinaryPeekStr(rawbuf, blloc+4, nextsect-blloc-2)
         Break
      EndIf
   EndWhile
   BinaryFree(rawbuf)
   Return(htmlmessage)
#EndFunction


;*****Test the UDF*****

;Get a rawfile path/filename
myrawfile=AskFileName("Select Postie raw file", "", "Postie raw files|*.raw|All files|*.*", "", 1)

;call the udf
htmlmessage=udfRaw2HtmlMessage(myrawfile)

if htmlmessage == 0
   message(myrawfile, "No HTML message found")   
else
   message(myrawfile, htmlmessage)
EndIf

Article ID:   W15064
File Created: 2017:07:28:12:58:35
Last Updated: 2002:09:05:12:49:24