diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile b/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile index 6e4b45eeda..bd86b6dcac 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile @@ -11,9 +11,14 @@ UsePrivateHeaders mail ; SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ; -if $(USESSL) { - 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 IMAP : @@ -23,10 +28,10 @@ Addon IMAP : LinkAgainst IMAP : be libmail.so $(TARGET_NETWORK_LIBS) ; -if $(USESSL) { - LinkAgainst IMAP : ssl crypto ; +if $(USE_SSL) { + LinkAgainst IMAP : $(sslDir)/lib/libssl.so $(sslDir)/lib/libcrypto.so ; } Package haiku-maildaemon-cvs : - IMAP : + IMAP : boot home config add-ons mail_daemon inbound_protocols ; diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_client.cpp b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_client.cpp index f699b9889a..85f7c4168c 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_client.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_client.cpp @@ -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 #include #include @@ -22,13 +29,13 @@ #include #include #ifndef HAIKU_TARGET_PLATFORM_BEOS // These headers don't exist in BeOS R5. - #include - #include +# include +# include #endif -#ifdef USESSL - #include - #include +#ifdef USE_SSL +# include +# include #endif #include "NestedString.h" @@ -51,13 +58,13 @@ class IMAP4Client : public BRemoteMailStorageProtocol { public: IMAP4Client(BMessage *settings, BMailChainRunner *run); virtual ~IMAP4Client(); - + virtual status_t GetMessage(const char *mailbox, const char *message, BPositionIO **, BMessage *headers); virtual status_t AddMessage(const char *mailbox, BPositionIO *data, BString *id); - + virtual status_t DeleteMessage(const char *mailbox, const char *message); virtual status_t CopyMessage(const char *mailbox, const char *to_mailbox, BString *message); - + virtual status_t CreateMailbox(const char *mailbox); virtual status_t DeleteMailbox(const char *mailbox); @@ -67,43 +74,43 @@ class IMAP4Client : public BRemoteMailStorageProtocol { BPath* out_folder_location) { return BRemoteMailStorageProtocol::GetMessage(uid, out_file, out_headers, out_folder_location); } virtual status_t DeleteMessage(const char* uid) { return BRemoteMailStorageProtocol::DeleteMessage(uid); } - + void GetUniqueIDs(); - + status_t ReceiveLine(BString &out); status_t SendCommand(const char *command); - + status_t Select(const char *mb, bool force_reselect = false, bool queue_new_messages = true, bool noop = true, bool no_command = false, bool ignore_forced_reselect = false); status_t Close(); - + virtual status_t InitCheck(BString *) { if (net < 0 && err == B_OK) return net; return err; } - + int GetResponse(BString &tag, NestedString *parsed_response, bool report_literals = false, bool recursion_flag = false); bool WasCommandOkay(BString &response); - + void InitializeMailboxes(); - + private: friend class NoopWorker; friend class IMAP4PartialReader; - + NoopWorker *noop; BMessageRunner *nooprunner; - + int32 commandCount; int net; BString selected_mb, inbox_name, hierarchy_delimiter, mb_root; BList box_info; status_t err; - - #ifdef USESSL + + #ifdef USE_SSL SSL_CTX *ctx; SSL *ssl; BIO *sbio; - + bool use_ssl; #endif - + bool force_reselect; }; @@ -113,10 +120,10 @@ class NoopWorker : public BHandler { void MessageReceived(BMessage *msg) { if (msg->what != 'impn' /* IMaP Noop */) return; - + if ((time(NULL) - last_run) < 9) return; - + us->Select(us->inbox_name.String()); last_run = time(NULL); } @@ -127,32 +134,32 @@ class NoopWorker : public BHandler { IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMailStorageProtocol(settings,run), noop(NULL), commandCount(0), net(-1), selected_mb(""), force_reselect(false) { err = B_OK; - + mb_root = settings->FindString("root"); - #ifdef USESSL + #ifdef USE_SSL use_ssl = (settings->FindInt32("flavor") == 1); ssl = NULL; ctx = NULL; #endif - + int port = settings->FindInt32("port"); - + if (port <= 0) - #ifdef USESSL + #ifdef USE_SSL port = use_ssl ? 993 : 143; #else port = 143; #endif -//-----Open TCP link +//-----Open TCP link runner->ReportProgress(0,0,MDR_DIALECT_CHOICE ("Opening connection...","接続中...")); - + uint32 hostIP = inet_addr(settings->FindString("server")); // first see if we can parse it as a numeric address if ((hostIP == 0)||(hostIP == (uint32)-1)) { struct hostent * he = gethostbyname(settings->FindString("server")); hostIP = he ? *((uint32*)he->h_addr) : 0; } - + if (hostIP == 0) { BString error; error << "Could not connect to IMAP server " << settings->FindString("server"); @@ -163,7 +170,7 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai runner->Stop(true); return; } - + #ifndef HAIKU_TARGET_PLATFORM_BEOS net = socket(AF_INET, SOCK_STREAM, 0); #else @@ -203,8 +210,8 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai runner->Stop(true); return; } - -#ifdef USESSL + +#ifdef USE_SSL if (use_ssl) { SSL_library_init(); SSL_load_error_strings(); @@ -212,12 +219,12 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai /*--- Because we're an add-on loaded at an unpredictable time, all the memory addresses and things contained in ourself are esssentially random. */ - + ctx = SSL_CTX_new(SSLv23_method()); ssl = SSL_new(ctx); sbio=BIO_new_socket(net,BIO_NOCLOSE); SSL_set_bio(ssl,sbio,sbio); - + if (SSL_connect(ssl) <= 0) { BString error; error << "Could not connect to IMAP server " << settings->FindString("server"); @@ -236,16 +243,16 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai return; } } - + #endif - + //-----Wait for welcome message BString response; ReceiveLine(response); //-----Log in runner->ReportProgress(0,0,MDR_DIALECT_CHOICE ("Authenticating...","認証中...")); - + const char *password = settings->FindString("password"); { char *passwd = get_passwd(settings,"cpasswd"); @@ -265,30 +272,30 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai runner->Stop(true); return; } - + runner->ReportProgress(0,0,"Logged in"); - + InitializeMailboxes(); GetUniqueIDs(); - + BStringList to_dl; unique_ids->NotThere(*manifest,&to_dl); - + noop = new NoopWorker(this); runner->AddHandler(noop); nooprunner = new BMessageRunner(BMessenger(noop,runner),new BMessage('impn'),10e6); - + if (to_dl.CountItems() > 0) runner->GetMessages(&to_dl,-1); } IMAP4Client::~IMAP4Client() { - if (net > 0) { + if (net > 0) { if (selected_mb != "") SendCommand("CLOSE"); SendCommand("LOGOUT"); - - #ifdef USESSL + + #ifdef USE_SSL if (use_ssl) { if (ssl) SSL_shutdown(ssl); @@ -296,7 +303,7 @@ IMAP4Client::~IMAP4Client() { SSL_CTX_free(ctx); } #endif - + #ifndef HAIKU_TARGET_PLATFORM_BEOS close(net); #else @@ -307,16 +314,16 @@ IMAP4Client::~IMAP4Client() { for (int32 i = 0; i < box_info.CountItems(); i++) delete (struct mailbox_info *)(box_info.ItemAt(i)); - + delete noop; } void IMAP4Client::InitializeMailboxes() { BString command; command << "LSUB \"" << mb_root << "\" \"*\""; - + SendCommand(command.String()); - + BString tag; char expected[255]; ::sprintf(expected,"a%.7ld",commandCount); @@ -328,10 +335,10 @@ void IMAP4Client::InitializeMailboxes() { val = GetResponse(tag,&response); if (val != NOT_COMMAND_RESPONSE) break; - + if (tag == expected) break; - + if (response[3]()[0] != '.') { struct mailbox_info *info = new struct mailbox_info; info->exists = -1; @@ -341,7 +348,7 @@ void IMAP4Client::InitializeMailboxes() { BString parsed_name = response[3](); if ((mb_root != "") && (strncmp(mb_root.String(),parsed_name.String(),mb_root.Length()) == 0)) parsed_name.Remove(0,mb_root.Length()); - + if (strcasecmp(response[2](),"NIL")) { hierarchy_delimiter = response[2](); if (strcmp(response[2](),"/")) { @@ -349,24 +356,24 @@ void IMAP4Client::InitializeMailboxes() { parsed_name.ReplaceAll('/','\\'); else parsed_name.ReplaceAll('/','-'); - + parsed_name.ReplaceAll(response[2](),"/"); } } if (parsed_name.ByteAt(0) == '/') parsed_name.Remove(0,1); - + mailboxes += parsed_name.String(); if (strcasecmp(parsed_name.String(),"INBOX") == 0) inbox_name = parsed_name; - + BPath blorp(path); blorp.Append(parsed_name.String()); create_directory(blorp.Path(),0777); } } while (1); - - + + if (hierarchy_delimiter == "" || hierarchy_delimiter == "NIL") { SendCommand("LIST \"\" \"\""); NestedString dem; @@ -375,8 +382,8 @@ void IMAP4Client::InitializeMailboxes() { if (hierarchy_delimiter == "" || hierarchy_delimiter == "NIL") hierarchy_delimiter = "/"; } - - if (mb_root.ByteAt(mb_root.Length() - 1) != hierarchy_delimiter.ByteAt(0)) { + + if (mb_root.ByteAt(mb_root.Length() - 1) != hierarchy_delimiter.ByteAt(0)) { command = "SELECT "; command << mb_root; SendCommand(command.String()); @@ -385,10 +392,10 @@ void IMAP4Client::InitializeMailboxes() { info->exists = -1; info->next_uid = -1; info->server_mb_name = mb_root; - + mailboxes += ""; box_info.AddItem(info); - + if (strcasecmp(mb_root.String(),"INBOX") == 0) inbox_name = ""; SendCommand("CLOSE"); @@ -403,21 +410,21 @@ void IMAP4Client::InitializeMailboxes() { status_t IMAP4Client::AddMessage(const char *mailbox, BPositionIO *data, BString *id) { Select(mailbox); //---Update info - + const int32 box_index = mailboxes.IndexOf(mailbox); char expected[255]; BString tag; - + BString command = "APPEND \""; off_t size; data->Seek(0,SEEK_END); size = data->Position(); - + BString attributes = "\\Seen"; - + { BNode *node = dynamic_cast(data); - + if (node != NULL) { BString status; node->ReadAttrString(B_MAIL_ATTR_STATUS,&status); @@ -429,68 +436,68 @@ status_t IMAP4Client::AddMessage(const char *mailbox, BPositionIO *data, BString attributes += " \\Answered"; } } - - + + command << ((struct mailbox_info *)(box_info.ItemAt(box_index)))->server_mb_name << "\" (" << attributes << ") {" << size << '}'; SendCommand(command.String()); status_t err = ReceiveLine(command); if (err < B_OK) return err; - + char *buffer = new char[size]; data->ReadAt(0,buffer,size); -#ifdef USESSL +#ifdef USE_SSL if (use_ssl) { SSL_write(ssl,buffer,size); SSL_write(ssl,"\r\n",2); - } else + } else #endif { send(net,buffer,size,0); send(net,"\r\n",2,0); } Select(mailbox,false,false,false,true); - + if (((struct mailbox_info *)(box_info.ItemAt(box_index)))->next_uid <= 0) { command = "FETCH "; command << ((struct mailbox_info *)(box_info.ItemAt(box_index)))->exists << " UID"; - + SendCommand(command.String()); ::sprintf(expected,"a%.7ld",commandCount); *id = ""; while (1) { NestedString response; GetResponse(tag,&response); - + if (tag == expected) break; - + *id = response[2][1](); } } else { *id = ""; *id << (((struct mailbox_info *)(box_info.ItemAt(box_index)))->next_uid - 1); } - + return B_OK; } status_t IMAP4Client::DeleteMessage(const char *mailbox, const char *message) { BString command = "UID STORE "; command << message << " +FLAGS.SILENT (\\Deleted)"; - + if (Select(mailbox,false,true,true,false,true) < B_OK) return B_ERROR; - + SendCommand(command.String()); if (!WasCommandOkay(command)) { command.Prepend("Error while deleting message: "); runner->ShowError(command.String()); return B_ERROR; } - + force_reselect = true; - + return B_OK; } @@ -498,44 +505,44 @@ status_t IMAP4Client::CopyMessage(const char *mailbox, const char *to_mailbox, B struct mailbox_info *to_mb = (struct mailbox_info *)(box_info.ItemAt(mailboxes.IndexOf(to_mailbox))); char expected[255]; BString tag; - + Select(mailbox); - + BString command = "UID COPY "; command << *message << " \"" << to_mb->server_mb_name << '\"'; SendCommand(command.String()); if (!WasCommandOkay(command)) return B_ERROR; - + Select(to_mailbox,false,false,true); //---Update mailbox info - + if (to_mb->next_uid <= 0) { command = "FETCH "; command << to_mb->exists << " UID"; - + SendCommand(command.String()); ::sprintf(expected,"a%.7ld",commandCount); *message = ""; while (1) { NestedString response; GetResponse(tag,&response); - + if (tag == expected) break; - + *message = response[2][1](); } } else { *message = ""; *message << (to_mb->next_uid - 1); } - + return B_OK; } status_t IMAP4Client::CreateMailbox(const char *mailbox) { Close(); - + struct mailbox_info *info = new struct mailbox_info; info->exists = -1; info->next_uid = -1; @@ -543,20 +550,20 @@ status_t IMAP4Client::CreateMailbox(const char *mailbox) { info->server_mb_name.ReplaceAll("/",hierarchy_delimiter.String()); if ((mb_root.ByteAt(mb_root.Length() - 1) != hierarchy_delimiter.ByteAt(0)) && (mb_root.Length() > 0)) info->server_mb_name.Prepend(hierarchy_delimiter); - + info->server_mb_name.Prepend(mb_root.String()); - + BString command; command << "CREATE \"" << info->server_mb_name << '\"'; SendCommand(command.String()); BString response; WasCommandOkay(response); //--- Deliberately ignore errors in the case of extant, but unsubscribed, mailboxes - + command = "SUBSCRIBE \""; command << info->server_mb_name << '\"'; SendCommand(command.String()); - + if (!WasCommandOkay(response)) { command = "Error creating mailbox "; command << mailbox << ". The server said: \n" << response << "\nThis may mean you can't create a new mailbox in this location."; @@ -564,40 +571,40 @@ status_t IMAP4Client::CreateMailbox(const char *mailbox) { delete info; return B_ERROR; } - + box_info.AddItem(info); - + return B_OK; } status_t IMAP4Client::DeleteMailbox(const char *mailbox) { Close(); - + if (!mailboxes.HasItem(mailbox)) return B_ERROR; - + BString command; - + command = "UNSUBSCRIBE \""; command << ((struct mailbox_info *)(box_info.ItemAt(mailboxes.IndexOf(mailbox))))->server_mb_name << '\"'; SendCommand(command.String()); WasCommandOkay(command); //---If this fails, that's fine. - + command = "DELETE \""; command << ((struct mailbox_info *)(box_info.ItemAt(mailboxes.IndexOf(mailbox))))->server_mb_name << '\"'; - + SendCommand(command.String()); if (!WasCommandOkay(command)) { command = "Error deleting mailbox "; command << mailbox << '.'; runner->ShowError(command.String()); - + return B_ERROR; } - + delete ((struct mailbox_info *)(box_info.RemoveItem(mailboxes.IndexOf(mailbox)))); - + return B_OK; } @@ -607,28 +614,28 @@ void IMAP4Client::GetUniqueIDs() { BString tag; BString uid; struct mailbox_info *info; - + runner->ReportProgress(0,0,"Getting Unique IDs"); - + for (int32 i = 0; i < mailboxes.CountItems(); i++) { Select(mailboxes[i],true,false /* We queue them as a group */); - + info = (struct mailbox_info *)(box_info.ItemAt(i)); if (info->exists <= 0) continue; - + command = "FETCH 1:"; command << info->exists << " UID"; - SendCommand(command.String()); - + SendCommand(command.String()); + ::sprintf(expected,"a%.7ld",commandCount); while(1) { NestedString response; GetResponse(tag,&response); - + if (tag == expected) break; - + uid = mailboxes[i]; uid << '/' << response[2][1](); unique_ids->AddItem(uid.String()); @@ -642,31 +649,31 @@ status_t IMAP4Client::Close() { SendCommand("CLOSE"); if (!WasCommandOkay(worthless)) return B_ERROR; - + selected_mb = ""; } - + return B_OK; } status_t IMAP4Client::Select(const char *mb, bool reselect, bool queue_new_messages, bool noop, bool no_command, bool ignore_forced_reselect) { if (net < 0) return B_NO_INIT; - + if (force_reselect && !ignore_forced_reselect) { reselect = true; force_reselect = false; } - + if (reselect) Close(); - + struct mailbox_info *info = (struct mailbox_info *)(box_info.ItemAt(mailboxes.IndexOf(mb))); if (info == NULL) return B_NAME_NOT_FOUND; const char *real_mb = info->server_mb_name.String(); - + if ((selected_mb != real_mb) || (noop) || (no_command)) { if ((selected_mb != "") && (selected_mb != real_mb)){ BString trash; @@ -680,35 +687,35 @@ status_t IMAP4Client::Select(const char *mb, bool reselect, bool queue_new_messa cmd = "NOOP"; else cmd << "SELECT \"" << real_mb << '\"'; - + if (!no_command) if (SendCommand(cmd.String()) < B_OK) return B_ERROR; - + char expected[255]; BString tag; ::sprintf(expected,"a%.7ld",commandCount); - + int32 new_exists(-1), new_next_uid(-1), recent(-1); - + while(1) { NestedString response; if (GetResponse(tag,&response) < B_OK) return B_ERROR; - + if (tag == expected) break; - + if ((response.CountItems() > 1) && (strcasecmp(response[1](),"EXISTS") == 0)) new_exists = atoi(response[0]()); - + if (response[0].CountItems() == 2 && strcasecmp(response[0][0](),"UIDNEXT") == 0) new_next_uid = atol(response[0][1]()); - + if ((response.CountItems() > 1) && (strcasecmp(response[1](),"RECENT") == 0)) recent = atoi(response[0]()); } - + if ((queue_new_messages) && (recent > 0)) { BString command = "FETCH "; command << new_exists - recent + 1 << ':' << new_exists << " UID"; @@ -720,31 +727,31 @@ status_t IMAP4Client::Select(const char *mb, bool reselect, bool queue_new_messa NestedString response; if (GetResponse(tag,&response) < 0) return B_ERROR; - + if (tag == expected) break; - + if (strcmp(response[2][0](),"UID") != 0) continue; //--- Courier IMAP blows. Hard. - + uid = mb; uid << '/' << response[2][1](); if (!unique_ids->HasItem(uid.String())) list.AddItem(uid.String()); } - + if (list.CountItems() > 0) { (*unique_ids) += list; runner->GetMessages(&list,-1); } } - + info->exists = new_exists; info->next_uid = new_next_uid; - + selected_mb = real_mb; } - + return B_OK; } @@ -757,7 +764,7 @@ class IMAP4PartialReader : public BPositionIO { delete slave; us->runner->ReportProgress(0,1); } - off_t Seek(off_t position, uint32 seek_mode) { + off_t Seek(off_t position, uint32 seek_mode) { if (seek_mode == SEEK_END) { if (!done) { slave->Seek(0,SEEK_END); @@ -792,9 +799,9 @@ class IMAP4PartialReader : public BPositionIO { NestedString response; if (us->GetResponse(command,&response) != NOT_COMMAND_RESPONSE && command == cmd) return; - + //response.PrintToStream(); - + us->WasCommandOkay(command); for (int32 i = 0; (i+1) < response[2].CountItems(); i++) { if (strcmp(response[2][i](),part) == 0) { @@ -802,16 +809,16 @@ class IMAP4PartialReader : public BPositionIO { break; } } - + } - + IMAP4Client *us; char unique[25]; BPositionIO *slave; bool done; }; -status_t IMAP4Client::GetMessage(const char *mailbox, const char *message, BPositionIO **data, BMessage *headers) { +status_t IMAP4Client::GetMessage(const char *mailbox, const char *message, BPositionIO **data, BMessage *headers) { { //--- Error reporting for non-existant messages often simply doesn't exist. So we have to check first... BString uid = mailbox; @@ -823,21 +830,21 @@ status_t IMAP4Client::GetMessage(const char *mailbox, const char *message, BPosi return B_NAME_NOT_FOUND; } } - + Select(mailbox); - - if (headers->FindBool("ENTIRE_MESSAGE")) { + + if (headers->FindBool("ENTIRE_MESSAGE")) { BString command = "UID FETCH "; command << message << " (FLAGS RFC822)"; - + SendCommand(command.String()); static char cmd[255]; ::sprintf(cmd,"a%.7ld"CRLF,commandCount); NestedString response; - + if (GetResponse(command,&response,true) != NOT_COMMAND_RESPONSE && command == cmd) return B_ERROR; - + for (int32 i = 0; i < response[2][1].CountItems(); i++) { if (strcmp(response[2][1][i](),"\\Seen") == 0) { headers->AddString("STATUS","Read"); @@ -855,7 +862,7 @@ status_t IMAP4Client::GetMessage(const char *mailbox, const char *message, BPosi headers->AddString("STATUS","Replied"); } } - + WasCommandOkay(command); (*data)->WriteAt(0,response[2][5](),strlen(response[2][5]())); runner->ReportProgress(0,1); @@ -869,9 +876,9 @@ status_t IMAP4Client::GetMessage(const char *mailbox, const char *message, BPosi NestedString response; if (GetResponse(command,&response) != NOT_COMMAND_RESPONSE && command == cmd) return B_ERROR; - + WasCommandOkay(command); - + for (int32 i = 0; i < response[2].CountItems(); i++) { if (strcmp(response[2][i](),"RFC822.SIZE") == 0) { i++; @@ -891,7 +898,7 @@ status_t IMAP4Client::GetMessage(const char *mailbox, const char *message, BPosi (*data)->Write(response[2][i](),strlen(response[2][i]())); } } - + *data = new IMAP4PartialReader(this,*data,message); return B_OK; } @@ -902,10 +909,10 @@ IMAP4Client::SendCommand(const char* command) { if (net < 0) return B_ERROR; - + static char cmd[255]; ::sprintf(cmd,"a%.7ld %s"CRLF,++commandCount,command); -#ifdef USESSL +#ifdef USE_SSL if (use_ssl) SSL_write(ssl,cmd,strlen(cmd)); else @@ -913,7 +920,7 @@ IMAP4Client::SendCommand(const char* command) send(net,cmd,strlen(cmd),0); PRINT(("C: %s",cmd)); - + return B_OK; } @@ -922,38 +929,38 @@ IMAP4Client::ReceiveLine(BString &out) { if (net < 0) return net; - + uint8 c = 0; int32 len = 0,r; out = ""; - - struct timeval tv; - struct fd_set fds; - tv.tv_sec = long(kIMAP4ClientTimeout / 1e6); - tv.tv_usec = long(kIMAP4ClientTimeout-(tv.tv_sec * 1e6)); - - /* Initialize (clear) the socket mask. */ + struct timeval tv; + struct fd_set fds; + + tv.tv_sec = long(kIMAP4ClientTimeout / 1e6); + tv.tv_usec = long(kIMAP4ClientTimeout-(tv.tv_sec * 1e6)); + + /* Initialize (clear) the socket mask. */ FD_ZERO(&fds); - - /* Set the socket in the mask. */ + + /* Set the socket in the mask. */ FD_SET(net, &fds); int result; -#ifdef USESSL +#ifdef USE_SSL if ((use_ssl) && (SSL_pending(ssl))) result = 1; else #endif result = select(32, &fds, NULL, NULL, &tv); - + if (result < 0) return errno; - + if(result > 0) { while(c != '\n' && c != xEOF) { - #ifdef USESSL + #ifdef USE_SSL if (use_ssl) r = SSL_read(ssl,&c,1); else @@ -962,7 +969,7 @@ IMAP4Client::ReceiveLine(BString &out) if(r <= 0) { BString error; error << "Connection to " << settings->FindString("server") << " lost."; - #ifdef USESSL + #ifdef USE_SSL if (use_ssl) { if (ssl) SSL_shutdown(ssl); @@ -980,7 +987,7 @@ IMAP4Client::ReceiveLine(BString &out) runner->ShowError(error.String()); return -1; } - + out += (char)c; len += r; } @@ -997,7 +1004,7 @@ IMAP4Client::ReceiveLine(BString &out) int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool report_literals, bool internal_flag) { if (net < 0) return net; - + uint8 c = 0; int32 r; int8 delimiters_passed = internal_flag ? 2 : 0; @@ -1006,30 +1013,30 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r bool in_quote = false; bool was_cr = false; int result; - + { struct timeval tv; - struct fd_set fds; - - tv.tv_sec = long(kIMAP4ClientTimeout / 1e6); - tv.tv_usec = long(kIMAP4ClientTimeout-(tv.tv_sec * 1e6)); - - /* Initialize (clear) the socket mask. */ + struct fd_set fds; + + tv.tv_sec = long(kIMAP4ClientTimeout / 1e6); + tv.tv_usec = long(kIMAP4ClientTimeout-(tv.tv_sec * 1e6)); + + /* Initialize (clear) the socket mask. */ FD_ZERO(&fds); - - /* Set the socket in the mask. */ + + /* Set the socket in the mask. */ FD_SET(net, &fds); -#ifdef USESSL +#ifdef USE_SSL if ((use_ssl) && (SSL_pending(ssl))) result = 1; else #endif result = select(32, &fds, NULL, NULL, &tv); } - + if (result < 0) return errno; - + if (!internal_flag) PRINT(("S: ")); @@ -1037,7 +1044,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r { while(c != '\n' && c != xEOF) { -#ifdef USESSL +#ifdef USE_SSL if (use_ssl) r = SSL_read(ssl,&c,1); else @@ -1046,7 +1053,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r if(r <= 0) { BString error; error << "Connection to " << settings->FindString("server") << " lost."; - #ifdef USESSL + #ifdef USE_SSL if (use_ssl) { if (ssl) SSL_shutdown(ssl); @@ -1064,11 +1071,11 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r runner->ShowError(error.String()); return -1; } - + #if DEBUG putchar(c); #endif - + if ((isspace(c) || (internal_flag && (c == ')' || c == ']'))) && !in_quote) { if (delimiters_passed == 0) { tag = out; @@ -1077,7 +1084,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r continue; } if (delimiters_passed == 1) { - + if (out == "NO") answer = NO; else if (out == "BAD") @@ -1086,12 +1093,12 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r answer = OK; else if (parsed_response != NULL && out != "") *parsed_response += out; - + out = ""; delimiters_passed ++; continue; } - + if (c == '\r') { was_cr = true; continue; @@ -1110,7 +1117,7 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r int read_octets = 0; int nibble_size; while (read_octets < octets_to_read) { - #ifdef USESSL + #ifdef USE_SSL if (use_ssl) nibble_size = SSL_read(ssl,buffer + read_octets,octets_to_read - read_octets); else @@ -1120,32 +1127,32 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r if (report_literals) runner->ReportProgress(nibble_size,0); } - + if (parsed_response != NULL) parsed_response->AdoptAndAdd(buffer); else delete [] buffer; - + c = ' '; continue; } } - + if (internal_flag && (c == ')' || c == ']')) { if (parsed_response != NULL && out != "") (*parsed_response) += out; break; } - + was_cr = false; if (parsed_response != NULL && out != "") (*parsed_response) += out; out = ""; continue; } - + was_cr = false; - + if (c == '\"') { in_quote = !in_quote; continue; @@ -1153,12 +1160,12 @@ int IMAP4Client::GetResponse(BString &tag, NestedString *parsed_response, bool r if (c == '(' || c == '[') { if (parsed_response != NULL) (*parsed_response) += NULL; - + BString trash; GetResponse(trash,&((*parsed_response)[parsed_response->CountItems() - 1]),report_literals,true); continue; } - + out += (char)c; } }else{ @@ -1178,20 +1185,20 @@ bool IMAP4Client::WasCommandOkay(BString &response) { return false; } } while (response[0] == '*'); - + bool to_ret = false; static char cmd[255]; ::sprintf(cmd,"a%.7ld OK",commandCount); if (strncmp(response.String(),cmd,strlen(cmd)) == 0) to_ret = true; - + int32 i = response.FindFirst(' '); i = response.FindFirst(' ',i+1); response.Remove(0,i+1); response.ReplaceAll("\r\n","\n"); for (int32 i = response.Length()-1; response.String()[i] == '\n'; i--) response.Truncate(i); - + return to_ret; } diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_config.cpp b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_config.cpp index 645330b38a..59da1f31e7 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_config.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_config.cpp @@ -1,8 +1,11 @@ -/* IMAPConfig - config view for the IMAP protocol add-on -** -** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. -*/ +/* + * 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. + */ +//! config view for the IMAP protocol add-on #include @@ -11,48 +14,53 @@ #include + class IMAPConfig : public BMailProtocolConfigView { - public: - IMAPConfig(BMessage *archive); - virtual ~IMAPConfig(); - virtual status_t Archive(BMessage *into, bool deep = true) const; - virtual void GetPreferredSize(float *width, float *height); +public: + IMAPConfig(BMessage *archive); + virtual ~IMAPConfig(); + virtual status_t Archive(BMessage *into, bool deep = true) const; + virtual void GetPreferredSize(float *width, float *height); }; + 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 - #ifdef USESSL - | B_MAIL_PROTOCOL_HAS_FLAVORS) + : BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_USERNAME + | B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME + | B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER +#ifdef USE_SSL + | B_MAIL_PROTOCOL_HAS_FLAVORS +#endif + ) { +#ifdef USE_SSL AddFlavor("No Encryption"); AddFlavor("SSL"); - #else - ) { - #endif - +#endif + SetTo(archive); - + ((BControl *)(FindView("leave_mail_remote")))->SetValue(B_CONTROL_ON); ((BControl *)(FindView("leave_mail_remote")))->Hide(); - + BRect frame = FindView("delete_remote_when_local")->Frame(); - + ((BControl *)(FindView("delete_remote_when_local")))->SetEnabled(true); ((BControl *)(FindView("delete_remote_when_local")))->MoveBy(0,-25); - - + + frame.right -= 10;// FindView("pass")->Frame().right; /*frame.top += 10; frame.bottom += 10;*/ - + BTextControl *folder = new BTextControl(frame,"root","Top Mailbox Folder: ","",NULL); folder->SetDivider(be_plain_font->StringWidth("Top Mailbox Folder: ")); - + if (archive->HasString("root")) folder->SetText(archive->FindString("root")); - + AddChild(folder); - + ResizeToPreferred(); } @@ -60,12 +68,12 @@ IMAPConfig::~IMAPConfig() {} status_t IMAPConfig::Archive(BMessage *into, bool deep) const { BMailProtocolConfigView::Archive(into,deep); - + if (into->ReplaceString("root",((BTextControl *)(FindView("root")))->Text()) != B_OK) into->AddString("root",((BTextControl *)(FindView("root")))->Text()); - + into->PrintToStream(); - + return B_OK; } diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/Jamfile b/src/add-ons/mail_daemon/inbound_protocols/pop3/Jamfile index 2896f4c81a..994ba2fab8 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/pop3/Jamfile +++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/Jamfile @@ -11,9 +11,16 @@ UsePrivateHeaders mail ; SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ; -if $(USESSL) { - SubDirC++Flags -DUSESSL ; - SubDirHdrs [ FDirName / boot home config include ] ; +local sslDir ; + +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 : @@ -24,8 +31,8 @@ Addon POP3 : LinkAgainst POP3 : be libmail.so $(TARGET_NETWORK_LIBS) ; -if $(USESSL) { - LinkAgainst POP3 : ssl crypto ; +if $(USE_SSL) { + LinkAgainst POP3 : $(sslDir)/lib/libssl.so $(sslDir)/lib/libcrypto.so ; } Package haiku-maildaemon-cvs : diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp b/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp index 5471035374..0850e2eb32 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp @@ -1,6 +1,6 @@ -/* +/* + * Copyright 2007-2008, Haiku Inc. 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. */ @@ -19,16 +19,16 @@ #ifndef HAIKU_TARGET_PLATFORM_BEOS // These headers don't exist in BeOS R5. - #include - #include +# include +# include #endif -#if USESSL - #include - #include - #include +#if USE_SSL +# include +# include +# include #else - #include "md5.h" +# include "md5.h" #endif #include @@ -51,7 +51,7 @@ POP3Protocol::POP3Protocol(BMessage *settings, BMailChainRunner *status) fNumMessages(-1), fMailDropSize(0) { -#ifdef USESSL +#ifdef USE_SSL fUseSSL = (settings->FindInt32("flavor") == 1); #endif Init(); @@ -60,12 +60,12 @@ POP3Protocol::POP3Protocol(BMessage *settings, BMailChainRunner *status) POP3Protocol::~POP3Protocol() { -#ifdef USESSL +#ifdef USE_SSL if (!fUseSSL || fSSL) #endif SendCommand("QUIT" CRLF); -#ifdef USESSL +#ifdef USE_SSL if (fUseSSL) { if (fSSL) SSL_shutdown(fSSL); @@ -76,7 +76,7 @@ POP3Protocol::~POP3Protocol() #ifndef HAIKU_TARGET_PLATFORM_BEOS close(fSocket); -#else +#else closesocket(fSocket); #endif } @@ -89,7 +89,7 @@ POP3Protocol::Open(const char *server, int port, int) "POP3サーバに接続しています...")); if (port <= 0) { -#ifdef USESSL +#ifdef USE_SSL port = fUseSSL ? 995 : 110; #else port = 110; @@ -149,7 +149,7 @@ POP3Protocol::Open(const char *server, int port, int) return B_ERROR; } -#ifdef USESSL +#ifdef USE_SSL if (fUseSSL) { SSL_library_init(); SSL_load_error_strings(); @@ -400,7 +400,7 @@ POP3Protocol::RetrieveInternal(const char *command, int32 message, if (SendCommand(command) != B_OK) return B_ERROR; - + struct timeval tv; tv.tv_sec = POP3_RETRIEVAL_TIMEOUT / 1000000; tv.tv_usec = POP3_RETRIEVAL_TIMEOUT % 1000000; @@ -412,7 +412,7 @@ POP3Protocol::RetrieveInternal(const char *command, int32 message, while (cont) { int result = 0; -#ifdef USESSL +#ifdef USE_SSL if (fUseSSL && SSL_pending(fSSL)) result = 1; else @@ -426,7 +426,7 @@ POP3Protocol::RetrieveInternal(const char *command, int32 message, } if (amountToReceive > bufSize - 1 - amountInBuffer) amountToReceive = bufSize - 1 - amountInBuffer; -#ifdef USESSL +#ifdef USE_SSL if (fUseSSL) { amountReceived = SSL_read(fSSL, buf + amountInBuffer, amountToReceive); @@ -594,7 +594,7 @@ POP3Protocol::ReceiveLine(BString &line) FD_SET(fSocket, &readSet); int result; -#ifdef USESSL +#ifdef USE_SSL if (fUseSSL && SSL_pending(fSSL)) result = 1; else @@ -606,7 +606,7 @@ POP3Protocol::ReceiveLine(BString &line) // Hope there's an end of line out there else this gets stuck. int32 bytesReceived; uint8 c = 0; -#ifdef USESSL +#ifdef USE_SSL if (fUseSSL) bytesReceived = SSL_read(fSSL, (char*)&c, 1); else @@ -647,7 +647,7 @@ POP3Protocol::SendCommand(const char *cmd) // Flush any accumulated garbage data before we send our command, so we // don't misinterrpret responses from previous commands (that got left over // due to bugs) as being from this command. - + struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; @@ -657,7 +657,7 @@ POP3Protocol::SendCommand(const char *cmd) FD_ZERO(&readSet); FD_SET(fSocket, &readSet); int result; -#ifdef USESSL +#ifdef USE_SSL if (fUseSSL && SSL_pending(fSSL)) result = 1; else @@ -667,7 +667,7 @@ POP3Protocol::SendCommand(const char *cmd) if (result > 0) { int amountReceived; char tempString [1025]; -#ifdef USESSL +#ifdef USE_SSL if (fUseSSL) amountReceived = SSL_read(fSSL, tempString, sizeof(tempString) - 1); else @@ -683,7 +683,7 @@ POP3Protocol::SendCommand(const char *cmd) // break; } -#ifdef USESSL +#ifdef USE_SSL if (fUseSSL) { SSL_write(fSSL, cmd,::strlen(cmd)); } else @@ -723,10 +723,10 @@ POP3Protocol::SendCommand(const char *cmd) void POP3Protocol::MD5Digest(unsigned char *in, char *asciiDigest) -{ +{ unsigned char digest[16]; -#ifdef USESSL +#ifdef USE_SSL MD5(in, ::strlen((char*)in), digest); #else 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_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME | B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER -#if USESSL +#if USE_SSL | B_MAIL_PROTOCOL_HAS_FLAVORS #endif ); view->AddAuthMethod("Plain Text"); view->AddAuthMethod("APOP"); -#if USESSL +#if USE_SSL view->AddFlavor("No Encryption"); view->AddFlavor("SSL"); #endif diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.h b/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.h index c3f777450d..ca671719d8 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.h +++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.h @@ -1,6 +1,6 @@ -/* +/* + * Copyright 2007-2008, Haiku Inc. 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. */ @@ -10,6 +10,10 @@ #include +#ifdef USE_SSL +# include +#endif + #include #include @@ -20,7 +24,7 @@ class POP3Protocol : public SimpleMailProtocol { public: POP3Protocol(BMessage *settings, BMailChainRunner *status); ~POP3Protocol(); - + status_t Open(const char *server, int port, int protocol); status_t Login(const char *uid, const char *password, int method); status_t UniqueIDs(); @@ -47,7 +51,7 @@ private: size_t fMailDropSize; BList fSizes; -#ifdef USESSL +#ifdef USE_SSL SSL_CTX* fSSLContext; SSL* fSSL; BIO* fSSLBio; diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/Jamfile b/src/add-ons/mail_daemon/outbound_protocols/smtp/Jamfile index 627281a1eb..58396adf93 100644 --- a/src/add-ons/mail_daemon/outbound_protocols/smtp/Jamfile +++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/Jamfile @@ -11,9 +11,14 @@ UsePrivateHeaders mail ; SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ; -if $(USESSL) { - 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 SMTP : @@ -22,8 +27,8 @@ Addon SMTP : LinkAgainst SMTP : be libmail.so $(TARGET_NETWORK_LIBS) ; -if $(USESSL) { - LinkAgainst SMTP : ssl crypto ; +if $(USE_SSL) { + LinkAgainst SMTP : $(sslDir)/lib/libssl.so $(sslDir)/lib/libcrypto.so ; } Package haiku-maildaemon-cvs : diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp b/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp index 2cabc26b47..96eae72a48 100644 --- a/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp +++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp @@ -1,7 +1,11 @@ -/* SMTPProtocol - implementation of the SMTP protocol -** -** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. -*/ +/* + * 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. + */ + +//! implementation of the SMTP protocol #include #include @@ -19,8 +23,8 @@ #include #include #ifndef HAIKU_TARGET_PLATFORM_BEOS // These headers don't exist in BeOS R5. - #include - #include +# include +# include #endif #include @@ -34,8 +38,10 @@ #include #include "smtp.h" -#ifndef USESSL -#include "md5.h" +#ifdef USE_SSL +# include +#else +# include "md5.h" #endif #include @@ -167,7 +173,7 @@ void MD5Digest (char* hexdigest, unsigned char *text, int text_len) { int i; unsigned char digest[17]; unsigned char c; - + MD5Sum((char*)digest, text, text_len); for (i = 0; i < 16; i++) { @@ -207,7 +213,7 @@ SplitChallengeIntoMap(BString str, map& m) if (*s == 0) return false; s++; - } + } *s++ = '\0'; } else { val = s; @@ -350,19 +356,19 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp) { runner->ReportProgress(0, 0, MDR_DIALECT_CHOICE ("Connecting to server...","接続中...")); - #ifdef USESSL + #ifdef USE_SSL use_ssl = (fSettings->FindInt32("flavor") == 1); ssl = NULL; ctx = NULL; #endif if (port <= 0) - #ifdef USESSL + #ifdef USE_SSL port = use_ssl ? 465 : 25; #else port = 25; #endif - + uint32 hostIP = inet_addr(address); // first see if we can parse it as a numeric address if ((hostIP == 0)||(hostIP == (uint32)-1)) { struct hostent * he = gethostbyname(address); @@ -371,7 +377,7 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp) if (hostIP == 0) return EHOSTUNREACH; - + #ifndef HAIKU_TARGET_PLATFORM_BEOS _fd = socket(AF_INET, SOCK_STREAM, 0); #else @@ -397,7 +403,7 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp) return errno; } -#ifdef USESSL +#ifdef USE_SSL if (use_ssl) { SSL_library_init(); SSL_load_error_strings(); @@ -405,12 +411,12 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp) /*--- Because we're an add-on loaded at an unpredictable time, all the memory addresses and things contained in ourself are esssentially random. */ - + ctx = SSL_CTX_new(SSLv23_method()); ssl = SSL_new(ctx); sbio=BIO_new_socket(_fd,BIO_NOCLOSE); SSL_set_bio(ssl,sbio,sbio); - + if (SSL_connect(ssl) <= 0) { BString error; error << "Could not connect to SMTP server " << fSettings->FindString("server"); @@ -429,18 +435,18 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp) return B_OK; } } - + #endif BString line; ReceiveResponse(line); - + char localhost[255]; gethostname(localhost,255); - + if (localhost[0] == 0) strcpy(localhost,"namethisbebox"); - + char *cmd = new char[::strlen(localhost)+8]; if (!esmtp) ::sprintf(cmd,"HELO %s"CRLF, localhost); @@ -749,7 +755,7 @@ SMTPProtocol::Close() // Error } -#ifdef USESSL +#ifdef USE_SSL if (use_ssl) { if (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] == '.') { foundCRLFPeriod = true; // Send data up to the CRLF, and include the period too. - #ifdef USESSL + #ifdef USE_SSL if (use_ssl) { if (SSL_write(ssl,data,i + 3) < 0) { amountUnread = 0; // Stop when an error happens. @@ -870,7 +876,7 @@ SMTPProtocol::Send(const char *to, const char *from, BPositionIO *message) if (!foundCRLFPeriod) { if (amountUnread <= 0) { // No more data, all we have is in the buffer. if (bufferLen > 0) { - #ifdef USESSL + #ifdef USE_SSL if (use_ssl) SSL_write(ssl,data,bufferLen); 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 // the next read, in case the CRLFPeriod is split between reads. if (bufferLen > 3) { - #ifdef USESSL + #ifdef USE_SSL if (use_ssl) { if (SSL_write(ssl,data,bufferLen - 3) < 0) break; @@ -927,20 +933,20 @@ SMTPProtocol::ReceiveResponse(BString &out) bool gotCode = false; int32 errCode; BString searchStr = ""; - + struct timeval tv; struct fd_set fds; tv.tv_sec = long(timeout / 1e6); tv.tv_usec = long(timeout-(tv.tv_sec * 1e6)); - + /* Initialize (clear) the socket mask. */ FD_ZERO(&fds); - + /* Set the socket in the mask. */ FD_SET(_fd, &fds); int result = -1; -#ifdef USESSL +#ifdef USE_SSL if ((use_ssl) && (SSL_pending(ssl))) result = 1; else @@ -948,10 +954,10 @@ SMTPProtocol::ReceiveResponse(BString &out) result = select(32, &fds, NULL, NULL, &tv); if (result < 0) return errno; - + if (result > 0) { while (1) { - #ifdef USESSL + #ifdef USE_SSL if (use_ssl) r = SSL_read(ssl,buf,SMTP_RESPONSE_SIZE - 1); else @@ -959,7 +965,7 @@ SMTPProtocol::ReceiveResponse(BString &out) r = recv(_fd,buf, SMTP_RESPONSE_SIZE - 1,0); if (r <= 0) break; - + if (!gotCode) { if (buf[3] == ' ' || buf[3] == '-') @@ -967,12 +973,12 @@ SMTPProtocol::ReceiveResponse(BString &out) errCode = atol(buf); gotCode = true; searchStr << errCode << ' '; - } + } } len += r; out.Append(buf, r); - + if (strstr(buf, CRLF) && (out.FindFirst(searchStr) != B_ERROR)) break; } @@ -991,7 +997,7 @@ SMTPProtocol::SendCommand(const char *cmd) { D(bug("C:%s\n", cmd)); -#ifdef USESSL +#ifdef USE_SSL if (use_ssl && ssl) { if (SSL_write(ssl,cmd,::strlen(cmd)) < 0) return B_ERROR; @@ -1039,8 +1045,8 @@ instantiate_mailfilter(BMessage *settings, BMailChainRunner *status) BView * instantiate_config_panel(BMessage *settings, BMessage *) { - #ifdef USESSL - BMailProtocolConfigView *view = new BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS | + #ifdef USE_SSL + BMailProtocolConfigView *view = new BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS | B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME | @@ -1048,7 +1054,7 @@ instantiate_config_panel(BMessage *settings, BMessage *) view->AddFlavor("Unencrypted"); view->AddFlavor("SSL"); #else - 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_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME); @@ -1060,7 +1066,7 @@ instantiate_config_panel(BMessage *settings, BMessage *) BTextControl *control = (BTextControl *)(view->FindView("host")); control->SetLabel(MDR_DIALECT_CHOICE ("SMTP Server: ","SMTPサーバ: ")); - + // Reset the dividers after changing one float widestLabel=0; for (int32 i = view->CountChildren(); i-- > 0;) { diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.h b/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.h index b5a2b55198..57d1989d2a 100644 --- a/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.h +++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.h @@ -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 #define ZOIDBERG_SMTP_H -/* SMTPProtocol - implementation of the SMTP protocol -** -** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. -*/ #include #include -#ifdef USESSL - #include - #include +#ifdef USE_SSL +# include +# include #endif + class SMTPProtocol : public BMailFilter { public: SMTPProtocol(BMessage *message, BMailChainRunner *runner); @@ -41,14 +44,14 @@ class SMTPProtocol : public BMailFilter { BMessage *fSettings; BMailChainRunner *runner; int32 fAuthType; - - #ifdef USESSL - SSL_CTX *ctx; - SSL *ssl; - BIO *sbio; - - bool use_ssl; - #endif + +#ifdef USE_SSL + SSL_CTX *ctx; + SSL *ssl; + BIO *sbio; + + bool use_ssl; +#endif status_t fStatus; BString fServerName; // required for DIGEST-MD5