* Removed support for building on BeOS R5.
* Made MessageIO comply to our coding style. * No other functional change (intended). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42055 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
SubDir HAIKU_TOP src add-ons mail_daemon inbound_protocols pop3 ;
|
SubDir HAIKU_TOP src add-ons mail_daemon inbound_protocols pop3 ;
|
||||||
|
|
||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
|
||||||
|
|
||||||
if $(TARGET_PLATFORM) != haiku {
|
if $(TARGET_PLATFORM) != haiku {
|
||||||
UsePublicHeaders mail ;
|
UsePublicHeaders mail ;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +1,51 @@
|
|||||||
/* BMailMessageIO - Glue code for reading/writing messages directly from the
|
/*
|
||||||
** protocols but present a BPositionIO interface to the caller, while caching
|
* Copyright 2007-2011, Haiku, Inc. All rights reserved.
|
||||||
** the data read/written in a slave file.
|
* Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
||||||
**
|
*/
|
||||||
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Glue code for reading/writing messages directly from the protocols but
|
||||||
|
present a BPositionIO interface to the caller, while caching the data
|
||||||
|
read/written in a slave file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <BeBuild.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "MessageIO.h"
|
#include "MessageIO.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
BMailMessageIO::BMailMessageIO(POP3Protocol* protocol, BPositionIO *dump_to,
|
|
||||||
int32 seq_id) :
|
BMailMessageIO::BMailMessageIO(POP3Protocol* protocol, BPositionIO* dumpTo,
|
||||||
slave(dump_to),
|
int32 messageID)
|
||||||
message_id(seq_id),
|
:
|
||||||
|
fSlave(dumpTo),
|
||||||
|
fMessageID(messageID),
|
||||||
fProtocol(protocol),
|
fProtocol(protocol),
|
||||||
size(0),
|
fSize(0),
|
||||||
state(READ_HEADER_NEXT) {
|
fState(READ_HEADER_NEXT)
|
||||||
//-----do nothing, and do it well-----
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMailMessageIO::~BMailMessageIO()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
BMailMessageIO::ReadAt(off_t pos, void* buffer, size_t amountToRead) {
|
BMailMessageIO::ReadAt(off_t pos, void* buffer, size_t amountToRead)
|
||||||
status_t errorCode;
|
{
|
||||||
char lastBytes [5];
|
char lastBytes[5];
|
||||||
off_t old_pos = slave->Position();
|
off_t oldPosition = fSlave->Position();
|
||||||
|
|
||||||
while ((pos + amountToRead) > size) {
|
while (pos + amountToRead > fSize) {
|
||||||
if (state >= ALL_READING_DONE)
|
if (fState >= ALL_READING_DONE)
|
||||||
break;
|
break;
|
||||||
switch (state) {
|
|
||||||
|
switch (fState) {
|
||||||
// Read (download from the mail server) just the message headers,
|
// Read (download from the mail server) just the message headers,
|
||||||
// and append a blank line if needed (so the header processing code
|
// and append a blank line if needed (so the header processing code
|
||||||
// can tell where the end of the headers is). Don't append too
|
// can tell where the end of the headers is). Don't append too
|
||||||
@@ -44,24 +54,27 @@ BMailMessageIO::ReadAt(off_t pos, void* buffer, size_t amountToRead) {
|
|||||||
// filters which discard the message after only reading the header,
|
// filters which discard the message after only reading the header,
|
||||||
// thus avoiding the time it takes to download the whole message.
|
// thus avoiding the time it takes to download the whole message.
|
||||||
case READ_HEADER_NEXT:
|
case READ_HEADER_NEXT:
|
||||||
slave->SetSize(0); // Truncate the file.
|
{
|
||||||
slave->Seek(0,SEEK_SET);
|
fSlave->SetSize(0); // Truncate the file.
|
||||||
errorCode = fProtocol->GetHeader(message_id, slave);
|
fSlave->Seek(0,SEEK_SET);
|
||||||
if (errorCode < 0)
|
status_t status = fProtocol->GetHeader(fMessageID, fSlave);
|
||||||
return errorCode;
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
// See if it already ends in a blank line, if not, add enough
|
// See if it already ends in a blank line, if not, add enough
|
||||||
// end-of-lines to give a blank line.
|
// end-of-lines to give a blank line.
|
||||||
slave->Seek(-4, SEEK_END);
|
fSlave->Seek(-4, SEEK_END);
|
||||||
strcpy (lastBytes, "xxxx");
|
strcpy(lastBytes, "xxxx");
|
||||||
slave->Read(lastBytes, 4);
|
fSlave->Read(lastBytes, 4);
|
||||||
if (strcmp (lastBytes, "\r\n\r\n") != 0) {
|
|
||||||
if (strcmp (lastBytes + 2, "\r\n") == 0)
|
if (strcmp(lastBytes, "\r\n\r\n") != 0) {
|
||||||
slave->Write("\r\n", 2);
|
if (strcmp(lastBytes + 2, "\r\n") == 0)
|
||||||
|
fSlave->Write("\r\n", 2);
|
||||||
else
|
else
|
||||||
slave->Write("\r\n\r\n", 4);
|
fSlave->Write("\r\n\r\n", 4);
|
||||||
}
|
}
|
||||||
state = READ_BODY_NEXT;
|
fState = READ_BODY_NEXT;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// OK, they want more than the headers. Read the whole message,
|
// OK, they want more than the headers. Read the whole message,
|
||||||
// starting from the beginning (network->Retrieve does a seek to
|
// starting from the beginning (network->Retrieve does a seek to
|
||||||
@@ -71,70 +84,73 @@ BMailMessageIO::ReadAt(off_t pos, void* buffer, size_t amountToRead) {
|
|||||||
// modem's V.90 data compression will make it very quick to
|
// modem's V.90 data compression will make it very quick to
|
||||||
// retransmit the header portion.
|
// retransmit the header portion.
|
||||||
case READ_BODY_NEXT:
|
case READ_BODY_NEXT:
|
||||||
slave->SetSize(0); // Truncate the file.
|
{
|
||||||
slave->Seek(0,SEEK_SET);
|
fSlave->SetSize(0); // Truncate the file.
|
||||||
errorCode = fProtocol->Retrieve(message_id, slave);
|
fSlave->Seek(0,SEEK_SET);
|
||||||
if (errorCode < 0)
|
status_t status = fProtocol->Retrieve(fMessageID, fSlave);
|
||||||
return errorCode;
|
if (status < 0)
|
||||||
state = ALL_READING_DONE;
|
return status;
|
||||||
|
fState = ALL_READING_DONE;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default: // Shouldn't happen.
|
default: // Shouldn't happen.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ResetSize();
|
_ResetSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put the file position back at where it was, if possible. That's because
|
// Put the file position back at where it was, if possible. That's because
|
||||||
// ReadAt isn't supposed to affect the file position.
|
// ReadAt isn't supposed to affect the file position.
|
||||||
if (old_pos < size)
|
if (oldPosition < fSize)
|
||||||
slave->Seek (old_pos, SEEK_SET);
|
fSlave->Seek (oldPosition, SEEK_SET);
|
||||||
else
|
else
|
||||||
slave->Seek (0, SEEK_END);
|
fSlave->Seek (0, SEEK_END);
|
||||||
|
|
||||||
return slave->ReadAt(pos, buffer, amountToRead);
|
return fSlave->ReadAt(pos, buffer, amountToRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t BMailMessageIO::WriteAt(off_t pos, const void* buffer, size_t amountToWrite) {
|
ssize_t
|
||||||
ssize_t return_val;
|
BMailMessageIO::WriteAt(off_t pos, const void* buffer, size_t amountToWrite)
|
||||||
|
{
|
||||||
|
ssize_t bytesWritten = fSlave->WriteAt(pos, buffer, amountToWrite);
|
||||||
|
_ResetSize();
|
||||||
|
|
||||||
return_val = slave->WriteAt(pos, buffer, amountToWrite);
|
return bytesWritten;
|
||||||
ResetSize();
|
|
||||||
|
|
||||||
return return_val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t BMailMessageIO::Seek(off_t position, uint32 seek_mode) {
|
|
||||||
ssize_t errorCode;
|
off_t
|
||||||
char tempBuffer [1];
|
BMailMessageIO::Seek(off_t position, uint32 seekMode)
|
||||||
|
{
|
||||||
if (seek_mode == SEEK_END) {
|
if (seekMode == SEEK_END && fState != ALL_READING_DONE) {
|
||||||
if (state != ALL_READING_DONE) {
|
// Force it to read the whole message to find the size of it.
|
||||||
// Force it to read the whole message to find the size of it.
|
char tempBuffer;
|
||||||
state = READ_BODY_NEXT; // Skip the header reading step.
|
fState = READ_BODY_NEXT;
|
||||||
errorCode = ReadAt (size + 1, tempBuffer, sizeof (tempBuffer));
|
// Skip the header reading step.
|
||||||
if (errorCode < 0)
|
ssize_t bytesRead = ReadAt(fSize + 1, &tempBuffer, sizeof(tempBuffer));
|
||||||
return errorCode;
|
if (bytesRead < 0)
|
||||||
}
|
return bytesRead;
|
||||||
}
|
}
|
||||||
return slave->Seek(position,seek_mode);
|
return fSlave->Seek(position, seekMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t BMailMessageIO::Position() const {
|
|
||||||
return slave->Position();
|
off_t
|
||||||
|
BMailMessageIO::Position() const
|
||||||
|
{
|
||||||
|
return fSlave->Position();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BMailMessageIO::ResetSize(void) {
|
|
||||||
off_t old = slave->Position();
|
|
||||||
|
|
||||||
slave->Seek(0,SEEK_END);
|
void
|
||||||
size = slave->Position();
|
BMailMessageIO::_ResetSize()
|
||||||
|
{
|
||||||
|
off_t old = fSlave->Position();
|
||||||
|
|
||||||
slave->Seek(old,SEEK_SET);
|
fSlave->Seek(0,SEEK_END);
|
||||||
|
fSize = fSlave->Position();
|
||||||
|
|
||||||
|
fSlave->Seek(old,SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
BMailMessageIO::~BMailMessageIO() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
/* MessageIO - Glue code for reading/writing messages directly from the
|
/*
|
||||||
** protocols but present a BPositionIO interface to the caller, while caching
|
* Copyright 2007-2011, Haiku, Inc. All rights reserved.
|
||||||
** the data read/written in a slave file.
|
* Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
||||||
**
|
*/
|
||||||
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
#ifndef MAIL_MESSAGE_IO_H
|
||||||
*/
|
#define MAIL_MESSAGE_IO_H
|
||||||
#ifndef ZOIDBERG_MAIL_MESSAGE_IO_H
|
|
||||||
#define ZOIDBERG_MAIL_MESSAGE_IO_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
#include <Path.h>
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
#include <Path.h>
|
||||||
|
|
||||||
#include "pop3.h"
|
#include "pop3.h"
|
||||||
|
|
||||||
@@ -18,32 +16,34 @@
|
|||||||
class BMailMessageIO : public BPositionIO {
|
class BMailMessageIO : public BPositionIO {
|
||||||
public:
|
public:
|
||||||
BMailMessageIO(POP3Protocol* protocol,
|
BMailMessageIO(POP3Protocol* protocol,
|
||||||
BPositionIO* dump_to, int32 seq_id);
|
BPositionIO* dumpTo, int32 messageID);
|
||||||
~BMailMessageIO();
|
~BMailMessageIO();
|
||||||
|
|
||||||
//----BPositionIO
|
//----BPositionIO
|
||||||
virtual ssize_t ReadAt(off_t pos, void *buffer,
|
virtual ssize_t ReadAt(off_t pos, void* buffer,
|
||||||
size_t amountToRead);
|
size_t amountToRead);
|
||||||
virtual ssize_t WriteAt(off_t pos, const void *buffer,
|
virtual ssize_t WriteAt(off_t pos, const void* buffer,
|
||||||
size_t amountToWrite);
|
size_t amountToWrite);
|
||||||
|
|
||||||
virtual off_t Seek(off_t position, uint32 seek_mode);
|
virtual off_t Seek(off_t position, uint32 seekMode);
|
||||||
virtual off_t Position() const;
|
virtual off_t Position() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ResetSize(void);
|
void _ResetSize();
|
||||||
|
|
||||||
BPositionIO* slave;
|
|
||||||
int32 message_id;
|
|
||||||
POP3Protocol* fProtocol;
|
|
||||||
|
|
||||||
size_t size;
|
|
||||||
|
|
||||||
|
private:
|
||||||
enum MessageIOStateEnum {
|
enum MessageIOStateEnum {
|
||||||
READ_HEADER_NEXT,
|
READ_HEADER_NEXT,
|
||||||
READ_BODY_NEXT,
|
READ_BODY_NEXT,
|
||||||
ALL_READING_DONE
|
ALL_READING_DONE
|
||||||
} state;
|
};
|
||||||
|
|
||||||
|
BPositionIO* fSlave;
|
||||||
|
int32 fMessageID;
|
||||||
|
POP3Protocol* fProtocol;
|
||||||
|
size_t fSize;
|
||||||
|
MessageIOStateEnum fState;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* ZOIDBERG_MAIL_MESSAGE_IO_H */
|
|
||||||
|
#endif /* MAIL_MESSAGE_IO_H */
|
||||||
|
|||||||
@@ -120,11 +120,7 @@ POP3Protocol::Disconnect()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAIKU_TARGET_PLATFORM_BEOS
|
|
||||||
close(fSocket);
|
close(fSocket);
|
||||||
#else
|
|
||||||
closesocket(fSocket);
|
|
||||||
#endif
|
|
||||||
fSocket = -1;
|
fSocket = -1;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -365,11 +361,7 @@ POP3Protocol::Open(const char *server, int port, int)
|
|||||||
return B_NAME_NOT_FOUND;
|
return B_NAME_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HAIKU_TARGET_PLATFORM_BEOS
|
|
||||||
fSocket = socket(AF_INET, SOCK_STREAM, 0);
|
fSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
#else
|
|
||||||
fSocket = socket(AF_INET, 2, 0);
|
|
||||||
#endif
|
|
||||||
if (fSocket >= 0) {
|
if (fSocket >= 0) {
|
||||||
struct sockaddr_in saAddr;
|
struct sockaddr_in saAddr;
|
||||||
memset(&saAddr, 0, sizeof(saAddr));
|
memset(&saAddr, 0, sizeof(saAddr));
|
||||||
@@ -378,11 +370,7 @@ POP3Protocol::Open(const char *server, int port, int)
|
|||||||
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;
|
||||||
error_msg << ": " << strerror(errno);
|
error_msg << ": " << strerror(errno);
|
||||||
ShowError(error_msg.String());
|
ShowError(error_msg.String());
|
||||||
@@ -417,35 +405,17 @@ POP3Protocol::Open(const char *server, int port, int)
|
|||||||
error << ". (SSL connection error)";
|
error << ". (SSL connection error)";
|
||||||
ShowError(error.String());
|
ShowError(error.String());
|
||||||
SSL_CTX_free(fSSLContext);
|
SSL_CTX_free(fSSLContext);
|
||||||
#ifndef HAIKU_TARGET_PLATFORM_BEOS
|
|
||||||
close(fSocket);
|
close(fSocket);
|
||||||
#else
|
|
||||||
closesocket(fSocket);
|
|
||||||
#endif
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BString line;
|
BString line;
|
||||||
status_t err;
|
status_t err = ReceiveLine(line);
|
||||||
#ifndef HAIKU_TARGET_PLATFORM_BEOS
|
|
||||||
err = ReceiveLine(line);
|
|
||||||
#else
|
|
||||||
int32 tries = 200000;
|
|
||||||
// no endless loop here
|
|
||||||
while ((err = ReceiveLine(line)) == 0) {
|
|
||||||
if (tries-- < 0)
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
#ifndef HAIKU_TARGET_PLATFORM_BEOS
|
|
||||||
close(fSocket);
|
close(fSocket);
|
||||||
#else
|
|
||||||
closesocket(fSocket);
|
|
||||||
#endif
|
|
||||||
fSocket = -1;
|
fSocket = -1;
|
||||||
error_msg << ": " << strerror(err);
|
error_msg << ": " << strerror(err);
|
||||||
ShowError(error_msg.String());
|
ShowError(error_msg.String());
|
||||||
|
|||||||
Reference in New Issue
Block a user