* mail_util.h was not self-contained.
* Added a few missing breaks in MailProtocolThread::MessageReceived()! * Minor coding style update. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42808 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All rights reserved.
|
||||
* Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
|
||||
*/
|
||||
#ifndef ZOIDBERG_GARGOYLE_MAIL_UTIL_H
|
||||
@@ -10,9 +11,10 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Node.h>
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <E-mail.h>
|
||||
#include <Message.h>
|
||||
#include <Node.h>
|
||||
|
||||
|
||||
// TODO: this should only be preserved for gcc2 compatibility
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All rights reserved.
|
||||
* Copyright 2011, Clemens Zeidler <[email protected]>
|
||||
* Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -18,7 +19,6 @@
|
||||
|
||||
struct mail_header_field {
|
||||
const char* rfc_name;
|
||||
|
||||
const char* attr_name;
|
||||
type_code attr_type;
|
||||
// currently either B_STRING_TYPE and B_TIME_TYPE
|
||||
@@ -65,7 +65,7 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file)
|
||||
file->Seek(0, SEEK_SET);
|
||||
|
||||
BMessage attributes;
|
||||
// TODO attributes.AddInt32(B_MAIL_ATTR_CONTENT, length);
|
||||
// TODO: attributes.AddInt32(B_MAIL_ATTR_CONTENT, length);
|
||||
attributes.AddInt32(B_MAIL_ATTR_ACCOUNT_ID, fAccountID);
|
||||
attributes.AddString(B_MAIL_ATTR_ACCOUNT, fAccountName);
|
||||
|
||||
@@ -83,6 +83,7 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file)
|
||||
gDefaultFields[i].rfc_name, target);
|
||||
if (status != B_OK)
|
||||
continue;
|
||||
|
||||
switch (gDefaultFields[i].attr_type){
|
||||
case B_STRING_TYPE:
|
||||
attributes.AddString(gDefaultFields[i].attr_name, target);
|
||||
@@ -111,8 +112,9 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file)
|
||||
if (name.Length() <= 0)
|
||||
name = "No Subject";
|
||||
attributes.AddString(B_MAIL_ATTR_THREAD, name);
|
||||
// Avoid hidden files, starting with a dot.
|
||||
if (name[0] == '.')
|
||||
name.Prepend ("_"); // Avoid hidden files, starting with a dot.
|
||||
name.Prepend ("_");
|
||||
|
||||
// Convert the date into a year-month-day fixed digit width format, so that
|
||||
// sorting by file name will give all the messages with the same subject in
|
||||
@@ -127,16 +129,13 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file)
|
||||
(const void**)&datePntr, &dateSize) == B_OK)
|
||||
dateAsTime = *datePntr;
|
||||
localtime_r(&dateAsTime, &timeFields);
|
||||
sprintf(numericDateString, "%04d%02d%02d%02d%02d%02d",
|
||||
timeFields.tm_year + 1900,
|
||||
timeFields.tm_mon + 1,
|
||||
timeFields.tm_mday,
|
||||
timeFields.tm_hour,
|
||||
timeFields.tm_min,
|
||||
timeFields.tm_sec);
|
||||
snprintf(numericDateString, sizeof(numericDateString),
|
||||
"%04d%02d%02d%02d%02d%02d",
|
||||
timeFields.tm_year + 1900, timeFields.tm_mon + 1, timeFields.tm_mday,
|
||||
timeFields.tm_hour, timeFields.tm_min, timeFields.tm_sec);
|
||||
name << " " << numericDateString;
|
||||
|
||||
BString worker = attributes.FindString("MAIL:from");
|
||||
BString worker = attributes.FindString(B_MAIL_ATTR_FROM);
|
||||
extract_address_name(worker);
|
||||
name << " " << worker;
|
||||
|
||||
@@ -149,8 +148,9 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file)
|
||||
name.ReplaceAll('!', '_');
|
||||
name.ReplaceAll('<', '_');
|
||||
name.ReplaceAll('>', '_');
|
||||
while (name.FindFirst(" ") >= 0) // Remove multiple spaces.
|
||||
name.Replace(" " /* Old */, " " /* New */, 1024 /* Count */);
|
||||
// Remove multiple spaces.
|
||||
while (name.FindFirst(" ") >= 0)
|
||||
name.Replace(" ", " ", 1024);
|
||||
|
||||
worker = name;
|
||||
int32 identicalNumber = 1;
|
||||
@@ -162,10 +162,10 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file)
|
||||
worker << "_" << identicalNumber;
|
||||
status = _SetFileName(ref, worker);
|
||||
}
|
||||
if (status < B_OK)
|
||||
if (status < B_OK) {
|
||||
printf("FolderFilter::ProcessMailMessage: could not rename mail (%s)! "
|
||||
"(should be: %s)\n",strerror(status), worker.String());
|
||||
else {
|
||||
} else {
|
||||
entry_ref to(ref.device, ref.directory, worker);
|
||||
fMailProtocol.FileRenamed(ref, to);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* BMailProtocol - the base class for protocol filters
|
||||
**
|
||||
** Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All rights reserved.
|
||||
* Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
@@ -35,56 +35,65 @@
|
||||
using std::map;
|
||||
|
||||
|
||||
const uint32 kMsgSyncMessages = '&SyM';
|
||||
const uint32 kMsgDeleteMessage = '&DeM';
|
||||
const uint32 kMsgAppendMessage = '&ApM';
|
||||
|
||||
const uint32 kMsgMoveFile = '&MoF';
|
||||
const uint32 kMsgDeleteFile = '&DeF';
|
||||
const uint32 kMsgFileRenamed = '&FiR';
|
||||
const uint32 kMsgFileDeleted = '&FDe';
|
||||
const uint32 kMsgInit = '&Ini';
|
||||
|
||||
const uint32 kMsgSendMessage = '&SeM';
|
||||
|
||||
|
||||
MailFilter::MailFilter(MailProtocol& protocol, AddonSettings* settings)
|
||||
:
|
||||
fMailProtocol(protocol),
|
||||
fAddonSettings(settings)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
MailFilter::~MailFilter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MailFilter::HeaderFetched(const entry_ref& ref, BFile* file)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MailFilter::BodyFetched(const entry_ref& ref, BFile* file)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MailFilter::MailboxSynced(status_t status)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MailFilter::MessageReadyToSend(const entry_ref& ref, BFile* file)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MailFilter::MessageSent(const entry_ref& ref, BFile* file)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
MailProtocol::MailProtocol(BMailAccountSettings* settings)
|
||||
:
|
||||
fMailNotifier(NULL),
|
||||
@@ -379,6 +388,9 @@ MailProtocol::_LoadFilter(AddonSettings* filterSettings)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
InboundProtocol::InboundProtocol(BMailAccountSettings* settings)
|
||||
:
|
||||
MailProtocol(settings)
|
||||
@@ -408,6 +420,9 @@ InboundProtocol::MarkMessageAsRead(const entry_ref& ref, read_flags flag)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
OutboundProtocol::OutboundProtocol(BMailAccountSettings* settings)
|
||||
:
|
||||
MailProtocol(settings)
|
||||
@@ -422,11 +437,7 @@ OutboundProtocol::~OutboundProtocol()
|
||||
}
|
||||
|
||||
|
||||
const uint32 kMsgMoveFile = '&MoF';
|
||||
const uint32 kMsgDeleteFile = '&DeF';
|
||||
const uint32 kMsgFileRenamed = '&FiR';
|
||||
const uint32 kMsgFileDeleted = '&FDe';
|
||||
const uint32 kMsgInit = '&Ini';
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
MailProtocolThread::MailProtocolThread(MailProtocol* protocol)
|
||||
@@ -478,6 +489,7 @@ MailProtocolThread::MessageReceived(BMessage* message)
|
||||
entry_ref to;
|
||||
message->FindRef("to", &to);
|
||||
fMailProtocol->FileRenamed(from, to);
|
||||
break;
|
||||
}
|
||||
|
||||
case kMsgFileDeleted:
|
||||
@@ -486,6 +498,7 @@ MailProtocolThread::MessageReceived(BMessage* message)
|
||||
message->FindInt32("device",&node.device);
|
||||
message->FindInt64("node", &node.node);
|
||||
fMailProtocol->FileDeleted(node);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -538,9 +551,7 @@ MailProtocolThread::TriggerFileDeleted(const node_ref& node)
|
||||
}
|
||||
|
||||
|
||||
const uint32 kMsgSyncMessages = '&SyM';
|
||||
const uint32 kMsgDeleteMessage = '&DeM';
|
||||
const uint32 kMsgAppendMessage = '&ApM';
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
InboundProtocolThread::InboundProtocolThread(InboundProtocol* protocol)
|
||||
@@ -613,6 +624,7 @@ InboundProtocolThread::MessageReceived(BMessage* message)
|
||||
|
||||
default:
|
||||
MailProtocolThread::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -671,7 +683,7 @@ InboundProtocolThread::_NotiyMailboxSynced(status_t status)
|
||||
}
|
||||
|
||||
|
||||
const uint32 kMsgSendMessage = '&SeM';
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
OutboundProtocolThread::OutboundProtocolThread(OutboundProtocol* protocol)
|
||||
|
||||
+163
-185
@@ -1,15 +1,10 @@
|
||||
/* mail util - header parsing
|
||||
**
|
||||
** Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All rights reserved.
|
||||
* Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include <UTF8.h>
|
||||
#include <Message.h>
|
||||
#include <String.h>
|
||||
#include <Locker.h>
|
||||
#include <DataIO.h>
|
||||
#include <List.h>
|
||||
#include <mail_util.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -18,27 +13,30 @@
|
||||
#include <regex.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <List.h>
|
||||
#include <Locker.h>
|
||||
#include <parsedate.h>
|
||||
#include <String.h>
|
||||
#include <UTF8.h>
|
||||
|
||||
#include <mail_encoding.h>
|
||||
|
||||
#include <mail_util.h>
|
||||
|
||||
#include <CharacterSet.h>
|
||||
#include <CharacterSetRoster.h>
|
||||
|
||||
|
||||
using namespace BPrivate;
|
||||
|
||||
|
||||
#define CRLF "\r\n"
|
||||
|
||||
struct CharsetConversionEntry
|
||||
{
|
||||
struct CharsetConversionEntry {
|
||||
const char *charset;
|
||||
uint32 flavor;
|
||||
};
|
||||
|
||||
extern const CharsetConversionEntry mail_charsets [] =
|
||||
{
|
||||
extern const CharsetConversionEntry mail_charsets[] = {
|
||||
// In order of authority, so when searching for the name for a particular
|
||||
// numbered conversion, start at the beginning of the array.
|
||||
{"iso-8859-1", B_ISO1_CONVERSION}, // MIME STANDARD
|
||||
@@ -86,6 +84,74 @@ extern const CharsetConversionEntry mail_charsets [] =
|
||||
};
|
||||
|
||||
|
||||
static int32 gLocker = 0;
|
||||
static size_t gNsub = 1;
|
||||
static re_pattern_buffer gRe;
|
||||
static re_pattern_buffer *gRebuf = NULL;
|
||||
static unsigned char gTranslation[256];
|
||||
|
||||
|
||||
static int
|
||||
handle_non_rfc2047_encoding(char **buffer, size_t *bufferLength,
|
||||
size_t *sourceLength)
|
||||
{
|
||||
char *string = *buffer;
|
||||
int32 length = *sourceLength;
|
||||
int32 i;
|
||||
|
||||
// check for 8-bit characters
|
||||
for (i = 0;i < length;i++)
|
||||
if (string[i] & 0x80)
|
||||
break;
|
||||
if (i == length)
|
||||
return false;
|
||||
|
||||
// check for groups of 8-bit characters - this code is not very smart;
|
||||
// it just can detect some sort of single-byte encoded stuff, the rest
|
||||
// is regarded as UTF-8
|
||||
|
||||
int32 singletons = 0,doubles = 0;
|
||||
|
||||
for (i = 0;i < length;i++)
|
||||
{
|
||||
if (string[i] & 0x80)
|
||||
{
|
||||
if ((string[i + 1] & 0x80) == 0)
|
||||
singletons++;
|
||||
else doubles++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (singletons != 0) // can't be valid UTF-8 anymore, so we assume ISO-Latin-1
|
||||
{
|
||||
int32 state = 0;
|
||||
// just to be sure
|
||||
int32 destLength = length * 4 + 1;
|
||||
int32 destBufferLength = destLength;
|
||||
char *dest = (char*)malloc(destLength);
|
||||
if (dest == NULL)
|
||||
return 0;
|
||||
|
||||
if (convert_to_utf8(B_ISO1_CONVERSION, string, &length,dest,
|
||||
&destLength, &state) == B_OK) {
|
||||
*buffer = dest;
|
||||
*bufferLength = destBufferLength;
|
||||
*sourceLength = destLength;
|
||||
return true;
|
||||
}
|
||||
free(dest);
|
||||
return false;
|
||||
}
|
||||
|
||||
// we assume a valid UTF-8 string here, but yes, we don't check it
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
status_t
|
||||
write_read_attr(BNode& node, read_flags flag)
|
||||
{
|
||||
@@ -93,7 +159,6 @@ write_read_attr(BNode& node, read_flags flag)
|
||||
< 0)
|
||||
return B_ERROR;
|
||||
|
||||
#if R5_COMPATIBLE
|
||||
// manage the status string only if it currently has a "read" status
|
||||
BString currentStatus;
|
||||
if (node.ReadAttrString(B_MAIL_ATTR_STATUS, ¤tStatus) == B_OK) {
|
||||
@@ -103,12 +168,12 @@ write_read_attr(BNode& node, read_flags flag)
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
const char* statusString = (flag == B_READ) ? "Read"
|
||||
: (flag == B_SEEN) ? "Seen" : "New";
|
||||
const char* statusString = flag == B_READ ? "Read"
|
||||
: flag == B_SEEN ? "Seen" : "New";
|
||||
if (node.WriteAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, statusString,
|
||||
strlen(statusString)) < 0)
|
||||
return B_ERROR;
|
||||
#endif
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -120,7 +185,6 @@ read_read_attr(BNode& node, read_flags& flag)
|
||||
== sizeof(int32))
|
||||
return B_OK;
|
||||
|
||||
#if R5_COMPATIBLE
|
||||
BString statusString;
|
||||
if (node.ReadAttrString(B_MAIL_ATTR_STATUS, &statusString) == B_OK) {
|
||||
if (statusString.ICompare("New"))
|
||||
@@ -130,24 +194,20 @@ read_read_attr(BNode& node, read_flags& flag)
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
// The next couple of functions are our wrapper around convert_to_utf8 and
|
||||
// convert_from_utf8 so that they can also convert from UTF-8 to UTF-8 by
|
||||
// specifying the B_MAIL_UTF8_CONVERSION constant as the conversion operation. It
|
||||
// also lets us add new conversions, like B_MAIL_US_ASCII_CONVERSION.
|
||||
// specifying the B_MAIL_UTF8_CONVERSION constant as the conversion operation.
|
||||
// It also lets us add new conversions, like B_MAIL_US_ASCII_CONVERSION.
|
||||
|
||||
_EXPORT status_t mail_convert_to_utf8 (
|
||||
uint32 srcEncoding,
|
||||
const char *src,
|
||||
int32 *srcLen,
|
||||
char *dst,
|
||||
int32 *dstLen,
|
||||
int32 *state,
|
||||
char substitute)
|
||||
|
||||
status_t
|
||||
mail_convert_to_utf8(uint32 srcEncoding, const char *src, int32 *srcLen,
|
||||
char *dst, int32 *dstLen, int32 *state, char substitute)
|
||||
{
|
||||
int32 copyAmount;
|
||||
char *originalDst = dst;
|
||||
@@ -203,14 +263,9 @@ _EXPORT status_t mail_convert_to_utf8 (
|
||||
}
|
||||
|
||||
|
||||
_EXPORT status_t mail_convert_from_utf8 (
|
||||
uint32 dstEncoding,
|
||||
const char *src,
|
||||
int32 *srcLen,
|
||||
char *dst,
|
||||
int32 *dstLen,
|
||||
int32 *state,
|
||||
char substitute)
|
||||
status_t
|
||||
mail_convert_from_utf8(uint32 dstEncoding, const char *src, int32 *srcLen,
|
||||
char *dst, int32 *dstLen, int32 *state, char substitute)
|
||||
{
|
||||
int32 copyAmount;
|
||||
status_t errorCode;
|
||||
@@ -218,8 +273,7 @@ _EXPORT status_t mail_convert_from_utf8 (
|
||||
int32 tempDstLen;
|
||||
int32 tempSrcLen;
|
||||
|
||||
if (dstEncoding == B_MAIL_UTF8_CONVERSION)
|
||||
{
|
||||
if (dstEncoding == B_MAIL_UTF8_CONVERSION) {
|
||||
copyAmount = *srcLen;
|
||||
if (*dstLen < copyAmount)
|
||||
copyAmount = *dstLen;
|
||||
@@ -229,8 +283,7 @@ _EXPORT status_t mail_convert_from_utf8 (
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
if (dstEncoding == B_MAIL_US_ASCII_CONVERSION)
|
||||
{
|
||||
if (dstEncoding == B_MAIL_US_ASCII_CONVERSION) {
|
||||
int32 characterLength;
|
||||
int32 dstRemaining = *dstLen;
|
||||
unsigned char letter;
|
||||
@@ -288,7 +341,8 @@ _EXPORT status_t mail_convert_from_utf8 (
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
errorCode = convert_from_utf8 (dstEncoding, src, srcLen, dst, dstLen, state, substitute);
|
||||
errorCode = convert_from_utf8(dstEncoding, src, srcLen, dst, dstLen, state,
|
||||
substitute);
|
||||
if (errorCode != B_OK)
|
||||
return errorCode;
|
||||
|
||||
@@ -317,64 +371,8 @@ _EXPORT status_t mail_convert_from_utf8 (
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int handle_non_rfc2047_encoding(char **buffer,size_t *bufferLength,size_t *sourceLength)
|
||||
{
|
||||
char *string = *buffer;
|
||||
int32 length = *sourceLength;
|
||||
int32 i;
|
||||
|
||||
// check for 8-bit characters
|
||||
for (i = 0;i < length;i++)
|
||||
if (string[i] & 0x80)
|
||||
break;
|
||||
if (i == length)
|
||||
return false;
|
||||
|
||||
// check for groups of 8-bit characters - this code is not very smart;
|
||||
// it just can detect some sort of single-byte encoded stuff, the rest
|
||||
// is regarded as UTF-8
|
||||
|
||||
int32 singletons = 0,doubles = 0;
|
||||
|
||||
for (i = 0;i < length;i++)
|
||||
{
|
||||
if (string[i] & 0x80)
|
||||
{
|
||||
if ((string[i + 1] & 0x80) == 0)
|
||||
singletons++;
|
||||
else doubles++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (singletons != 0) // can't be valid UTF-8 anymore, so we assume ISO-Latin-1
|
||||
{
|
||||
int32 state = 0;
|
||||
// just to be sure
|
||||
int32 destLength = length * 4 + 1;
|
||||
int32 destBufferLength = destLength;
|
||||
char *dest = (char*)malloc(destLength);
|
||||
if (dest == NULL)
|
||||
return 0;
|
||||
|
||||
if (convert_to_utf8(B_ISO1_CONVERSION, string, &length,dest,
|
||||
&destLength, &state) == B_OK) {
|
||||
*buffer = dest;
|
||||
*bufferLength = destBufferLength;
|
||||
*sourceLength = destLength;
|
||||
return true;
|
||||
}
|
||||
free(dest);
|
||||
return false;
|
||||
}
|
||||
|
||||
// we assume a valid UTF-8 string here, but yes, we don't check it
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
_EXPORT ssize_t rfc2047_to_utf8(char **bufp, size_t *bufLen, size_t strLen)
|
||||
ssize_t
|
||||
rfc2047_to_utf8(char **bufp, size_t *bufLen, size_t strLen)
|
||||
{
|
||||
char *head, *tail;
|
||||
char *charset, *encoding, *end;
|
||||
@@ -437,22 +435,22 @@ _EXPORT ssize_t rfc2047_to_utf8(char **bufp, size_t *bufLen, size_t strLen)
|
||||
size_t cLen = encoding - 1 - charset;
|
||||
bool base64encoded = toupper(*encoding) == 'B';
|
||||
|
||||
uint32 convert_id = B_MAIL_NULL_CONVERSION;
|
||||
char charset_string[cLen+1];
|
||||
memcpy(charset_string, charset, cLen);
|
||||
charset_string[cLen] = '\0';
|
||||
if (strcasecmp(charset_string, "us-ascii") == 0) {
|
||||
convert_id = B_MAIL_US_ASCII_CONVERSION;
|
||||
} else if (strcasecmp(charset_string, "utf-8") == 0) {
|
||||
convert_id = B_MAIL_UTF8_CONVERSION;
|
||||
uint32 convertID = B_MAIL_NULL_CONVERSION;
|
||||
char charsetName[cLen + 1];
|
||||
memcpy(charsetName, charset, cLen);
|
||||
charsetName[cLen] = '\0';
|
||||
if (strcasecmp(charsetName, "us-ascii") == 0) {
|
||||
convertID = B_MAIL_US_ASCII_CONVERSION;
|
||||
} else if (strcasecmp(charsetName, "utf-8") == 0) {
|
||||
convertID = B_MAIL_UTF8_CONVERSION;
|
||||
} else {
|
||||
const BCharacterSet * cs = BCharacterSetRoster::FindCharacterSetByName(charset_string);
|
||||
if (cs != NULL) {
|
||||
convert_id = cs->GetConversionID();
|
||||
const BCharacterSet* charSet
|
||||
= BCharacterSetRoster::FindCharacterSetByName(charsetName);
|
||||
if (charSet != NULL) {
|
||||
convertID = charSet->GetConversionID();
|
||||
}
|
||||
}
|
||||
if (convert_id == B_MAIL_NULL_CONVERSION)
|
||||
{
|
||||
if (convertID == B_MAIL_NULL_CONVERSION) {
|
||||
// unidentified charset
|
||||
// what to do? doing nothing skips the encoded text;
|
||||
// but we should keep it: we copy it to the output.
|
||||
@@ -480,9 +478,9 @@ _EXPORT ssize_t rfc2047_to_utf8(char **bufp, size_t *bufLen, size_t strLen)
|
||||
//
|
||||
// do the conversion
|
||||
//
|
||||
ret = mail_convert_to_utf8(convert_id, src, &cvLen, dst, &dstLen, &convState);
|
||||
if (ret != B_OK)
|
||||
{
|
||||
ret = mail_convert_to_utf8(convertID, src, &cvLen, dst, &dstLen,
|
||||
&convState);
|
||||
if (ret != B_OK) {
|
||||
// what to do? doing nothing skips the encoded text
|
||||
// but we should keep it: we copy it to the output.
|
||||
|
||||
@@ -524,10 +522,8 @@ _EXPORT ssize_t rfc2047_to_utf8(char **bufp, size_t *bufLen, size_t strLen)
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
else
|
||||
{
|
||||
if (dstLen > end-string)
|
||||
{
|
||||
else {
|
||||
if (dstLen > end-string) {
|
||||
// copy the string forward...
|
||||
memmove(string+dstLen, end, strLen - (end-head) + 1);
|
||||
strLen += string+dstLen - end;
|
||||
@@ -553,7 +549,9 @@ _EXPORT ssize_t rfc2047_to_utf8(char **bufp, size_t *bufLen, size_t strLen)
|
||||
}
|
||||
|
||||
|
||||
_EXPORT ssize_t utf8_to_rfc2047 (char **bufp, ssize_t length, uint32 charset, char encoding) {
|
||||
ssize_t
|
||||
utf8_to_rfc2047 (char **bufp, ssize_t length, uint32 charset, char encoding)
|
||||
{
|
||||
struct word {
|
||||
BString originalWord;
|
||||
BString convertedWord;
|
||||
@@ -748,9 +746,8 @@ _EXPORT ssize_t utf8_to_rfc2047 (char **bufp, ssize_t length, uint32 charset, ch
|
||||
}
|
||||
|
||||
|
||||
//====================================================================
|
||||
|
||||
void FoldLineAtWhiteSpaceAndAddCRLF (BString &string)
|
||||
void
|
||||
FoldLineAtWhiteSpaceAndAddCRLF(BString &string)
|
||||
{
|
||||
int inputLength = string.Length();
|
||||
int lineStartIndex;
|
||||
@@ -827,21 +824,18 @@ void FoldLineAtWhiteSpaceAndAddCRLF (BString &string)
|
||||
}
|
||||
|
||||
|
||||
//====================================================================
|
||||
|
||||
_EXPORT ssize_t readfoldedline(FILE *file, char **buffer, size_t *buflen)
|
||||
ssize_t
|
||||
readfoldedline(FILE *file, char **buffer, size_t *buflen)
|
||||
{
|
||||
ssize_t len = buflen && *buflen ? *buflen : 0;
|
||||
char * buf = buffer && *buffer ? *buffer : NULL;
|
||||
ssize_t cnt = 0; // Number of characters currently in the buffer.
|
||||
int c;
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
// Make sure there is space in the buffer for two more characters (one
|
||||
// for the next character, and one for the end of string NUL byte).
|
||||
if (buf == NULL || cnt + 2 >= len)
|
||||
{
|
||||
if (buf == NULL || cnt + 2 >= len) {
|
||||
char *temp = (char *)realloc(buf, len + 64);
|
||||
if (temp == NULL) {
|
||||
// Out of memory, however existing buffer remains allocated.
|
||||
@@ -898,7 +892,6 @@ _EXPORT ssize_t readfoldedline(FILE *file, char **buffer, size_t *buflen)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (buf != NULL && cnt >= 0)
|
||||
buf[cnt] = '\0';
|
||||
|
||||
@@ -914,9 +907,8 @@ _EXPORT ssize_t readfoldedline(FILE *file, char **buffer, size_t *buflen)
|
||||
}
|
||||
|
||||
|
||||
//====================================================================
|
||||
|
||||
_EXPORT ssize_t readfoldedline(BPositionIO &in, char **buffer, size_t *buflen)
|
||||
ssize_t
|
||||
readfoldedline(BPositionIO &in, char **buffer, size_t *buflen)
|
||||
{
|
||||
ssize_t len = buflen && *buflen ? *buflen : 0;
|
||||
char * buf = buffer && *buffer ? *buffer : NULL;
|
||||
@@ -924,12 +916,10 @@ _EXPORT ssize_t readfoldedline(BPositionIO &in, char **buffer, size_t *buflen)
|
||||
char c;
|
||||
status_t errorCode;
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
// Make sure there is space in the buffer for two more characters (one
|
||||
// for the next character, and one for the end of string NUL byte).
|
||||
if (buf == NULL || cnt + 2 >= len)
|
||||
{
|
||||
if (buf == NULL || cnt + 2 >= len) {
|
||||
char *temp = (char *)realloc(buf, len + 64);
|
||||
if (temp == NULL) {
|
||||
// Out of memory, however existing buffer remains allocated.
|
||||
@@ -1005,7 +995,7 @@ _EXPORT ssize_t readfoldedline(BPositionIO &in, char **buffer, size_t *buflen)
|
||||
}
|
||||
|
||||
|
||||
_EXPORT ssize_t
|
||||
ssize_t
|
||||
nextfoldedline(const char** header, char **buffer, size_t *buflen)
|
||||
{
|
||||
ssize_t len = buflen && *buflen ? *buflen : 0;
|
||||
@@ -1085,7 +1075,7 @@ nextfoldedline(const char** header, char **buffer, size_t *buflen)
|
||||
}
|
||||
|
||||
|
||||
_EXPORT void
|
||||
void
|
||||
trim_white_space(BString &string)
|
||||
{
|
||||
int32 i;
|
||||
@@ -1105,12 +1095,11 @@ trim_white_space(BString &string)
|
||||
}
|
||||
|
||||
|
||||
/** Tries to return a human-readable name from the specified
|
||||
* header parameter (should be from "To:" or "From:").
|
||||
* Tries to return the name rather than the eMail address.
|
||||
/*! Tries to return a human-readable name from the specified
|
||||
header parameter (should be from "To:" or "From:").
|
||||
Tries to return the name rather than the eMail address.
|
||||
*/
|
||||
|
||||
_EXPORT void
|
||||
void
|
||||
extract_address_name(BString &header)
|
||||
{
|
||||
BString name;
|
||||
@@ -1198,19 +1187,13 @@ extract_address_name(BString &header)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Given a subject in a BString, remove the extraneous RE: re: and other stuff
|
||||
// to get down to the core subject string, which should be identical for all
|
||||
// messages posted about a topic. The input string is modified in place to
|
||||
// become the output core subject string.
|
||||
|
||||
static int32 gLocker = 0;
|
||||
static size_t gNsub = 1;
|
||||
static re_pattern_buffer gRe;
|
||||
static re_pattern_buffer *gRebuf = NULL;
|
||||
static unsigned char gTranslation[256];
|
||||
|
||||
_EXPORT void SubjectToThread (BString &string)
|
||||
/*! Given a subject in a BString, remove the extraneous RE: re: and other stuff
|
||||
to get down to the core subject string, which should be identical for all
|
||||
messages posted about a topic. The input string is modified in place to
|
||||
become the output core subject string.
|
||||
*/
|
||||
void
|
||||
SubjectToThread (BString &string)
|
||||
{
|
||||
// a regex that matches a non-ASCII UTF8 character:
|
||||
#define U8C \
|
||||
@@ -1230,8 +1213,7 @@ _EXPORT void SubjectToThread (BString &string)
|
||||
"|^( +| *(\\<(\\w|" U8C "){2,3} *(\\[[^\\]]*\\])? *:)+ *)" \
|
||||
"| *\\(fwd\\) *$"
|
||||
|
||||
if (gRebuf == NULL && atomic_add(&gLocker,1) == 0)
|
||||
{
|
||||
if (gRebuf == NULL && atomic_add(&gLocker, 1) == 0) {
|
||||
// the idea is to compile the regexp once to speed up testing
|
||||
|
||||
for (int i=0; i<256; ++i) gTranslation[i]=i;
|
||||
@@ -1256,16 +1238,13 @@ _EXPORT void SubjectToThread (BString &string)
|
||||
gRebuf = &gRe;
|
||||
else
|
||||
fprintf(stderr, "Failed to compile the regex: %s\n", err);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int32 tries = 200;
|
||||
while (gRebuf == NULL && tries-- > 0)
|
||||
snooze(10000);
|
||||
}
|
||||
|
||||
if (gRebuf)
|
||||
{
|
||||
if (gRebuf) {
|
||||
struct re_registers regs;
|
||||
// can't be static if this function is to be thread-safe
|
||||
|
||||
@@ -1273,11 +1252,8 @@ _EXPORT void SubjectToThread (BString &string)
|
||||
regs.start = (regoff_t*)malloc(gNsub*sizeof(regoff_t));
|
||||
regs.end = (regoff_t*)malloc(gNsub*sizeof(regoff_t));
|
||||
|
||||
for (int start=0;
|
||||
(start=re_search(gRebuf, string.String(), string.Length(),
|
||||
0, string.Length(), ®s)) >= 0;
|
||||
)
|
||||
{
|
||||
for (int start = 0; (start = re_search(gRebuf, string.String(),
|
||||
string.Length(), 0, string.Length(), ®s)) >= 0;) {
|
||||
//
|
||||
// we found something
|
||||
//
|
||||
@@ -1287,7 +1263,8 @@ _EXPORT void SubjectToThread (BString &string)
|
||||
start = regs.start[2];
|
||||
|
||||
string.Remove(start,regs.end[0]-start);
|
||||
if (start) string.Insert(' ',1,start);
|
||||
if (start)
|
||||
string.Insert(' ',1,start);
|
||||
|
||||
// TODO: for some subjects this results in an endless loop, check
|
||||
// why this happen.
|
||||
@@ -1306,11 +1283,11 @@ _EXPORT void SubjectToThread (BString &string)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Converts a date to a time. Handles numeric time zones too, unlike
|
||||
// parsedate. Returns -1 if it fails.
|
||||
|
||||
_EXPORT time_t ParseDateWithTimeZone (const char *DateString)
|
||||
/*! Converts a date to a time. Handles numeric time zones too, unlike
|
||||
parsedate(). Returns -1 if it fails.
|
||||
*/
|
||||
time_t
|
||||
ParseDateWithTimeZone(const char *DateString)
|
||||
{
|
||||
time_t currentTime;
|
||||
time_t dateAsTime;
|
||||
@@ -1390,10 +1367,9 @@ _EXPORT time_t ParseDateWithTimeZone (const char *DateString)
|
||||
}
|
||||
|
||||
|
||||
/** Parses a mail header and fills the headers BMessage
|
||||
/*! Parses a mail header and fills the headers BMessage
|
||||
*/
|
||||
|
||||
_EXPORT status_t
|
||||
status_t
|
||||
parse_header(BMessage &headers, BPositionIO &input)
|
||||
{
|
||||
char *buffer = NULL;
|
||||
@@ -1417,10 +1393,12 @@ parse_header(BMessage &headers, BPositionIO &input)
|
||||
// unified case for later fetch
|
||||
|
||||
delimiter++; // Skip the colon.
|
||||
// Skip over leading white space and tabs.
|
||||
// TODO: (comments in brackets).
|
||||
while (isspace(*delimiter))
|
||||
delimiter++; // Skip over leading white space and tabs. To do: (comments in brackets).
|
||||
delimiter++;
|
||||
|
||||
// ToDo: implement joining of multiple header tags (i.e. multiple "Cc:"s)
|
||||
// TODO: implement joining of multiple header tags (i.e. multiple "Cc:"s)
|
||||
headers.AddString(header.String(), delimiter);
|
||||
}
|
||||
free(buffer);
|
||||
@@ -1429,7 +1407,7 @@ parse_header(BMessage &headers, BPositionIO &input)
|
||||
}
|
||||
|
||||
|
||||
_EXPORT status_t
|
||||
status_t
|
||||
extract_from_header(const BString& header, const BString& field,
|
||||
BString& target)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user