* If USE_SSL is set when compiling the MDR add-ons, SSL will be used.

* By default, it will use a directory generated/cross-ssl where you need to
  unzip the optional openssl package into before. If you're on Haiku, you can
  use the SSL_DIR environment variable to point it to /boot/home/config
  instead.
* Fixed build with USE_SSL defined.
* Renamed USESSL to USE_SSL.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26971 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-08-14 12:28:44 +00:00
parent 6a5919034d
commit ad12e71861
9 changed files with 377 additions and 332 deletions
@@ -11,9 +11,14 @@ UsePrivateHeaders mail ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ; SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ;
if $(USESSL) { if $(USE_SSL) {
SubDirC++Flags -DUSESSL ; SubDirC++Flags -DUSE_SSL ;
SubDirHdrs [ FDirName / boot home config include ] ; if ! $(SSL_DIR) {
sslDir = [ FDirName $(HAIKU_OUTPUT_DIR) cross-ssl config ] ;
} else {
sslDir = $(SSL_DIR) ;
}
SubDirSysHdrs [ FDirName $(sslDir) include ] ;
} }
Addon IMAP : Addon IMAP :
@@ -23,8 +28,8 @@ Addon IMAP :
LinkAgainst IMAP : be libmail.so $(TARGET_NETWORK_LIBS) ; LinkAgainst IMAP : be libmail.so $(TARGET_NETWORK_LIBS) ;
if $(USESSL) { if $(USE_SSL) {
LinkAgainst IMAP : ssl crypto ; LinkAgainst IMAP : $(sslDir)/lib/libssl.so $(sslDir)/lib/libcrypto.so ;
} }
Package haiku-maildaemon-cvs : Package haiku-maildaemon-cvs :
@@ -1,3 +1,10 @@
/*
* Copyright 2007-2008, Haiku Inc. All Rights Reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
*
* Distributed under the terms of the MIT License.
*/
#include <RemoteStorageProtocol.h> #include <RemoteStorageProtocol.h>
#include <E-mail.h> #include <E-mail.h>
#include <netdb.h> #include <netdb.h>
@@ -22,13 +29,13 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/time.h> #include <sys/time.h>
#ifndef HAIKU_TARGET_PLATFORM_BEOS // These headers don't exist in BeOS R5. #ifndef HAIKU_TARGET_PLATFORM_BEOS // These headers don't exist in BeOS R5.
#include <arpa/inet.h> # include <arpa/inet.h>
#include <sys/select.h> # include <sys/select.h>
#endif #endif
#ifdef USESSL #ifdef USE_SSL
#include <openssl/ssl.h> # include <openssl/ssl.h>
#include <openssl/rand.h> # include <openssl/rand.h>
#endif #endif
#include "NestedString.h" #include "NestedString.h"
@@ -96,7 +103,7 @@ class IMAP4Client : public BRemoteMailStorageProtocol {
BList box_info; BList box_info;
status_t err; status_t err;
#ifdef USESSL #ifdef USE_SSL
SSL_CTX *ctx; SSL_CTX *ctx;
SSL *ssl; SSL *ssl;
BIO *sbio; BIO *sbio;
@@ -129,7 +136,7 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai
err = B_OK; err = B_OK;
mb_root = settings->FindString("root"); mb_root = settings->FindString("root");
#ifdef USESSL #ifdef USE_SSL
use_ssl = (settings->FindInt32("flavor") == 1); use_ssl = (settings->FindInt32("flavor") == 1);
ssl = NULL; ssl = NULL;
ctx = NULL; ctx = NULL;
@@ -138,7 +145,7 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai
int port = settings->FindInt32("port"); int port = settings->FindInt32("port");
if (port <= 0) if (port <= 0)
#ifdef USESSL #ifdef USE_SSL
port = use_ssl ? 993 : 143; port = use_ssl ? 993 : 143;
#else #else
port = 143; port = 143;
@@ -204,7 +211,7 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai
return; return;
} }
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) { if (use_ssl) {
SSL_library_init(); SSL_library_init();
SSL_load_error_strings(); SSL_load_error_strings();
@@ -288,7 +295,7 @@ IMAP4Client::~IMAP4Client() {
SendCommand("CLOSE"); SendCommand("CLOSE");
SendCommand("LOGOUT"); SendCommand("LOGOUT");
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) { if (use_ssl) {
if (ssl) if (ssl)
SSL_shutdown(ssl); SSL_shutdown(ssl);
@@ -439,7 +446,7 @@ status_t IMAP4Client::AddMessage(const char *mailbox, BPositionIO *data, BString
char *buffer = new char[size]; char *buffer = new char[size];
data->ReadAt(0,buffer,size); data->ReadAt(0,buffer,size);
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) { if (use_ssl) {
SSL_write(ssl,buffer,size); SSL_write(ssl,buffer,size);
SSL_write(ssl,"\r\n",2); SSL_write(ssl,"\r\n",2);
@@ -905,7 +912,7 @@ IMAP4Client::SendCommand(const char* command)
static char cmd[255]; static char cmd[255];
::sprintf(cmd,"a%.7ld %s"CRLF,++commandCount,command); ::sprintf(cmd,"a%.7ld %s"CRLF,++commandCount,command);
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) if (use_ssl)
SSL_write(ssl,cmd,strlen(cmd)); SSL_write(ssl,cmd,strlen(cmd));
else else
@@ -939,7 +946,7 @@ IMAP4Client::ReceiveLine(BString &out)
/* Set the socket in the mask. */ /* Set the socket in the mask. */
FD_SET(net, &fds); FD_SET(net, &fds);
int result; int result;
#ifdef USESSL #ifdef USE_SSL
if ((use_ssl) && (SSL_pending(ssl))) if ((use_ssl) && (SSL_pending(ssl)))
result = 1; result = 1;
else else
@@ -953,7 +960,7 @@ IMAP4Client::ReceiveLine(BString &out)
{ {
while(c != '\n' && c != xEOF) while(c != '\n' && c != xEOF)
{ {
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) if (use_ssl)
r = SSL_read(ssl,&c,1); r = SSL_read(ssl,&c,1);
else else
@@ -962,7 +969,7 @@ IMAP4Client::ReceiveLine(BString &out)
if(r <= 0) { if(r <= 0) {
BString error; BString error;
error << "Connection to " << settings->FindString("server") << " lost."; error << "Connection to " << settings->FindString("server") << " lost.";
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) { if (use_ssl) {
if (ssl) if (ssl)
SSL_shutdown(ssl); SSL_shutdown(ssl);
@@ -1019,7 +1026,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r
/* Set the socket in the mask. */ /* Set the socket in the mask. */
FD_SET(net, &fds); FD_SET(net, &fds);
#ifdef USESSL #ifdef USE_SSL
if ((use_ssl) && (SSL_pending(ssl))) if ((use_ssl) && (SSL_pending(ssl)))
result = 1; result = 1;
else else
@@ -1037,7 +1044,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r
{ {
while(c != '\n' && c != xEOF) while(c != '\n' && c != xEOF)
{ {
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) if (use_ssl)
r = SSL_read(ssl,&c,1); r = SSL_read(ssl,&c,1);
else else
@@ -1046,7 +1053,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r
if(r <= 0) { if(r <= 0) {
BString error; BString error;
error << "Connection to " << settings->FindString("server") << " lost."; error << "Connection to " << settings->FindString("server") << " lost.";
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) { if (use_ssl) {
if (ssl) if (ssl)
SSL_shutdown(ssl); SSL_shutdown(ssl);
@@ -1110,7 +1117,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r
int read_octets = 0; int read_octets = 0;
int nibble_size; int nibble_size;
while (read_octets < octets_to_read) { while (read_octets < octets_to_read) {
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) if (use_ssl)
nibble_size = SSL_read(ssl,buffer + read_octets,octets_to_read - read_octets); nibble_size = SSL_read(ssl,buffer + read_octets,octets_to_read - read_octets);
else else
@@ -1,8 +1,11 @@
/* IMAPConfig - config view for the IMAP protocol add-on /*
** * Copyright 2007-2008, Haiku Inc. All Rights Reserved.
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
*/ *
* Distributed under the terms of the MIT License.
*/
//! config view for the IMAP protocol add-on
#include <TextControl.h> #include <TextControl.h>
@@ -11,24 +14,29 @@
#include <MDRLanguage.h> #include <MDRLanguage.h>
class IMAPConfig : public BMailProtocolConfigView { class IMAPConfig : public BMailProtocolConfigView {
public: public:
IMAPConfig(BMessage *archive); IMAPConfig(BMessage *archive);
virtual ~IMAPConfig(); virtual ~IMAPConfig();
virtual status_t Archive(BMessage *into, bool deep = true) const; virtual status_t Archive(BMessage *into, bool deep = true) const;
virtual void GetPreferredSize(float *width, float *height); virtual void GetPreferredSize(float *width, float *height);
}; };
IMAPConfig::IMAPConfig(BMessage *archive) IMAPConfig::IMAPConfig(BMessage *archive)
: BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME | B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER : BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_USERNAME
#ifdef USESSL | B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME
| B_MAIL_PROTOCOL_HAS_FLAVORS) | B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER
#ifdef USE_SSL
| B_MAIL_PROTOCOL_HAS_FLAVORS
#endif
)
{ {
#ifdef USE_SSL
AddFlavor("No Encryption"); AddFlavor("No Encryption");
AddFlavor("SSL"); AddFlavor("SSL");
#else #endif
) {
#endif
SetTo(archive); SetTo(archive);
@@ -11,9 +11,16 @@ UsePrivateHeaders mail ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ; SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ;
if $(USESSL) { local sslDir ;
SubDirC++Flags -DUSESSL ;
SubDirHdrs [ FDirName / boot home config include ] ; if $(USE_SSL) {
SubDirC++Flags -DUSE_SSL ;
if ! $(SSL_DIR) {
sslDir = [ FDirName $(HAIKU_OUTPUT_DIR) cross-ssl config ] ;
} else {
sslDir = $(SSL_DIR) ;
}
SubDirSysHdrs [ FDirName $(sslDir) include ] ;
} }
Addon POP3 : Addon POP3 :
@@ -24,8 +31,8 @@ Addon POP3 :
LinkAgainst POP3 : be libmail.so $(TARGET_NETWORK_LIBS) ; LinkAgainst POP3 : be libmail.so $(TARGET_NETWORK_LIBS) ;
if $(USESSL) { if $(USE_SSL) {
LinkAgainst POP3 : ssl crypto ; LinkAgainst POP3 : $(sslDir)/lib/libssl.so $(sslDir)/lib/libcrypto.so ;
} }
Package haiku-maildaemon-cvs : Package haiku-maildaemon-cvs :
@@ -1,6 +1,6 @@
/* /*
* Copyright 2007-2008, Haiku Inc. All Rights Reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2007, Haiku Inc. All Rights Reserved.
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -19,16 +19,16 @@
#ifndef HAIKU_TARGET_PLATFORM_BEOS #ifndef HAIKU_TARGET_PLATFORM_BEOS
// These headers don't exist in BeOS R5. // These headers don't exist in BeOS R5.
#include <arpa/inet.h> # include <arpa/inet.h>
#include <sys/select.h> # include <sys/select.h>
#endif #endif
#if USESSL #if USE_SSL
#include <openssl/ssl.h> # include <openssl/ssl.h>
#include <openssl/rand.h> # include <openssl/rand.h>
#include <openssl/md5.h> # include <openssl/md5.h>
#else #else
#include "md5.h" # include "md5.h"
#endif #endif
#include <DataIO.h> #include <DataIO.h>
@@ -51,7 +51,7 @@ POP3Protocol::POP3Protocol(BMessage *settings, BMailChainRunner *status)
fNumMessages(-1), fNumMessages(-1),
fMailDropSize(0) fMailDropSize(0)
{ {
#ifdef USESSL #ifdef USE_SSL
fUseSSL = (settings->FindInt32("flavor") == 1); fUseSSL = (settings->FindInt32("flavor") == 1);
#endif #endif
Init(); Init();
@@ -60,12 +60,12 @@ POP3Protocol::POP3Protocol(BMessage *settings, BMailChainRunner *status)
POP3Protocol::~POP3Protocol() POP3Protocol::~POP3Protocol()
{ {
#ifdef USESSL #ifdef USE_SSL
if (!fUseSSL || fSSL) if (!fUseSSL || fSSL)
#endif #endif
SendCommand("QUIT" CRLF); SendCommand("QUIT" CRLF);
#ifdef USESSL #ifdef USE_SSL
if (fUseSSL) { if (fUseSSL) {
if (fSSL) if (fSSL)
SSL_shutdown(fSSL); SSL_shutdown(fSSL);
@@ -89,7 +89,7 @@ POP3Protocol::Open(const char *server, int port, int)
"POP3サーバに接続しています...")); "POP3サーバに接続しています..."));
if (port <= 0) { if (port <= 0) {
#ifdef USESSL #ifdef USE_SSL
port = fUseSSL ? 995 : 110; port = fUseSSL ? 995 : 110;
#else #else
port = 110; port = 110;
@@ -149,7 +149,7 @@ POP3Protocol::Open(const char *server, int port, int)
return B_ERROR; return B_ERROR;
} }
#ifdef USESSL #ifdef USE_SSL
if (fUseSSL) { if (fUseSSL) {
SSL_library_init(); SSL_library_init();
SSL_load_error_strings(); SSL_load_error_strings();
@@ -412,7 +412,7 @@ POP3Protocol::RetrieveInternal(const char *command, int32 message,
while (cont) { while (cont) {
int result = 0; int result = 0;
#ifdef USESSL #ifdef USE_SSL
if (fUseSSL && SSL_pending(fSSL)) if (fUseSSL && SSL_pending(fSSL))
result = 1; result = 1;
else else
@@ -426,7 +426,7 @@ POP3Protocol::RetrieveInternal(const char *command, int32 message,
} }
if (amountToReceive > bufSize - 1 - amountInBuffer) if (amountToReceive > bufSize - 1 - amountInBuffer)
amountToReceive = bufSize - 1 - amountInBuffer; amountToReceive = bufSize - 1 - amountInBuffer;
#ifdef USESSL #ifdef USE_SSL
if (fUseSSL) { if (fUseSSL) {
amountReceived = SSL_read(fSSL, buf + amountInBuffer, amountReceived = SSL_read(fSSL, buf + amountInBuffer,
amountToReceive); amountToReceive);
@@ -594,7 +594,7 @@ POP3Protocol::ReceiveLine(BString &line)
FD_SET(fSocket, &readSet); FD_SET(fSocket, &readSet);
int result; int result;
#ifdef USESSL #ifdef USE_SSL
if (fUseSSL && SSL_pending(fSSL)) if (fUseSSL && SSL_pending(fSSL))
result = 1; result = 1;
else else
@@ -606,7 +606,7 @@ POP3Protocol::ReceiveLine(BString &line)
// Hope there's an end of line out there else this gets stuck. // Hope there's an end of line out there else this gets stuck.
int32 bytesReceived; int32 bytesReceived;
uint8 c = 0; uint8 c = 0;
#ifdef USESSL #ifdef USE_SSL
if (fUseSSL) if (fUseSSL)
bytesReceived = SSL_read(fSSL, (char*)&c, 1); bytesReceived = SSL_read(fSSL, (char*)&c, 1);
else else
@@ -657,7 +657,7 @@ POP3Protocol::SendCommand(const char *cmd)
FD_ZERO(&readSet); FD_ZERO(&readSet);
FD_SET(fSocket, &readSet); FD_SET(fSocket, &readSet);
int result; int result;
#ifdef USESSL #ifdef USE_SSL
if (fUseSSL && SSL_pending(fSSL)) if (fUseSSL && SSL_pending(fSSL))
result = 1; result = 1;
else else
@@ -667,7 +667,7 @@ POP3Protocol::SendCommand(const char *cmd)
if (result > 0) { if (result > 0) {
int amountReceived; int amountReceived;
char tempString [1025]; char tempString [1025];
#ifdef USESSL #ifdef USE_SSL
if (fUseSSL) if (fUseSSL)
amountReceived = SSL_read(fSSL, tempString, sizeof(tempString) - 1); amountReceived = SSL_read(fSSL, tempString, sizeof(tempString) - 1);
else else
@@ -683,7 +683,7 @@ POP3Protocol::SendCommand(const char *cmd)
// break; // break;
} }
#ifdef USESSL #ifdef USE_SSL
if (fUseSSL) { if (fUseSSL) {
SSL_write(fSSL, cmd,::strlen(cmd)); SSL_write(fSSL, cmd,::strlen(cmd));
} else } else
@@ -726,7 +726,7 @@ POP3Protocol::MD5Digest(unsigned char *in, char *asciiDigest)
{ {
unsigned char digest[16]; unsigned char digest[16];
#ifdef USESSL #ifdef USE_SSL
MD5(in, ::strlen((char*)in), digest); MD5(in, ::strlen((char*)in), digest);
#else #else
MD5_CTX context; MD5_CTX context;
@@ -761,14 +761,14 @@ instantiate_config_panel(BMessage *settings, BMessage *)
B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_AUTH_METHODS B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_AUTH_METHODS
| B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME | B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME
| B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER | B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER
#if USESSL #if USE_SSL
| B_MAIL_PROTOCOL_HAS_FLAVORS | B_MAIL_PROTOCOL_HAS_FLAVORS
#endif #endif
); );
view->AddAuthMethod("Plain Text"); view->AddAuthMethod("Plain Text");
view->AddAuthMethod("APOP"); view->AddAuthMethod("APOP");
#if USESSL #if USE_SSL
view->AddFlavor("No Encryption"); view->AddFlavor("No Encryption");
view->AddFlavor("SSL"); view->AddFlavor("SSL");
#endif #endif
@@ -1,6 +1,6 @@
/* /*
* Copyright 2007-2008, Haiku Inc. All Rights Reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2007, Haiku Inc. All Rights Reserved.
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -10,6 +10,10 @@
#include <map> #include <map>
#ifdef USE_SSL
# include <openssl/ssl.h>
#endif
#include <List.h> #include <List.h>
#include <String.h> #include <String.h>
@@ -47,7 +51,7 @@ private:
size_t fMailDropSize; size_t fMailDropSize;
BList fSizes; BList fSizes;
#ifdef USESSL #ifdef USE_SSL
SSL_CTX* fSSLContext; SSL_CTX* fSSLContext;
SSL* fSSL; SSL* fSSL;
BIO* fSSLBio; BIO* fSSLBio;
@@ -11,9 +11,14 @@ UsePrivateHeaders mail ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ; SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ;
if $(USESSL) { if $(USE_SSL) {
SubDirC++Flags -DUSESSL ; SubDirC++Flags -DUSE_SSL ;
SubDirHdrs [ FDirName / boot home config include ] ; if ! $(SSL_DIR) {
sslDir = [ FDirName $(HAIKU_OUTPUT_DIR) cross-ssl config ] ;
} else {
sslDir = $(SSL_DIR) ;
}
SubDirSysHdrs [ FDirName $(sslDir) include ] ;
} }
Addon SMTP : Addon SMTP :
@@ -22,8 +27,8 @@ Addon SMTP :
LinkAgainst SMTP : be libmail.so $(TARGET_NETWORK_LIBS) ; LinkAgainst SMTP : be libmail.so $(TARGET_NETWORK_LIBS) ;
if $(USESSL) { if $(USE_SSL) {
LinkAgainst SMTP : ssl crypto ; LinkAgainst SMTP : $(sslDir)/lib/libssl.so $(sslDir)/lib/libcrypto.so ;
} }
Package haiku-maildaemon-cvs : Package haiku-maildaemon-cvs :
@@ -1,7 +1,11 @@
/* SMTPProtocol - implementation of the SMTP protocol /*
** * Copyright 2007-2008, Haiku Inc. All Rights Reserved.
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
*/ *
* Distributed under the terms of the MIT License.
*/
//! implementation of the SMTP protocol
#include <DataIO.h> #include <DataIO.h>
#include <Message.h> #include <Message.h>
@@ -19,8 +23,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>
#ifndef HAIKU_TARGET_PLATFORM_BEOS // These headers don't exist in BeOS R5. #ifndef HAIKU_TARGET_PLATFORM_BEOS // These headers don't exist in BeOS R5.
#include <arpa/inet.h> # include <arpa/inet.h>
#include <sys/select.h> # include <sys/select.h>
#endif #endif
#include <status.h> #include <status.h>
@@ -34,8 +38,10 @@
#include <map> #include <map>
#include "smtp.h" #include "smtp.h"
#ifndef USESSL #ifdef USE_SSL
#include "md5.h" # include <openssl/md5.h>
#else
# include "md5.h"
#endif #endif
#include <MDRLanguage.h> #include <MDRLanguage.h>
@@ -350,14 +356,14 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp)
{ {
runner->ReportProgress(0, 0, MDR_DIALECT_CHOICE ("Connecting to server...","接続中...")); runner->ReportProgress(0, 0, MDR_DIALECT_CHOICE ("Connecting to server...","接続中..."));
#ifdef USESSL #ifdef USE_SSL
use_ssl = (fSettings->FindInt32("flavor") == 1); use_ssl = (fSettings->FindInt32("flavor") == 1);
ssl = NULL; ssl = NULL;
ctx = NULL; ctx = NULL;
#endif #endif
if (port <= 0) if (port <= 0)
#ifdef USESSL #ifdef USE_SSL
port = use_ssl ? 465 : 25; port = use_ssl ? 465 : 25;
#else #else
port = 25; port = 25;
@@ -397,7 +403,7 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp)
return errno; return errno;
} }
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) { if (use_ssl) {
SSL_library_init(); SSL_library_init();
SSL_load_error_strings(); SSL_load_error_strings();
@@ -749,7 +755,7 @@ SMTPProtocol::Close()
// Error // Error
} }
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) { if (use_ssl) {
if (ssl) if (ssl)
SSL_shutdown(ssl); SSL_shutdown(ssl);
@@ -844,7 +850,7 @@ SMTPProtocol::Send(const char *to, const char *from, BPositionIO *message)
if (data[i] == '\r' && data[i+1] == '\n' && data[i+2] == '.') { if (data[i] == '\r' && data[i+1] == '\n' && data[i+2] == '.') {
foundCRLFPeriod = true; foundCRLFPeriod = true;
// Send data up to the CRLF, and include the period too. // Send data up to the CRLF, and include the period too.
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) { if (use_ssl) {
if (SSL_write(ssl,data,i + 3) < 0) { if (SSL_write(ssl,data,i + 3) < 0) {
amountUnread = 0; // Stop when an error happens. amountUnread = 0; // Stop when an error happens.
@@ -870,7 +876,7 @@ SMTPProtocol::Send(const char *to, const char *from, BPositionIO *message)
if (!foundCRLFPeriod) { if (!foundCRLFPeriod) {
if (amountUnread <= 0) { // No more data, all we have is in the buffer. if (amountUnread <= 0) { // No more data, all we have is in the buffer.
if (bufferLen > 0) { if (bufferLen > 0) {
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) if (use_ssl)
SSL_write(ssl,data,bufferLen); SSL_write(ssl,data,bufferLen);
else else
@@ -887,7 +893,7 @@ SMTPProtocol::Send(const char *to, const char *from, BPositionIO *message)
// Send most of the buffer, except a few characters to overlap with // Send most of the buffer, except a few characters to overlap with
// the next read, in case the CRLFPeriod is split between reads. // the next read, in case the CRLFPeriod is split between reads.
if (bufferLen > 3) { if (bufferLen > 3) {
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) { if (use_ssl) {
if (SSL_write(ssl,data,bufferLen - 3) < 0) if (SSL_write(ssl,data,bufferLen - 3) < 0)
break; break;
@@ -940,7 +946,7 @@ SMTPProtocol::ReceiveResponse(BString &out)
/* Set the socket in the mask. */ /* Set the socket in the mask. */
FD_SET(_fd, &fds); FD_SET(_fd, &fds);
int result = -1; int result = -1;
#ifdef USESSL #ifdef USE_SSL
if ((use_ssl) && (SSL_pending(ssl))) if ((use_ssl) && (SSL_pending(ssl)))
result = 1; result = 1;
else else
@@ -951,7 +957,7 @@ SMTPProtocol::ReceiveResponse(BString &out)
if (result > 0) { if (result > 0) {
while (1) { while (1) {
#ifdef USESSL #ifdef USE_SSL
if (use_ssl) if (use_ssl)
r = SSL_read(ssl,buf,SMTP_RESPONSE_SIZE - 1); r = SSL_read(ssl,buf,SMTP_RESPONSE_SIZE - 1);
else else
@@ -991,7 +997,7 @@ SMTPProtocol::SendCommand(const char *cmd)
{ {
D(bug("C:%s\n", cmd)); D(bug("C:%s\n", cmd));
#ifdef USESSL #ifdef USE_SSL
if (use_ssl && ssl) { if (use_ssl && ssl) {
if (SSL_write(ssl,cmd,::strlen(cmd)) < 0) if (SSL_write(ssl,cmd,::strlen(cmd)) < 0)
return B_ERROR; return B_ERROR;
@@ -1039,7 +1045,7 @@ instantiate_mailfilter(BMessage *settings, BMailChainRunner *status)
BView * BView *
instantiate_config_panel(BMessage *settings, BMessage *) instantiate_config_panel(BMessage *settings, BMessage *)
{ {
#ifdef USESSL #ifdef USE_SSL
BMailProtocolConfigView *view = new BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS | BMailProtocolConfigView *view = new BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS |
B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_USERNAME |
B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_PASSWORD |
@@ -1,20 +1,23 @@
/*
* Copyright 2007-2008, Haiku Inc. All Rights Reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
*
* Distributed under the terms of the MIT License.
*/
#ifndef ZOIDBERG_SMTP_H #ifndef ZOIDBERG_SMTP_H
#define ZOIDBERG_SMTP_H #define ZOIDBERG_SMTP_H
/* SMTPProtocol - implementation of the SMTP protocol
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
#include <String.h> #include <String.h>
#include <MailAddon.h> #include <MailAddon.h>
#ifdef USESSL #ifdef USE_SSL
#include <openssl/ssl.h> # include <openssl/ssl.h>
#include <openssl/rand.h> # include <openssl/rand.h>
#endif #endif
class SMTPProtocol : public BMailFilter { class SMTPProtocol : public BMailFilter {
public: public:
SMTPProtocol(BMessage *message, BMailChainRunner *runner); SMTPProtocol(BMessage *message, BMailChainRunner *runner);
@@ -42,13 +45,13 @@ class SMTPProtocol : public BMailFilter {
BMailChainRunner *runner; BMailChainRunner *runner;
int32 fAuthType; int32 fAuthType;
#ifdef USESSL #ifdef USE_SSL
SSL_CTX *ctx; SSL_CTX *ctx;
SSL *ssl; SSL *ssl;
BIO *sbio; BIO *sbio;
bool use_ssl; bool use_ssl;
#endif #endif
status_t fStatus; status_t fStatus;
BString fServerName; // required for DIGEST-MD5 BString fServerName; // required for DIGEST-MD5