view Email Body "DOCTYPE html"

Discuss anything else that does not suite other forums.

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

view Email Body "DOCTYPE html"

Post by AUGE_OHR »

hi,

i can send / receive Email with hbTIP but there is still a Question : how to view / Print a Email Body :?:

Code: Select all

   cBody := aEmail:getBody()
   DO CASE
      CASE "DOCTYPE html" $ cBody
         STRFILE(cBody,cFileName)
         RUN myView(cFileName)
as i don't know Email Structure my Question is : can i show a Body with "DOCTYPE html" in a HTML Viewer :?:
have fun
Jimmy
User avatar
danielmaximiliano
Posts: 2625
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: view Email Body "DOCTYPE html"

Post by danielmaximiliano »

My code

Code: Select all

#define CRLF  INetCRLF()

#require "hbtip"
REQUEST __HBEXTERN__HBSSL__

Code: Select all

/*****************************************************************************/  
Procedure Email_GetBody()
/*****************************************************************************/  
 
   lResetServer      := oPopServer:Reset()
   cMail             := oPopServer:retrieve( Incomming.Messages.Value  ) 
   
   If oPopServer:lastErrorCode() != 0 
      
      MsgInfo( 'The message does not exist or was deleted ' + Chr( 10 ) +;
               'Server responds : ' + oPopServer:lastErrorMessage() ,;
               ' Attention Message  ' )
        oPopServer:Close()       
        lOpen                       := .F.
        Incomming.Connect.Enabled   := .T.
        Incomming.ReadTray.Enabled  := .F.
        Incomming.Messages.DeleteAllItems
        Incomming.LabelServer.Hide
        Incomming.LabelReply.Hide 
        Incomming.Server.Show
        Incomming.cPass.Show
        Incomming.cUser.Show
        Incomming.User_1.Show
        Incomming.Pass_1.Show  
        Return
   Endif 
   
   aEmail    := TIPMail():new()
   oEmail    := aEmail:fromString( cMail )
   
   IF aEmail:isMultiPart() 
      // Retrieve all parts of a multipart message 
      aParts := aEmail:getMultiParts( )
           /* through all parts of the eMail */
       FOR EACH oPart IN aParts
           IF .NOT. Empty( oPart:getFileName() )
              If MsgYesNo(' download the attachment : ' + oPart:getFileName() , ;
                          ' Select Y / N ' )
                // This is a file attachment. Store it in the TMP folder.
                IF .NOT. oPart:detachFile( cCurrentFolder+'\Attachment' )
                  MsgExclamation('Could not save the file : ' + oPart:getFileName() , ' !! Warning Message ¡¡ ' )
                ENDIF
              Endif
           ELSE
               CreateHtml(oPart:getBody() , oPart:GetFieldPart( "Content-Type" ))   
           Endif
      NEXT  
   ELSE  // Is simple eMail message
       CreateHtml(aEmail:getBody() , aEmail:GetFieldPart( "Content-Type" ))   
   Endif 
               
Return

Code: Select all

/*****************************************************************************/
Function CreateHtml( cStringBody , cEmailType )
/*****************************************************************************/
   LOCAL oHTML := THtml():New()

   oHTML:SetTitle( 'HBTIP' )
   
   oHTML:AddPara( cStringBody , "LEFT" )
   
   oHTML:Generate()

   oHTML:SaveToFile( cCurrentFolder + '/Html/email.html' )
   
   Incomming.oBody.Object:Navigate('file:///' + cCurrentFolder + '/Html/email.html')
   
RETURN
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: view Email Body "DOCTYPE html"

Post by AUGE_OHR »

danielmaximiliano wrote: Sun Nov 24, 2019 1:38 am My code
WOW ... so "easy" if know how :D
THX
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: view Email Body "DOCTYPE html"

Post by AUGE_OHR »

hi,

Question about THTML() : is it from HMG :?:
THTML_ERROR.jpg
THTML_ERROR.jpg (44.15 KiB) Viewed 2336 times
when search in HMG DOC it have other Syntax :o
Description

THtml() is a class that creates an .html file of the same name you pass to the constructor.
The class methods are as follows:

