Strip out jwsmtp and the server mailer based on it.
Turn related functions into stubs
This commit is contained in:
parent
e64d34bd19
commit
57b6e955b1
14 changed files with 3 additions and 2475 deletions
|
@ -504,7 +504,6 @@ SET(wesnothd_SRC
|
|||
server/ban.cpp
|
||||
server/game.cpp
|
||||
server/input_stream.cpp
|
||||
server/mail.cpp
|
||||
server/metrics.cpp
|
||||
server/player.cpp
|
||||
server/player_network.cpp
|
||||
|
@ -520,9 +519,6 @@ SET(wesnothd_SRC
|
|||
time.cpp
|
||||
network_worker.cpp
|
||||
loadscreen_empty.cpp
|
||||
server/jwsmtp/mailer.cpp
|
||||
server/jwsmtp/compat.cpp
|
||||
server/jwsmtp/base64.cpp
|
||||
)
|
||||
|
||||
add_executable(wesnothd ${wesnothd_SRC})
|
||||
|
|
|
@ -296,7 +296,6 @@ wesnothd_SOURCES = \
|
|||
server/ban.cpp \
|
||||
server/game.cpp \
|
||||
server/input_stream.cpp \
|
||||
server/mail.cpp \
|
||||
server/metrics.cpp \
|
||||
server/player.cpp \
|
||||
server/player_network.cpp \
|
||||
|
@ -308,9 +307,6 @@ wesnothd_SOURCES = \
|
|||
server/user_handler.cpp \
|
||||
server/forum_user_handler.cpp \
|
||||
server/sample_user_handler.cpp \
|
||||
server/jwsmtp/mailer.cpp \
|
||||
server/jwsmtp/compat.cpp \
|
||||
server/jwsmtp/base64.cpp \
|
||||
network.cpp \
|
||||
network_worker.cpp \
|
||||
time.cpp \
|
||||
|
|
|
@ -420,11 +420,7 @@ wesnothd_sources = Split("""
|
|||
server/sample_user_handler.cpp
|
||||
server/simple_wml.cpp
|
||||
server/user_handler.cpp
|
||||
server/mail.cpp
|
||||
time.cpp
|
||||
server/jwsmtp/mailer.cpp
|
||||
server/jwsmtp/compat.cpp
|
||||
server/jwsmtp/base64.cpp
|
||||
""")
|
||||
wesnothd_sources.extend(env.Object("server/server.cpp", EXTRA_DEFINE = env['fifodir'] and "FIFODIR='\"$fifodir\"'" or None))
|
||||
|
||||
|
|
|
@ -1,234 +0,0 @@
|
|||
// Note that the only valid version of the GPL as far as jwSMTP
|
||||
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
|
||||
// unless explicitly otherwise stated.
|
||||
//
|
||||
// This file is part of the jwSMTP library.
|
||||
//
|
||||
// jwSMTP library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; version 2 of the License.
|
||||
//
|
||||
// jwSMTP library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with jwSMTP library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// jwSMTP library
|
||||
// http://johnwiggins.net
|
||||
// smtplib@johnwiggins.net
|
||||
//
|
||||
// base64.h: base64 encoding functions
|
||||
//
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "base64.h"
|
||||
|
||||
namespace jwsmtp {
|
||||
|
||||
char getbase64character(const char& in)
|
||||
{
|
||||
switch(in) {
|
||||
case B64_A:
|
||||
return 'A';
|
||||
case B64_B:
|
||||
return 'B';
|
||||
case B64_C:
|
||||
return 'C';
|
||||
case B64_D:
|
||||
return 'D';
|
||||
case B64_E:
|
||||
return 'E';
|
||||
case B64_F:
|
||||
return 'F';
|
||||
case B64_G:
|
||||
return 'G';
|
||||
case B64_H:
|
||||
return 'H';
|
||||
case B64_I:
|
||||
return 'I';
|
||||
case B64_J:
|
||||
return 'J';
|
||||
case B64_K:
|
||||
return 'K';
|
||||
case B64_L:
|
||||
return 'L';
|
||||
case B64_M:
|
||||
return 'M';
|
||||
case B64_N:
|
||||
return 'N';
|
||||
case B64_O:
|
||||
return 'O';
|
||||
case B64_P:
|
||||
return 'P';
|
||||
case B64_Q:
|
||||
return 'Q';
|
||||
case B64_R:
|
||||
return 'R';
|
||||
case B64_S:
|
||||
return 'S';
|
||||
case B64_T:
|
||||
return 'T';
|
||||
case B64_U:
|
||||
return 'U';
|
||||
case B64_V:
|
||||
return 'V';
|
||||
case B64_W:
|
||||
return 'W';
|
||||
case B64_X:
|
||||
return 'X';
|
||||
case B64_Y:
|
||||
return 'Y';
|
||||
case B64_Z:
|
||||
return 'Z';
|
||||
case B64_a:
|
||||
return 'a';
|
||||
case B64_b:
|
||||
return 'b';
|
||||
case B64_c:
|
||||
return 'c';
|
||||
case B64_d:
|
||||
return 'd';
|
||||
case B64_e:
|
||||
return 'e';
|
||||
case B64_f:
|
||||
return 'f';
|
||||
case B64_g:
|
||||
return 'g';
|
||||
case B64_h:
|
||||
return 'h';
|
||||
case B64_i:
|
||||
return 'i';
|
||||
case B64_j:
|
||||
return 'j';
|
||||
case B64_k:
|
||||
return 'k';
|
||||
case B64_l:
|
||||
return 'l';
|
||||
case B64_m:
|
||||
return 'm';
|
||||
case B64_n:
|
||||
return 'n';
|
||||
case B64_o:
|
||||
return 'o';
|
||||
case B64_p:
|
||||
return 'p';
|
||||
case B64_q:
|
||||
return 'q';
|
||||
case B64_r:
|
||||
return 'r';
|
||||
case B64_s:
|
||||
return 's';
|
||||
case B64_t:
|
||||
return 't';
|
||||
case B64_u:
|
||||
return 'u';
|
||||
case B64_v:
|
||||
return 'v';
|
||||
case B64_w:
|
||||
return 'w';
|
||||
case B64_x:
|
||||
return 'x';
|
||||
case B64_y:
|
||||
return 'y';
|
||||
case B64_z:
|
||||
return 'z';
|
||||
case B64_0:
|
||||
return '0';
|
||||
case B64_1:
|
||||
return '1';
|
||||
case B64_2:
|
||||
return '2';
|
||||
case B64_3:
|
||||
return '3';
|
||||
case B64_4:
|
||||
return '4';
|
||||
case B64_5:
|
||||
return '5';
|
||||
case B64_6:
|
||||
return '6';
|
||||
case B64_7:
|
||||
return '7';
|
||||
case B64_8:
|
||||
return '8';
|
||||
case B64_9:
|
||||
return '9';
|
||||
case plus:
|
||||
return '+';
|
||||
case slash:
|
||||
return '/';
|
||||
case padding:
|
||||
return '=';
|
||||
}
|
||||
return '\0'; // ?????? yikes
|
||||
}
|
||||
|
||||
std::vector<char> base64encode(const std::vector<char>& input, const bool returns) {
|
||||
std::vector<char> output;
|
||||
|
||||
// add a newline (SMTP demands less than 1000 characters in a message line).
|
||||
long count = 0;
|
||||
for(std::vector<char>::size_type p = 0; p < input.size(); p+=3) {
|
||||
output.push_back(getbase64character((input[p] & 0xFC) >> 2));
|
||||
++count;
|
||||
|
||||
if(p+1 < input.size()) {
|
||||
output.push_back(getbase64character(((input[p] & 0x03) <<4) | ((input[p+1] & 0xF0) >> 4)));
|
||||
++count;
|
||||
}
|
||||
if(p+2 < input.size()) {
|
||||
output.push_back(getbase64character(((input[p+1] & 0x0F) <<2) | ((input[p+2] & 0xC0) >>6)));
|
||||
output.push_back(getbase64character((input[p+2] & 0x3F)));
|
||||
++count;
|
||||
}
|
||||
|
||||
if(p+1 == input.size()) {
|
||||
output.push_back(getbase64character(((input[p] & 0x03) <<4)));
|
||||
}
|
||||
else if(p+2 == input.size()) {
|
||||
output.push_back(getbase64character(((input[p+1] & 0x0F) <<2)));
|
||||
}
|
||||
|
||||
if(returns) {
|
||||
// 79 characters on a line.
|
||||
if(count > 75) {
|
||||
output.push_back('\r');
|
||||
output.push_back('\n');
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int pad(input.size() % 3);
|
||||
if(pad) {
|
||||
if(pad == 1)
|
||||
pad = 2;
|
||||
else
|
||||
pad = 1;
|
||||
}
|
||||
for(int i = 0; i < pad; ++i)
|
||||
output.push_back('=');
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string base64encode(const std::string& input, const bool returns) {
|
||||
std::vector<char> in, out;
|
||||
for(std::string::const_iterator it = input.begin(); it != input.end(); ++it) {
|
||||
in.push_back(*it);
|
||||
}
|
||||
out = base64encode(in, returns);
|
||||
std::string ret;
|
||||
for(std::vector<char>::const_iterator it1 = out.begin(); it1 != out.end(); ++it1) {
|
||||
ret += *it1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // end namespace jwsmtp
|
||||
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
// Note that the only valid version of the GPL as far as jwSMTP
|
||||
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
|
||||
// unless explicitly otherwise stated.
|
||||
//
|
||||
// This file is part of the jwSMTP library.
|
||||
//
|
||||
// jwSMTP library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; version 2 of the License.
|
||||
//
|
||||
// jwSMTP library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with jwSMTP library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// jwSMTP library
|
||||
// http://johnwiggins.net
|
||||
// smtplib@johnwiggins.net
|
||||
//
|
||||
// base64.h: base64 encoding functions
|
||||
//
|
||||
|
||||
#ifndef __BASE64_H__
|
||||
#define __BASE64_H__
|
||||
|
||||
namespace jwsmtp {
|
||||
|
||||
// added the B64 to all members of the enum for SunOS (thanks Ken Weinert)
|
||||
enum BASE64
|
||||
{
|
||||
B64_A, B64_B, B64_C, B64_D, B64_E, B64_F, B64_G, B64_H, B64_I, B64_J, B64_K, B64_L, B64_M, B64_N, B64_O, B64_P, B64_Q, B64_R, B64_S, B64_T, B64_U, B64_V, B64_W, B64_X, B64_Y, B64_Z,
|
||||
B64_a, B64_b, B64_c, B64_d, B64_e, B64_f, B64_g, B64_h, B64_i, B64_j, B64_k, B64_l, B64_m, B64_n, B64_o, B64_p, B64_q, B64_r, B64_s, B64_t, B64_u, B64_v, B64_w, B64_x, B64_y, B64_z,
|
||||
B64_0, B64_1, B64_2, B64_3, B64_4, B64_5, B64_6, B64_7, B64_8, B64_9, plus, slash, padding
|
||||
};
|
||||
|
||||
char getbase64character(const char& in);
|
||||
std::vector<char> base64encode(const std::vector<char>& input, const bool returns = true);
|
||||
std::string base64encode(const std::string& input, const bool returns = true);
|
||||
|
||||
} // end namespace jwsmtp
|
||||
|
||||
|
||||
#endif // #ifndef __BASE64_H__
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
// Note that the only valid version of the GPL as far as jwSMTP
|
||||
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
|
||||
// unless explicitly otherwise stated.
|
||||
//
|
||||
// This file is part of the jwSMTP library.
|
||||
//
|
||||
// jwSMTP library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; version 2 of the License.
|
||||
//
|
||||
// jwSMTP library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with jwSMTP library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// jwSMTP library
|
||||
// http://johnwiggins.net
|
||||
// smtplib@johnwiggins.net
|
||||
//
|
||||
|
||||
#include <string>
|
||||
#include "compat.h"
|
||||
|
||||
namespace jwsmtp {
|
||||
|
||||
bool Connect(SOCKET sockfd, const SOCKADDR_IN& addr) {
|
||||
#ifdef _WIN32
|
||||
return bool(connect(sockfd, (sockaddr*)&addr, addr.get_size()) != SOCKET_ERROR);
|
||||
#else
|
||||
return bool(connect(sockfd,
|
||||
const_cast<sockaddr *>(reinterpret_cast<const sockaddr*>(&addr)),
|
||||
addr.get_size()) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Socket(SOCKET& s, int /*domain*/, int type, int protocol) {
|
||||
s = socket(AF_INET, type, protocol);
|
||||
#ifdef _WIN32
|
||||
return bool(s != INVALID_SOCKET);
|
||||
#else
|
||||
return bool(s != -1);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Send(int &CharsSent, SOCKET s, const char *msg, size_t len, int flags) {
|
||||
CharsSent = send(s, msg, len, flags);
|
||||
#ifdef _WIN32
|
||||
return bool((CharsSent != SOCKET_ERROR));
|
||||
#else
|
||||
return bool((CharsSent != -1));
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Recv(int &CharsRecv, SOCKET s, char *buf, size_t len, int flags) {
|
||||
CharsRecv = recv(s, buf, len, flags);
|
||||
#ifdef _WIN32
|
||||
return bool((CharsRecv != SOCKET_ERROR));
|
||||
#else
|
||||
return bool((CharsRecv != -1));
|
||||
#endif
|
||||
}
|
||||
|
||||
// just wrap the call to shutdown the connection on a socket
|
||||
// this way I don't have to call it this way everywhere.
|
||||
void Closesocket(const SOCKET& s) {
|
||||
#ifdef _WIN32
|
||||
closesocket(s);
|
||||
#else
|
||||
close(s);
|
||||
#endif
|
||||
}
|
||||
|
||||
// This does nothing on unix.
|
||||
// for windoze only, to initialise networking, snore
|
||||
void initNetworking() {
|
||||
#ifdef _WIN32
|
||||
class socks
|
||||
{
|
||||
public:
|
||||
bool init() {
|
||||
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
|
||||
wVersionRequested = MAKEWORD( 2, 0 );
|
||||
int ret = WSAStartup( wVersionRequested, &wsaData);
|
||||
if(ret)
|
||||
return false;
|
||||
initialised = true;
|
||||
return true;
|
||||
}
|
||||
bool IsInitialised() const {return initialised;}
|
||||
socks():initialised(false){init();}
|
||||
~socks()
|
||||
{
|
||||
if(initialised)
|
||||
shutdown();
|
||||
}
|
||||
private:
|
||||
void shutdown(){WSACleanup();}
|
||||
bool initialised;
|
||||
};
|
||||
static socks s;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // end namespace jwsmtp
|
||||
|
|
@ -1,169 +0,0 @@
|
|||
// Note that the only valid version of the GPL as far as jwSMTP
|
||||
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
|
||||
// unless explicitly otherwise stated.
|
||||
//
|
||||
// This file is part of the jwSMTP library.
|
||||
//
|
||||
// jwSMTP library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; version 2 of the License.
|
||||
//
|
||||
// jwSMTP library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with jwSMTP library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// jwSMTP library
|
||||
// http://johnwiggins.net
|
||||
// smtplib@johnwiggins.net
|
||||
//
|
||||
|
||||
#ifndef __COMPAT_H__
|
||||
#define __COMPAT_H__
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifdef _MSC_VER
|
||||
# pragma warning( disable : 4786 )
|
||||
// tell the linker which libraries to find functions in
|
||||
# pragma comment(lib, "ws2_32.lib")
|
||||
# endif
|
||||
#include <winsock2.h>
|
||||
#else // assume some unix variant
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
typedef int SOCKET; // get round windows definitions.
|
||||
#endif
|
||||
|
||||
//windows:
|
||||
//struct sockaddr_in {
|
||||
// short sin_family;
|
||||
// unsigned short sin_port;
|
||||
// struct in_addr sin_addr;
|
||||
// char sin_zero[8];
|
||||
//};
|
||||
//
|
||||
//struct in_addr {
|
||||
// union {
|
||||
// struct{
|
||||
// unsigned char s_b1,
|
||||
// s_b2,
|
||||
// s_b3,
|
||||
// s_b4;
|
||||
// } S_un_b;
|
||||
// struct {
|
||||
// unsigned short s_w1,
|
||||
// s_w2;
|
||||
// } S_un_w;
|
||||
// unsigned long S_addr;
|
||||
// } S_un;
|
||||
//};
|
||||
//
|
||||
//struct sockaddr {
|
||||
// u_short sa_family;
|
||||
// char sa_data[14];
|
||||
//};
|
||||
|
||||
//linux:
|
||||
//struct sockaddr_in {
|
||||
// short int sin_family; /* AF_INET */
|
||||
// unsigned short int sin_port; /* Port number */
|
||||
// struct in_addr sin_addr; /* Internet address */
|
||||
//};
|
||||
//
|
||||
//struct in_addr {
|
||||
// unsigned long int s_addr;
|
||||
//};
|
||||
|
||||
namespace jwsmtp {
|
||||
|
||||
struct SOCKADDR_IN {
|
||||
sockaddr_in ADDR; // we are wrapping this structure.
|
||||
|
||||
// this is bad as we just assume that the address "addr" is valid here.
|
||||
// need a real check and set ok appropriately
|
||||
// SOCKADDR_IN(sockaddr_in addr):ADDR(addr), ok(true) {}
|
||||
|
||||
SOCKADDR_IN(const std::string& address, unsigned short port, short family = AF_INET)
|
||||
: ADDR()
|
||||
, ok(false)
|
||||
{
|
||||
ADDR.sin_port = port;
|
||||
ADDR.sin_family = family;
|
||||
#ifdef _WIN32
|
||||
ADDR.sin_addr.S_un.S_addr = inet_addr(address.c_str());
|
||||
ok = (ADDR.sin_addr.S_un.S_addr != INADDR_NONE);
|
||||
#else
|
||||
ok = (inet_aton(address.c_str(), &ADDR.sin_addr));
|
||||
#endif
|
||||
}
|
||||
|
||||
SOCKADDR_IN(const SOCKADDR_IN& addr)
|
||||
: ADDR(addr.ADDR)
|
||||
, ok(addr.ok)
|
||||
{
|
||||
}
|
||||
|
||||
SOCKADDR_IN operator = (const SOCKADDR_IN& addr) {
|
||||
ADDR = addr.ADDR;
|
||||
ok = addr.ok;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator bool() const {return ok;}
|
||||
|
||||
operator const sockaddr_in () const {
|
||||
return ADDR;
|
||||
}
|
||||
operator const sockaddr () const {
|
||||
sockaddr addr;
|
||||
std::copy(const_cast<char *>(reinterpret_cast<const char*>(&ADDR)),
|
||||
const_cast<char *>(reinterpret_cast<const char*>(&ADDR)) + sizeof(ADDR),
|
||||
reinterpret_cast<char*>(&addr));
|
||||
return addr;
|
||||
}
|
||||
|
||||
size_t get_size() const {return sizeof(ADDR);}
|
||||
char* get_sin_addr() {
|
||||
return reinterpret_cast<char*>(&ADDR.sin_addr);
|
||||
}
|
||||
void set_port(unsigned short newport) {ADDR.sin_port = newport;}
|
||||
void set_ip(const std::string& newip) {
|
||||
#ifdef _WIN32
|
||||
ADDR.sin_addr.S_un.S_addr = inet_addr(newip.c_str());
|
||||
ok = (ADDR.sin_addr.S_un.S_addr != INADDR_NONE);
|
||||
#else
|
||||
ok = (inet_aton(newip.c_str(), &ADDR.sin_addr));
|
||||
#endif
|
||||
}
|
||||
void zeroaddress() {
|
||||
#ifdef _WIN32
|
||||
ADDR.sin_addr.S_un.S_addr = 0;
|
||||
#else
|
||||
ADDR.sin_addr.s_addr = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
bool ok;
|
||||
};
|
||||
|
||||
bool Connect(SOCKET sockfd, const SOCKADDR_IN& addr);
|
||||
bool Socket(SOCKET& s, int domain, int type, int protocol);
|
||||
bool Send(int &CharsSent, SOCKET s, const char *msg, size_t len, int flags);
|
||||
bool Recv(int &CharsRecv, SOCKET s, char *buf, size_t len, int flags);
|
||||
void Closesocket(const SOCKET& s);
|
||||
void initNetworking();
|
||||
|
||||
} // end namespace jwsmtp
|
||||
|
||||
#endif // #ifndef __COMPAT_H__
|
||||
|
||||
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
// Note that the only valid version of the GPL as far as jwSMTP
|
||||
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
|
||||
// unless explicitly otherwise stated.
|
||||
//
|
||||
// This file is part of the jwSMTP library.
|
||||
//
|
||||
// jwSMTP library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; version 2 of the License.
|
||||
//
|
||||
// jwSMTP library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with jwSMTP library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// jwSMTP library
|
||||
// http://johnwiggins.net
|
||||
// smtplib@johnwiggins.net
|
||||
//
|
||||
|
||||
#ifndef __JWSMTP_H__
|
||||
#define __JWSMTP_H__
|
||||
|
||||
#include "mailer.h"
|
||||
#include "compat.h"
|
||||
#include "base64.h"
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -1,259 +0,0 @@
|
|||
// Note that the only valid version of the GPL as far as jwSMTP
|
||||
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
|
||||
// unless explicitly otherwise stated.
|
||||
//
|
||||
// This file is part of the jwSMTP library.
|
||||
//
|
||||
// jwSMTP library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; version 2 of the License.
|
||||
//
|
||||
// jwSMTP library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with jwSMTP library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// jwSMTP library
|
||||
// http://johnwiggins.net
|
||||
// smtplib@johnwiggins.net
|
||||
//
|
||||
#ifndef __MAILER_H__
|
||||
#define __MAILER_H__
|
||||
|
||||
#include <string>
|
||||
#include <string.h> //Edit: Included for strcpy()
|
||||
#include <vector>
|
||||
#include "compat.h"
|
||||
|
||||
namespace jwsmtp {
|
||||
|
||||
class mailer
|
||||
{
|
||||
public:
|
||||
// if MXLookup is true:
|
||||
// 'server' is a nameserver to lookup an MX record by.
|
||||
// if MXLookup is false.
|
||||
// 'server' is an SMTP server which will be attempted directly for mailing
|
||||
// if an IP address is not found, either MX record or direct to SMTP server,
|
||||
// an attempt will be made to send mail directly to the server in the mail address.
|
||||
// e.g. mail to fred@somewhere.com will have a connection attempt made directly to:
|
||||
// somewhere.com (which is probably wrong and therefore will still fail)
|
||||
mailer(const char* TOaddress, const char* FROMaddress,
|
||||
const char* Subject, const std::vector<char>& Message,
|
||||
const char* server = "127.0.0.1"/*default to localhost*/,
|
||||
unsigned short Port = SMTP_PORT, // default SMTP port
|
||||
bool MXLookup = true);
|
||||
|
||||
mailer(const char* TOaddress, const char* FROMaddress,
|
||||
const char* Subject, const char* Message,
|
||||
const char* server = "127.0.0.1"/*default to localhost*/,
|
||||
unsigned short Port = SMTP_PORT, // default SMTP port
|
||||
bool MXLookup = true);
|
||||
|
||||
// defaults to SMTP_PORT & no MX lookup.
|
||||
// now we can do:
|
||||
// mailer m; // mail an smtp server direct.
|
||||
// mailer m2(true); // use MX lookup.
|
||||
// mailer m2(false, weirdportnumber); // SMTP to a non standard port.
|
||||
mailer(bool MXLookup = false, unsigned short Port = SMTP_PORT);
|
||||
|
||||
~mailer();
|
||||
|
||||
// call this operator to have the mail mailed.
|
||||
// This is to facilitate using multiple threads
|
||||
// i.e. using boost::thread. (see http://www.boost.org)
|
||||
//
|
||||
// e.g.
|
||||
// mailer mail(args...);
|
||||
// boost::thread thrd(mail); // operator()() implicitly called.
|
||||
// thrd.join(); // if needed.
|
||||
//
|
||||
// or:
|
||||
// mailer mail(args...);
|
||||
// mail.operator()();
|
||||
void operator()();
|
||||
void send();
|
||||
|
||||
// attach a file to the mail. (MIME 1.0)
|
||||
// returns false if !filename.length() or
|
||||
// the file could not be opened for reading...etc.
|
||||
bool attach(const std::string& filename);
|
||||
|
||||
// remove an attachment from the list of attachments.
|
||||
// returns false if !filename.length() or
|
||||
// the file is not attached or there are no attachments.
|
||||
bool removeattachment(const std::string& filename);
|
||||
|
||||
// Set a new message (replacing the old)
|
||||
// will return false and not change the message if newmessage is empty.
|
||||
bool setmessage(const std::string& newmessage);
|
||||
bool setmessage(const std::vector<char>& newmessage);
|
||||
|
||||
// Set a new HTML message (replacing the old)
|
||||
// will return false and not change the message if newmessage is empty.
|
||||
bool setmessageHTML(const std::string& newmessage);
|
||||
bool setmessageHTML(const std::vector<char>& newmessage);
|
||||
// use a file for the data
|
||||
bool setmessageHTMLfile(const std::string& filename);
|
||||
|
||||
// Set a new Subject for the mail (replacing the old)
|
||||
// will return false if newSubject is empty.
|
||||
bool setsubject(const std::string& newSubject);
|
||||
|
||||
// sets the nameserver or smtp server to connect to
|
||||
// dependant on the constructor call, i.e. whether
|
||||
// 'lookupMXRecord' was set to false or true.
|
||||
// (see constructor comment for details)
|
||||
bool setserver(const std::string& nameserver_or_smtpserver);
|
||||
|
||||
// sets the senders address (fromAddress variable)
|
||||
bool setsender(const std::string& newsender);
|
||||
|
||||
// add a recipient to the recipient list. (maximum allowed recipients 100).
|
||||
// returns true if the address could be added to the
|
||||
// recipient list, otherwise false.
|
||||
// recipient_type must be in the range mailer::TO -> mailer::BCC if
|
||||
// not recipient_type defaults to BCC (blind copy), see const enum below.
|
||||
bool addrecipient(const std::string& newrecipient, short recipient_type = TO /*CC, BCC*/);
|
||||
|
||||
// remove a recipient from the recipient list.
|
||||
// returns true if the address could be removed from the
|
||||
// recipient list, otherwise false.
|
||||
bool removerecipient(const std::string& recipient);
|
||||
|
||||
// clear all recipients from the recipient list.
|
||||
void clearrecipients();
|
||||
|
||||
// clear all attachments from the mail.
|
||||
void clearattachments();
|
||||
|
||||
// clear all recipients, message, attachments, errors.
|
||||
// does not reset the name/smtp server (use setserver for this)
|
||||
// does not set the senders address (use setsender for this)
|
||||
void reset();
|
||||
|
||||
// returns the return code sent by the smtp server or a local error.
|
||||
// this is the only way to find if there is an error in processing.
|
||||
// if the mail is sent correctly this string will begin with 250
|
||||
// see smtp RFC 821 section 4.2.2 for response codes.
|
||||
const std::string& response() const;
|
||||
|
||||
// Constants
|
||||
// in unix we have to have a named object.
|
||||
const static enum {TO, Cc, Bcc, SMTP_PORT = 25, DNS_PORT = 53} consts;
|
||||
|
||||
// what type of authentication are we using.
|
||||
// (if using authentication that is).
|
||||
enum authtype {LOGIN = 1, PLAIN} type;
|
||||
|
||||
// set the authentication type
|
||||
// currently LOGIN or PLAIN only.
|
||||
// The default login type is LOGIN, set in the constructor
|
||||
void authtype(const enum authtype Type);
|
||||
|
||||
// set the username for authentication.
|
||||
// If this function is called with a non empty string
|
||||
// jwSMTP will try to use authentication.
|
||||
// To not use authentication after this, call again
|
||||
// with the empty string e.g.
|
||||
// mailerobject.username("");
|
||||
void username(const std::string& User);
|
||||
// set the password for authentication
|
||||
void password(const std::string& Pass);
|
||||
|
||||
private:
|
||||
// create a header with current message and attachments.
|
||||
std::vector<char> makesmtpmessage() const;
|
||||
|
||||
// this breaks a message line up to be less than 1000 chars per line.
|
||||
// keeps words intact also --- rfc821
|
||||
// Check line returns are in the form "\r\n"
|
||||
// (qmail balks otherwise, i.e. LAME server)
|
||||
// also if a period is on a line by itself add a period
|
||||
// stops prematurely ending the mail before whole message is sent.
|
||||
void checkRFCcompat();
|
||||
|
||||
// helper function.
|
||||
// returns the part of the string toaddress after the @ symbol.
|
||||
// i.e. the 'toaddress' is an email address eg. someone@somewhere.com
|
||||
// this function returns 'somewhere.com'
|
||||
std::string getserveraddress(const std::string& toaddress) const;
|
||||
|
||||
// Does the work of getting MX records for the server returned by 'getserveraddress'
|
||||
// will use the dns server passed to this's constructor in 'nameserver'
|
||||
// or if MXlookup is false in the constuctor, will return an address
|
||||
// for the server that 'getserveraddress' returns.
|
||||
// returns false on failure, true on success
|
||||
bool gethostaddresses(std::vector<SOCKADDR_IN>& adds);
|
||||
|
||||
// Parses a dns Resource Record (see TCP/IP illustrated, STEVENS, page 194)
|
||||
bool parseRR(int& pos, const unsigned char dns[], std::string& name, in_addr& address);
|
||||
|
||||
// Parses a dns name returned in a dns query (see TCP/IP illustrated, STEVENS, page 192)
|
||||
void parsename(int& pos, const unsigned char dns[], std::string& name);
|
||||
|
||||
// email address wrapper struct
|
||||
struct Address {
|
||||
|
||||
Address()
|
||||
: name()
|
||||
,address()
|
||||
{
|
||||
}
|
||||
|
||||
std::string name; // e.g. freddy foobar
|
||||
std::string address; // e.g. someone@mail.com
|
||||
};
|
||||
|
||||
// authenticate against a server.
|
||||
bool authenticate(const std::string& servergreeting, const SOCKET& s);
|
||||
|
||||
// less typing later, these are definately abominations!
|
||||
typedef std::vector<std::pair<std::vector<char>, std::string> >::const_iterator vec_pair_char_str_const_iter;
|
||||
typedef std::vector<std::pair<Address, short> >::const_iterator recipient_const_iter;
|
||||
typedef std::vector<std::pair<Address, short> >::iterator recipient_iter;
|
||||
typedef std::vector<std::string>::const_iterator vec_str_const_iter;
|
||||
|
||||
// split an address into its relevant parts i.e.
|
||||
// name and actual address and return it in Address.
|
||||
// this may be usefull out of the class maybe
|
||||
// it should be a static function or a global? thinking about it.
|
||||
Address parseaddress(const std::string& addresstoparse);
|
||||
|
||||
// The addresses to send the mail to
|
||||
std::vector<std::pair<Address, short> > recipients;
|
||||
// The address the mail is from.
|
||||
Address fromAddress;
|
||||
// Subject of the mail
|
||||
std::string subject;
|
||||
// The contents of the mail message
|
||||
std::vector<char> message;
|
||||
// The contents of the mail message in html format.
|
||||
std::vector<char> messageHTML;
|
||||
// attachments: the file as a stream of char's and the name of the file.
|
||||
std::vector<std::pair<std::vector<char>, std::string> > attachments;
|
||||
// This will be filled in from the toAddress by getserveraddress
|
||||
std::string server;
|
||||
// Name of a nameserver to query
|
||||
std::string nameserver;
|
||||
// The port to mail to on the smtp server.
|
||||
const unsigned short port;
|
||||
// use dns to query for MX records
|
||||
const bool lookupMXRecord;
|
||||
// using authentication
|
||||
bool auth;
|
||||
// username for authenticated smtp
|
||||
std::string user;
|
||||
// password for authenticated smtp
|
||||
std::string pass;
|
||||
// filled in with server return strings
|
||||
std::string returnstring;
|
||||
};
|
||||
|
||||
} // end namespace jwsmtp
|
||||
|
||||
#endif // !ifndef __MAILER_H__
|
|
@ -1,57 +0,0 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 - 2009 by Thomas Baumhauer <thomas.baumhauer@NOSPAMgmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "mail.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void mailer::load_mail_cfg(const config& c) {
|
||||
mail_cfg.from_address = c["from_address"].empty() ? "NOREPLY@wesnoth.org" : c["from_address"];
|
||||
mail_cfg.server = c["server"].empty() ? "127.0.0.1" : c["server"];
|
||||
|
||||
//"username" and "password" may stay empty
|
||||
mail_cfg.username = c["username"];
|
||||
mail_cfg.password = c["password"];
|
||||
|
||||
if(c["mail_port"].empty()) {
|
||||
mail_cfg.port = jwsmtp::mailer::SMTP_PORT;
|
||||
} else {
|
||||
try {
|
||||
mail_cfg.port = lexical_cast_default<unsigned short>(c["port"]);
|
||||
} catch (bad_lexical_cast) {
|
||||
std::cerr << "Bad lexical cast reading the 'port', using default port 25.\n";
|
||||
mail_cfg.port = jwsmtp::mailer::SMTP_PORT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool mailer::send_mail(const std::string& to_address, const std::string& subject, const std::string& message) {
|
||||
jwsmtp::mailer m(to_address.c_str(), mail_cfg.from_address.c_str(), subject.c_str(),
|
||||
message.c_str(), mail_cfg.server.c_str(), mail_cfg.port, false);
|
||||
|
||||
if(!(mail_cfg.username.empty())) {
|
||||
m.username(mail_cfg.username.c_str());
|
||||
m.password(mail_cfg.password.c_str());
|
||||
}
|
||||
|
||||
m.send();
|
||||
|
||||
std::cout << "Sent email to " << to_address << " with response '" << m.response() << "'\n";
|
||||
if(m.response().substr(0,3) != "250") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 - 2009 by Thomas Baumhauer <thomas.baumhauer@NOSPAMgmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef MAIL_HPP_INCLUDED
|
||||
#define MAIL_HPP_INCLUDED
|
||||
|
||||
#include "../global.hpp"
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "jwsmtp/jwsmtp.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
// The [mail] section in the server configuration
|
||||
// file could look like this:
|
||||
//
|
||||
//[mail]
|
||||
// server=localhost
|
||||
// username=user
|
||||
// password=secret
|
||||
// from_address=noreply@wesnoth.org
|
||||
//[/mail]
|
||||
|
||||
/**
|
||||
* A helper classe for sending email using the jwsmtp library.
|
||||
*/
|
||||
class mailer {
|
||||
public:
|
||||
mailer(const config& c) :
|
||||
mail_cfg()
|
||||
{
|
||||
load_mail_cfg(c);
|
||||
}
|
||||
|
||||
struct tmail_cfg {
|
||||
|
||||
tmail_cfg() :
|
||||
from_address(),
|
||||
server(),
|
||||
port(0),
|
||||
username(),
|
||||
password()
|
||||
{
|
||||
}
|
||||
|
||||
std::string from_address;
|
||||
std::string server;
|
||||
unsigned short port;
|
||||
std::string username;
|
||||
std::string password;
|
||||
};
|
||||
|
||||
tmail_cfg mail_cfg;
|
||||
|
||||
void load_mail_cfg(const config& c);
|
||||
bool send_mail(const std::string& to_address, const std::string& subject, const std::string& message);
|
||||
};
|
||||
|
||||
#endif //MAIL_HPP_INCLUDED
|
|
@ -13,8 +13,7 @@
|
|||
*/
|
||||
|
||||
#include "user_handler.hpp"
|
||||
|
||||
#include "mail.hpp"
|
||||
#include "../config.hpp"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
|
@ -31,23 +30,10 @@ bool user_handler::send_mail(const std::string& to_user,
|
|||
throw error("Could not send email. The email address of the user '" + to_user + "' is empty.");
|
||||
}
|
||||
|
||||
if(!mailer_) {
|
||||
throw user_handler::error("This server is configured not to send email.");
|
||||
}
|
||||
|
||||
if(!(mailer_->send_mail(get_mail(to_user), subject, message))) {
|
||||
throw user_handler::error("There was an error sending the email.");
|
||||
}
|
||||
|
||||
return true;
|
||||
throw user_handler::error("This server is configured not to send email.");
|
||||
}
|
||||
|
||||
void user_handler::init_mailer(const config &c) {
|
||||
if (c) {
|
||||
mailer_ = new mailer(c);
|
||||
} else {
|
||||
mailer_ = NULL;
|
||||
}
|
||||
void user_handler::init_mailer(const config &) {
|
||||
}
|
||||
|
||||
std::string user_handler::create_salt(int length) {
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
class config;
|
||||
|
||||
#include "mail.hpp"
|
||||
|
||||
#include "../global.hpp"
|
||||
|
||||
#include <string>
|
||||
|
@ -38,16 +36,11 @@ class user_handler {
|
|||
|
||||
public:
|
||||
user_handler()
|
||||
: mailer_(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~user_handler()
|
||||
{
|
||||
if(mailer_) {
|
||||
delete mailer_;
|
||||
mailer_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,8 +155,6 @@ class user_handler {
|
|||
* Should return an empty string when not used.
|
||||
*/
|
||||
virtual std::string get_mail(const std::string& user) =0;
|
||||
|
||||
mailer* mailer_;
|
||||
};
|
||||
|
||||
#endif //USER_HANDLER_HPP_INCLUDED
|
||||
|
|
Loading…
Add table
Reference in a new issue