Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef SMTP_H
- #define SMTP_H
- #define SMTP_CONNECT_TIMEOUT 7
- class SMTP
- {
- public:
- enum AddressType
- {
- TO = 0,
- CC,
- BCC,
- FROM,
- RETURN
- };
- // A few of those could use bitmasks...
- enum Status
- {
- NOTHING = 0,
- CONNECTED, // Just the raw TCP Connection
- BANNER_RECVIVED,
- EHLO_ACCEPTED,
- AUTHENTICATED,
- SENDER_ACCEPTED,
- RECIPENTS_ACCEPTED,
- DATA_ACCEPTED,
- DELIVERY_SUCCESSFUL
- };
- enum Errors
- {
- NONE = 0,
- CANNOT_CONNECT,
- REJECT_ON_CONNECT,
- HELO_NOT_ACCEPTED,
- SSL_HELO_NOT_ACCEPTED,
- LOGIN_NOT_POSSIBLE,
- CREDENTIALS_WRONG,
- SSL_ERROR_SERVER_NOT_READY,
- SSL_ERROR_CONNECT,
- SENDER_NOT_ACCEPTED,
- RECIPENTS_NOT_ACCEPTED,
- DATA_NOT_ACCEPTED,
- SPAM_MESSAGE_DETECTED,
- GREYLISTED,
- CONNECTION_DROPPED
- };
- struct Address
- {
- std::string a;
- std::string friendlyName;
- };
- SMTP();
- ~SMTP();
- bool connect(std::string server, std::string ehloName, bool useAuthenticatedPort);
- bool connect(std::vector<MX_Information> servers, std::string ehloName, bool useAuthenticatedConnection);
- VOID add_address(Address address, AddressType type);
- bool send();
- bool supports_feature(std::string feature);
- void print_supported_functions()
- {
- for(std::vector<std::string>::iterator i = supportedFunctions.begin(); i != supportedFunctions.end(); i++)
- printf("%s\n", i->c_str());
- }
- char* get_reply_code()
- {
- buffer[3] = 0;
- return buffer;
- }
- char* get_reply_message()
- {
- return &buffer[4];
- }
- VOID send_NOOP();
- // Crypto & Auth
- bool is_login_possible();
- bool is_TLS_possible();
- bool switch_to_TLS();
- bool authenticate(std::string user, std::string password);
- //Fixme: Remove. Only used in TestSMTPError (Todo: Make TestSMTPError a friend?)
- void send_command(std::string command)
- {
- sock->Send(command);
- recv_reply();
- }
- void add_attachment(std::string data, std::string name, std::string type);
- void add_attachment(const unsigned char* data, size_t len, std::string name, std::string type);
- void set_subject(std::string subj){subject = subj;}
- void set_message(std::string msg){message = msg;}
- void set_HTML_message(std::string msg){htmlMessage = msg;}
- bool is_connected()
- {
- return connected;
- }
- int get_error()
- {
- if(sock->GetConnectionClosed())
- currentError = CONNECTION_DROPPED;
- return currentError;
- }
- int get_status()
- {
- return currentStatus;
- }
- private:
- std::string subject;
- std::string message, htmlMessage;
- struct Attachment
- {
- std::string data;
- std::string name;
- std::string type;
- };
- std::vector<Attachment> attachments;
- // Used later when switching to SSL
- std::string ehloName;
- std::string server;
- bool connected;
- bool authenticated;
- bool usingSSL;
- Status currentStatus;
- Errors currentError;
- char errorCode[4];
- AbstractSocket* sock;
- std::vector<Address> toAddress;
- std::vector<Address> ccAddress;
- std::vector<Address> bccAddress;
- Address fromAddress;
- Address returnAddress;
- std::vector<std::string> supportedFunctions;
- std::string heloMessage;
- char buffer[0x1000];
- size_t length;
- bool get_supported_functions();
- VOID recv_reply();
- bool is_successful();
- bool is_successful(char* successStatusCode);
- void get_date(std::string& res);
- // TODO: Header template?
- void build_envelope_header(std::string& header);
- void format_address(Address& a, std::string& res);
- // TODO: Find out which triggered the error? Which error?
- bool send_recipents(std::vector<Address>& addresses);
- void add_envelope_recipent(std::string recipentType, std::vector<Address>& address, std::string& res);
- // Computes the boundary from the message or the from Address
- std::string get_boundary(std::string seed);
- void build_message_body(std::string& body);
- };
- #endif // SMTP_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement