* Style cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42259 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -6,37 +6,40 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//! implementation of the SMTP protocol
|
|
||||||
|
|
||||||
#include <DataIO.h>
|
//! Implementation of the SMTP protocol
|
||||||
#include <Message.h>
|
|
||||||
#include <Alert.h>
|
|
||||||
#include <TextControl.h>
|
|
||||||
#include <Entry.h>
|
|
||||||
#include <File.h>
|
|
||||||
#include <Path.h>
|
|
||||||
#include <MenuField.h>
|
|
||||||
|
|
||||||
#include <cctype>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <sys/select.h>
|
|
||||||
|
|
||||||
#include <ProtocolConfigView.h>
|
#include "smtp.h"
|
||||||
#include <mail_encoding.h>
|
|
||||||
#include <MailSettings.h>
|
|
||||||
#include <NodeMessage.h>
|
|
||||||
#include <crypt.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "smtp.h"
|
#include <arpa/inet.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/select.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <Alert.h>
|
||||||
|
#include <DataIO.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <File.h>
|
||||||
|
#include <MenuField.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <TextControl.h>
|
||||||
|
|
||||||
|
#include <crypt.h>
|
||||||
|
#include <mail_encoding.h>
|
||||||
|
#include <MailSettings.h>
|
||||||
|
#include <NodeMessage.h>
|
||||||
|
#include <ProtocolConfigView.h>
|
||||||
|
|
||||||
#ifdef USE_SSL
|
#ifdef USE_SSL
|
||||||
# include <openssl/md5.h>
|
# include <openssl/md5.h>
|
||||||
#else
|
#else
|
||||||
@@ -65,18 +68,14 @@ using namespace std;
|
|||||||
** written by Martin Schaaf <[email protected]>
|
** written by Martin Schaaf <[email protected]>
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MD5Hmac(unsigned char *digest,
|
MD5Hmac(unsigned char *digest, const unsigned char* text, int text_len,
|
||||||
const unsigned char* text, int text_len,
|
|
||||||
const unsigned char* key, int key_len)
|
const unsigned char* key, int key_len)
|
||||||
{
|
{
|
||||||
MD5_CTX context;
|
MD5_CTX context;
|
||||||
unsigned char k_ipad[64]; /* inner padding -
|
unsigned char k_ipad[64];
|
||||||
* key XORd with ipad
|
// inner padding - key XORd with ipad
|
||||||
*/
|
unsigned char k_opad[64];
|
||||||
unsigned char k_opad[64]; /* outer padding -
|
// outer padding - key XORd with opad
|
||||||
* key XORd with opad
|
|
||||||
*/
|
|
||||||
/* unsigned char tk[16]; */
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* start out by storing key in pads */
|
/* start out by storing key in pads */
|
||||||
@@ -106,7 +105,6 @@ MD5Hmac(unsigned char *digest,
|
|||||||
* and text is the data being protected
|
* and text is the data being protected
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* XOR key with ipad and opad values */
|
/* XOR key with ipad and opad values */
|
||||||
for (i = 0; i < 64; i++) {
|
for (i = 0; i < 64; i++) {
|
||||||
k_ipad[i] ^= 0x36;
|
k_ipad[i] ^= 0x36;
|
||||||
@@ -134,8 +132,7 @@ MD5Hmac(unsigned char *digest,
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MD5HexHmac(char *hexdigest,
|
MD5HexHmac(char *hexdigest, const unsigned char* text, int text_len,
|
||||||
const unsigned char* text, int text_len,
|
|
||||||
const unsigned char* key, int key_len)
|
const unsigned char* key, int key_len)
|
||||||
{
|
{
|
||||||
unsigned char digest[16];
|
unsigned char digest[16];
|
||||||
@@ -317,9 +314,7 @@ SMTPProtocol::Disconnect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Process EMail to be sent
|
//! Process EMail to be sent
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
SMTPProtocol::SendMessages(const std::vector<entry_ref>& mails,
|
SMTPProtocol::SendMessages(const std::vector<entry_ref>& mails,
|
||||||
size_t totalBytes)
|
size_t totalBytes)
|
||||||
@@ -351,8 +346,7 @@ SMTPProtocol::SendMessages(const std::vector<entry_ref>& mails,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Opens connection to server
|
//! Opens connection to server
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
SMTPProtocol::Open(const char *address, int port, bool esmtp)
|
SMTPProtocol::Open(const char *address, int port, bool esmtp)
|
||||||
{
|
{
|
||||||
@@ -381,30 +375,22 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp)
|
|||||||
if (hostIP == 0)
|
if (hostIP == 0)
|
||||||
return EHOSTUNREACH;
|
return EHOSTUNREACH;
|
||||||
|
|
||||||
#ifndef HAIKU_TARGET_PLATFORM_BEOS
|
|
||||||
fSocket = socket(AF_INET, SOCK_STREAM, 0);
|
fSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
#else
|
if (fSocket < 0)
|
||||||
fSocket = socket(AF_INET, 2, 0);
|
return errno;
|
||||||
#endif
|
|
||||||
if (fSocket >= 0) {
|
|
||||||
struct sockaddr_in saAddr;
|
struct sockaddr_in saAddr;
|
||||||
memset(&saAddr, 0, sizeof(saAddr));
|
memset(&saAddr, 0, sizeof(saAddr));
|
||||||
saAddr.sin_family = AF_INET;
|
saAddr.sin_family = AF_INET;
|
||||||
saAddr.sin_port = htons(port);
|
saAddr.sin_port = htons(port);
|
||||||
saAddr.sin_addr.s_addr = hostIP;
|
saAddr.sin_addr.s_addr = hostIP;
|
||||||
int result = connect(fSocket, (struct sockaddr *) &saAddr, sizeof(saAddr));
|
int result = connect(fSocket, (struct sockaddr *)&saAddr,
|
||||||
|
sizeof(saAddr));
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
#ifndef HAIKU_TARGET_PLATFORM_BEOS
|
|
||||||
close(fSocket);
|
close(fSocket);
|
||||||
#else
|
|
||||||
closesocket(fSocket);
|
|
||||||
#endif
|
|
||||||
fSocket = -1;
|
fSocket = -1;
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef USE_SSL
|
#ifdef USE_SSL
|
||||||
if (use_ssl) {
|
if (use_ssl) {
|
||||||
@@ -428,17 +414,12 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp)
|
|||||||
error << ". (SSL connection error)";
|
error << ". (SSL connection error)";
|
||||||
ShowError(error.String());
|
ShowError(error.String());
|
||||||
SSL_CTX_free(ctx);
|
SSL_CTX_free(ctx);
|
||||||
#ifndef HAIKU_TARGET_PLATFORM_BEOS
|
|
||||||
close(fSocket);
|
close(fSocket);
|
||||||
#else
|
|
||||||
closesocket(fSocket);
|
|
||||||
#endif
|
|
||||||
fSocket = -1;
|
fSocket = -1;
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // USE_SSL
|
||||||
#endif
|
|
||||||
|
|
||||||
BString line;
|
BString line;
|
||||||
ReceiveResponse(line);
|
ReceiveResponse(line);
|
||||||
@@ -460,12 +441,9 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_SSL
|
#ifdef USE_SSL
|
||||||
// Check for STARTTLS
|
// Check for STARTTLS
|
||||||
if(use_STARTTLS)
|
if (use_STARTTLS) {
|
||||||
{
|
|
||||||
const char *res = fLog.String();
|
const char *res = fLog.String();
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
@@ -473,11 +451,9 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp)
|
|||||||
RAND_seed(this,sizeof(SMTPProtocol));
|
RAND_seed(this,sizeof(SMTPProtocol));
|
||||||
::sprintf(cmd, "STARTTLS"CRLF);
|
::sprintf(cmd, "STARTTLS"CRLF);
|
||||||
|
|
||||||
if ((p = ::strstr(res, "STARTTLS")) != NULL)
|
if ((p = ::strstr(res, "STARTTLS")) != NULL) {
|
||||||
{
|
|
||||||
// Server advertises STARTTLS support
|
// Server advertises STARTTLS support
|
||||||
if(SendCommand(cmd) != B_OK)
|
if (SendCommand(cmd) != B_OK) {
|
||||||
{
|
|
||||||
delete[] cmd;
|
delete[] cmd;
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -499,15 +475,13 @@ SMTPProtocol::Open(const char *address, int port, bool esmtp)
|
|||||||
else
|
else
|
||||||
::sprintf(cmd, "EHLO %s"CRLF, localhost);
|
::sprintf(cmd, "EHLO %s"CRLF, localhost);
|
||||||
|
|
||||||
if(SendCommand(cmd) != B_OK)
|
if (SendCommand(cmd) != B_OK) {
|
||||||
{
|
|
||||||
delete[] cmd;
|
delete[] cmd;
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif // USE_SSL
|
||||||
|
|
||||||
delete[] cmd;
|
delete[] cmd;
|
||||||
|
|
||||||
@@ -805,8 +779,6 @@ SMTPProtocol::Close()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Send mail */
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
SMTPProtocol::Send(const char* to, const char* from, BPositionIO *message)
|
SMTPProtocol::Send(const char* to, const char* from, BPositionIO *message)
|
||||||
{
|
{
|
||||||
@@ -954,8 +926,7 @@ SMTPProtocol::Send(const char* to, const char* from, BPositionIO *message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Receives response from server.
|
//! Receives response from server.
|
||||||
|
|
||||||
int32
|
int32
|
||||||
SMTPProtocol::ReceiveResponse(BString &out)
|
SMTPProtocol::ReceiveResponse(BString &out)
|
||||||
{
|
{
|
||||||
@@ -1064,7 +1035,9 @@ SMTPProtocol::SendCommand(const char *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Instantiate hook
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
OutboundProtocol*
|
OutboundProtocol*
|
||||||
instantiate_outbound_protocol(BMailAccountSettings* settings)
|
instantiate_outbound_protocol(BMailAccountSettings* settings)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user