New(<cFile>) Create a new instance of the THtml class
Close() Close the created file
WriteTitle(<cTitle>) Write the file title
WritePar(<cPar>) Writes a paragraph
WriteParBold(<cPar>) Same as WritePar(), but the text is
WriteLink(<cLink>,<cName>) Write a link to another topic
WriteText(<cText>) Write any text
so none of your Method exist :(

Code: Select all

   oHTML:SetTitle( 'HBTIP' )
   oHTML:AddPara( cStringBody , "LEFT" )
   oHTML:Generate()
   oHTML:SaveToFile( cCurrentFolder + '/Html/email.html' )
so where is your CLASS Thtml() come from :?:
thx for help
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: view Email Body "DOCTYPE html"

Post by AUGE_OHR »

i have test it with QHTM() ... it work general but to much empty "frame" (did not download Images)
have to make more test to get "only" text to read
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: view Email Body "DOCTYPE html"

Post by AUGE_OHR »

hi,

i get Email where Body is empty ... hm

than i saw this in Email Source
Content-Type: multipart/related;
boundary="----=_Part_54615146_1810148544.1574637521787"

------=_Part_54615146_1810148544.1574637521787
Content-Type: text/html; charset=UTF-8;
Content-Transfer-Encoding: quoted-printable
so how get that Part :?:
here is the EML File
MAIL_EML.ZIP
(18.62 KiB) Downloaded 145 times

Code: Select all

            IF aEmail:isMultiPart()
               // odczytanie wszystkich cze˜ci wiadomo˜ci
               // reading all parts of the message
               aParts := aEmail:getMultiParts()
               nPart := 0
               FOR EACH oPart IN aParts
i got in aParts[1]:cBody what i want but i can't access it.
Error BASE/41 Scope violation (hidden): TIPMAIL:CBODY
Called from TIPMAIL:CBODY(0)
Called from GETEMAIL(436)
Called from (b)MAIN(81)
Called from _PROCESSINITPROCEDURE(5876)
Called from _ACTIVATEWINDOW(5627)
Called from MAIN(172)
who can help please.
Attachments
Pearl_Attachment.JPG
Pearl_Attachment.JPG (77.66 KiB) Viewed 2277 times
have fun
Jimmy
User avatar
danielmaximiliano
Posts: 2625
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: view Email Body "DOCTYPE html"

Post by danielmaximiliano »

AUGE_OHR wrote: Mon Nov 25, 2019 8:06 am i have test it with QHTM() ... it work general but to much empty "frame" (did not download Images)
have to make more test to get "only" text to read

Code: Select all

#include "hbclass.ch"

CREATE CLASS THTML

   VAR cTitle                             // Page Title
   VAR cBody                              // HTML Body Handler
   VAR cBGColor                           // Background Color
   VAR cLinkColor                         // Link Color
   VAR cvLinkColor                        // Visited Link Color
   VAR cContent                           // Page Content Handler

   METHOD New()                           // New Method
   METHOD SetTitle( cTitle )              // Set Page Title
   METHOD AddLink( cLinkTo, cLinkName )   // Add <H1> Header
   METHOD AddHead( cDescr )               // Add Hyperlink
   METHOD AddPara( cPara, cAlign )        // Add Paragraph
   METHOD Generate()                      // Generate HTML
   METHOD SaveToFile( cFile )             // Show Result

END CLASS

METHOD New() CLASS THTML

   ::cTitle      := "Untitled"
   ::cBGColor    := "#FFFFFF"
   ::cLinkColor  := "#0000FF"
   ::cvLinkColor := "#FF0000"
   ::cContent    := ""
   ::cBody       := ""

   RETURN Self

METHOD SetTitle( cTitle ) CLASS THTML

   ::cTitle := cTitle

   RETURN Self

METHOD AddLink( cLinkTo, cLinkName ) CLASS THTML

   ::cBody := ::cBody + ;
      "<a href='" + cLinkTo + "'>" + cLinkName + "</a>"

   RETURN Self

METHOD AddHead( cDescr ) CLASS THTML

   // Why this doesn't work?
   // ::cBody += ...
   // ???

   ::cBody := ::cBody + ;
      "<h1>" + cDescr + "</h1>"

   RETURN NIL

METHOD AddPara( cPara, cAlign ) CLASS THTML

   cAlign := iif( cAlign == NIL, "Left", cAlign ) // Added Patrick Mast 2000-06-17

   ::cBody := ::cBody + ;
      "<p align='" + cAlign + "'>" + hb_eol() + ;
      cPara + hb_eol() + ;
      "</p>"

   RETURN Self

METHOD Generate() CLASS THTML

   ::cContent :=                                                           ;
      "<html><head>"                                          + hb_eol() + ;
      "<title>"      + ::cTitle + "</title>"                  + hb_eol() + ;
      "<body link='" + ::cLinkColor + "' " +                               ;
      "vlink='"      + ::cvLinkColor + "'>" +                 + hb_eol() + ;
                       ::cBody                                + hb_eol() + ;
      "</body></html>"

   RETURN Self

METHOD SaveToFile( cFile ) CLASS THTML

   LOCAL hFile := FCreate( cFile )

   FWrite( hFile, ::cContent )
   FClose( hFile )

   RETURN Self
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: view Email Body "DOCTYPE html"

Post by AUGE_OHR »

hi,

your CLASS Thtml work much better for what i want, THX
have fun
Jimmy
Post Reply