Compose is called strictly as part of an email origination process. Once everything has been added in - the sender, the complete list of reciepients, the subject, the body, and files named as attachments, Compose is called to compile into a single chain, the complete message as it will be relayed. Arguments: None

Return TypeFunction nameArguments
hzEcodehzEmail::Compose(void)

Declared in file: hzMailer.h
Defined in file : hzMailer.cpp

Function Logic:

0:START 1:plog 2:unknown 3:items 4:items items rx ema items 5:unknown 6:ema items 7:unknown 8:rx ema items 9:unknown 10:ema items 11:unknown 12:rx ema items 13:unknown 14:ema items 15:items 16:unknown 17:items pid items items items items items items items m_Final items 18:unknown 19:A rc 20:unknown 21:items items items items items i 22:unknown 23:items 24:i 25:items items items items items items items 26:items 27:items items items m_Final items 28:Return rc

Function body:

hzEcode hzEmail::Compose (void)
{
   //  Category: Mail Composition
   //  
   //  Compose is called strictly as part of an email origination process. Once everything has been added in - the sender, the complete list of reciepients, the subject, the body,
   //  and files named as attachments, Compose is called to compile into a single chain, the complete message as it will be relayed.
   //  
   //  Arguments: None
   //  
   //  Returns: E_NOTFOUND If any attachment filepath specified does not exist
   //     E_TYPE  If any attachment filepath names a directory entry that is not a file
   //     E_NODATA If any attachment filepath is a file but empty
   //     E_OPENFAIL If any attachment file specified could not be opened for reading
   //     E_OK  If this email message was successfully composed
   _hzfunc("hzEmail::Compose") ;
   hzList<hzEmaddr>::Iter  rx ;    //  Recipients iterator
   hzList<_efile>::Iter    iA ;    //  Attachments iterator
   ifstream        is ;            //  Attachment input stream
   hzEmaddr        ema ;           //  Email address
   _efile          A ;             //  Attachment
   hzXDate         now ;           //  Current time and date stamp
   hzChain         filedata ;      //  Working output chain
   hzLogger*       plog ;          //  Current thread logger
   const char*     i ;             //  Forward slash position
   uint32_t        pid ;           //  Process id (part of mail-id)
   char            idbuf[60];      //  Mail-Id buffer
   hzEcode         rc = E_OK ;     //  Return code
   plog = GetThreadLogger() ;
   if (!plog)
       Fatal("No thrread logger\n") ;
   m_Final.Clear() ;
   m_Final.Printf("From: %s <%s>\r\n", *m_RealFrom, *m_AddrFrom) ;
   //  if (_hzGlobal_Debug & HZ_DEBUG_MAILER)
   //   plog->Log("Have a total of %d std recipients\n", m_Recipients.Count()) ;
   //  Deal with main recipients
   rx = m_Recipients ;
   ema = rx.Element() ;
   m_Final.Printf("To: %s\r\n", *ema) ;
   for (rx++ ; rx.Valid() ; rx++)
   {
       ema = rx.Element() ;
       m_Final.Printf("    %s\r\n", *ema) ;
   }
   //  Deal with carbon copy recipients
   if (m_CC.Count())
   {
       rx = m_CC ;
       ema = rx.Element() ;
       m_Final.Printf("Cc: %s\r\n", *ema) ;
       for (rx++ ; rx.Valid() ; rx++)
       {
           ema = rx.Element() ;
           m_Final.Printf("    %s\r\n", *ema) ;
       }
   }
   //  Deal with blind carbon copy recipients
   if (m_BCC.Count())
   {
       rx = m_BCC ;
       ema = rx.Element() ;
       m_Final.Printf("Bcc: %s\r\n", *ema) ;
       for (rx++ ; rx.Valid() ; rx++)
       {
           ema = rx.Element() ;
           m_Final.Printf("    %s\r\n", *ema) ;
       }
   }
   m_Final.Printf("Subject: %s\r\n", *m_Subject) ;
   if (m_SendAttach.Count())
   {
       now.SysDateTime() ;
       pid = getpid() ;
       sprintf(idbuf, "%d--%04d%02d%02d%02d%02d%02d.%06d--%x",
           pid, now.Year(), now.Month(), now.Day(), now.Hour(), now.Min(), now.Sec(), now.uSec(), pid) ;
       m_Final << "MIME-Version: 1.0\r\n" ;
       m_Final.Printf("Content-Type: multipart/mixed; boundary=\"%s\"\r\n\r\n", idbuf) ;
       m_Final << "This is a multi-part message in MIME format.\r\n\r\n" ;
       m_Final.Printf("--%s\r\n", idbuf) ;
       m_Final << "Content-Type: text/plain; charset=utf-8; format=flowed\r\n" ;
       m_Final << "Content-Transfer-Encoding: 7bit\r\n\r\n" ;
       m_Final += m_Text ;
       m_Final << "\r\n\r\n" ;
       for (iA = m_SendAttach ; iA.Valid() ; iA++)
       {
           A = iA.Element() ;
           rc = OpenInputStrm(is, A.m_Filepath) ;
           if (rc != E_OK)
               break ;
           filedata.Clear() ;
           filedata << is ;
           m_Final.Printf("--%s\r\n", idbuf) ;
           m_Final << "Content-Type: " ;
           m_Final << Mimetype2Txt(A.m_eType) ;
           i = strrchr(*A.m_Filepath, CHAR_FWSLASH) ;
           if (i)
               i++ ;
           else
               i = A.m_Filepath ;
           m_Final.Printf("; name=\"%s\"\r\n", i) ;
           m_Final << "Content-Transfer-Encoding: base64\r\n" ;
           m_Final.Printf("Content-Disposition: attachment; filename=\"%s\"\r\n\r\n", i) ;
           Base64Encode(m_Final, filedata) ;
           m_Final << "\r\n" ;
           is.close() ;
           is.clear() ;
       }
       m_Final.Printf("--%s--\r\n", idbuf) ;
   }
   else
   {
       //  No attachements. No multipart MIME thing
       m_Final << "MIME-Version: 1.0\r\n" ;
       m_Final << "Content-Type: text/plain; charset=utf-8; format=flowed\r\n" ;
       m_Final << "Content-Transfer-Encoding: 7bit\r\n\r\n" ;
       m_Final += m_Text ;
       m_Final << "\r\n\r\n" ;
   }
   return rc ;
}