Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Smtp.h

Go to the documentation of this file.
00001 #ifndef SMTP_H
00002 #define SMTP_H
00003 
00004 #include <abuse/abuse.h>
00005 #include <abuse/Url.h>
00006 #include <abuse/smtp_error.h>
00007 #include <abuse/VirtStream.h>
00008 #include <abuse/ZeSocket.h>
00009 #include <iterator>
00010 #include <list>
00011 #include <fstream>
00012 
00013 class Smtp
00014 {
00015 public:
00016         Smtp(VirtStream& hOut,const std::string& logfilename="")throw(net_error);
00017         Smtp(VirtStream& hOut,std::ofstream* log=NULL)throw(net_error);
00018         virtual ~Smtp();
00019         //connect to the mailserver
00020         virtual void connect(const Url& to,short int port=25)throw(net_error);
00021         virtual void helo(const std::string& helostr="")throw(smtp_error);
00022         void mailFrom(const std::string& email,const std::string& name="")throw(smtp_error);
00023         void rcptTo(const std::string& email)throw(smtp_error);
00024         void rcptTo(std::istream_iterator<std::string>& begin,std::istream_iterator<std::string>& end)throw(smtp_error);
00025         void bccTo(const std::string& email)throw(smtp_error);
00026         void data(const std::string& data, const std::string& subject)throw(smtp_error);
00027         void addHeaders(const std::string& headers);
00028         void reset()throw(smtp_error);
00029         virtual void quit();
00030         enum Flags{NODATE=1};
00031         void setFlags(Flags newFlags);
00032         Flags getFlags()const;
00033 protected:
00034         //are we connected to the mail server
00035         bool m_bConnected;
00036         //flags about RFC headers
00037         Flags flags;
00038         //logfile, if present
00039         std::ofstream* m_log;
00040         //does the class own the logfile?
00041         bool m_bOwnLog;
00042         //window to log onto 
00043         VirtStream* m_out;
00044         //socket to the mail server
00045         ZeSocket m_sock;
00046         //From: header
00047         std::string from;
00048         //To: header list
00049         std::list<std::string> to;
00050         //get the result and check for error
00051         std::string additionalHeaders;
00052         std::string getResult()throw(smtp_error);
00053         //add RFC-requested headers
00054         std::string addRFCHeaders(const std::string& subject);
00055         // Output original msg From: & Date: lines to log
00056         void Smtp::buildLogEntry(const std::string& data);
00057         //logging facility
00058         void log(const std::string& msg)
00059         {
00060                 if(m_log) 
00061                 {
00062                         *m_log<<msg;
00063 #ifdef SPECIALBUILD
00064                         m_log->flush();
00065 #endif
00066                 }
00067 
00068         }
00069         //ex RFC 822 bis section 2.3
00070         static std::string substLfWithCrLf(const std::string& str);
00071 };
00072 
00073 #endif //SMTP_H

Generated on Thu Jun 16 00:13:14 2005 for Netlib for Abuse! by  doxygen 1.4.3