1 /*
2  * Copyright (C) 2002-2003 Fhg Fokus
3  *
4  * This file is part of SEMS, a free SIP media server.
5  *
6  * SEMS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version. This program is released under
10  * the GPL with the additional exemption that compiling, linking,
11  * and/or using OpenSSL is allowed.
12  *
13  * For a license to use the SEMS software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * SEMS is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27 /** @file AmSmtpClient.h */
28 #ifndef _AmSmtpClient_h_
29 #define _AmSmtpClient_h_
30 
31 #include "AmMail.h"
32 
33 #include <string>
34 #include <vector>
35 using std::string;
36 using std::vector;
37 
38 /**
39  * SMTP Line buffer for commands and responses
40  * (not for data transmission!)
41  */
42 #define SMTP_LINE_BUFFER  512
43 
44 /**
45  * \brief SMTP client implementation
46  *
47  */
48 class AmSmtpClient
49 {
50   string         server_ip;
51   unsigned short server_port;
52 
53   /** socket descriptor */
54   int          sd;
55   /** size of last response receved */
56   unsigned int received;
57   /** recv & scratch buffer */
58   char         lbuf[SMTP_LINE_BUFFER];
59   /** code of the last response */
60   unsigned int res_code;
61   /** code of the last response */
62   //char         res_code_str[4]; // null-terminated
63   /** textof the last response */
64   string       res_msg;
65 
66   enum Status { st_None=0, st_Ok, st_Error, st_Unknown };
67   /** Client status */
68   Status status;
69 
70   /** @return true if failed */
71   bool read_line();
72   /** @return true if failed */
73   bool get_response();
74   /** @return true if failed */
75   bool parse_response();
76   /** @return true if failed */
77   bool send_line(const string& cmd);
78   /** @return true if failed */
79   bool send_data(const vector<string>& hdrs, const AmMail& mail);
80   /** @return true if failed */
81   bool send_command(const string& cmd);
82   /** @return true if failed */
83   bool send_body(const vector<string>& hdrs, const AmMail& mail);
84 
85 public:
86   AmSmtpClient();
87   ~AmSmtpClient();
88 
89   /** @return true if failed */
90   bool connect(const string& _server_ip, unsigned short _server_port);
91   /** @return true if failed */
92   bool send(const AmMail& mail);
93   /** @return true if failed */
94   bool disconnect();
95   /** @return true if failed */
96   bool close();
97 };
98 
99 #endif
100 
101 // Local Variables:
102 // mode:C++
103 // End:
104 
105