Style (pointer & spaces/tabs)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38115 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+193
-118
@@ -25,15 +25,15 @@ using namespace BPrivate ;
|
|||||||
|
|
||||||
struct CharsetConversionEntry
|
struct CharsetConversionEntry
|
||||||
{
|
{
|
||||||
const char *charset;
|
const char* charset;
|
||||||
uint32 flavor;
|
uint32 flavor;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const CharsetConversionEntry mail_charsets[];
|
extern const CharsetConversionEntry mail_charsets[];
|
||||||
|
|
||||||
|
|
||||||
const char *kHeaderCharsetString = "header-charset";
|
const char* kHeaderCharsetString = "header-charset";
|
||||||
const char *kHeaderEncodingString = "header-encoding";
|
const char* kHeaderEncodingString = "header-encoding";
|
||||||
// Special field names in the headers which specify the character set (int32)
|
// Special field names in the headers which specify the character set (int32)
|
||||||
// and encoding (int8) to use when converting the headers from UTF-8 to the
|
// and encoding (int8) to use when converting the headers from UTF-8 to the
|
||||||
// output e-mail format (rfc2047). Since they are numbers, not strings, the
|
// output e-mail format (rfc2047). Since they are numbers, not strings, the
|
||||||
@@ -45,13 +45,16 @@ BMailComponent::BMailComponent(uint32 defaultCharSet)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BMailComponent::~BMailComponent()
|
BMailComponent::~BMailComponent()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 BMailComponent::ComponentType()
|
|
||||||
|
uint32
|
||||||
|
BMailComponent::ComponentType()
|
||||||
{
|
{
|
||||||
if (NULL != dynamic_cast<BAttributedMailAttachment *> (this))
|
if (NULL != dynamic_cast<BAttributedMailAttachment*> (this))
|
||||||
return B_MAIL_ATTRIBUTED_ATTACHMENT;
|
return B_MAIL_ATTRIBUTED_ATTACHMENT;
|
||||||
|
|
||||||
BMimeType type, super;
|
BMimeType type, super;
|
||||||
@@ -70,9 +73,11 @@ uint32 BMailComponent::ComponentType()
|
|||||||
return B_MAIL_SIMPLE_ATTACHMENT;
|
return B_MAIL_SIMPLE_ATTACHMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
BMailComponent *BMailComponent::WhatIsThis() {
|
|
||||||
switch (ComponentType())
|
BMailComponent*
|
||||||
{
|
BMailComponent::WhatIsThis()
|
||||||
|
{
|
||||||
|
switch (ComponentType()) {
|
||||||
case B_MAIL_SIMPLE_ATTACHMENT:
|
case B_MAIL_SIMPLE_ATTACHMENT:
|
||||||
return new BSimpleMailAttachment;
|
return new BSimpleMailAttachment;
|
||||||
case B_MAIL_ATTRIBUTED_ATTACHMENT:
|
case B_MAIL_ATTRIBUTED_ATTACHMENT:
|
||||||
@@ -85,17 +90,21 @@ BMailComponent *BMailComponent::WhatIsThis() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BMailComponent::IsAttachment() {
|
|
||||||
const char *disposition = HeaderField("Content-Disposition");
|
bool
|
||||||
if ((disposition != NULL) && (strncasecmp(disposition,"Attachment",strlen("Attachment")) == 0))
|
BMailComponent::IsAttachment()
|
||||||
|
{
|
||||||
|
const char* disposition = HeaderField("Content-Disposition");
|
||||||
|
if ((disposition != NULL)
|
||||||
|
&& (strncasecmp(disposition, "Attachment", strlen("Attachment")) == 0))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
BMessage header;
|
BMessage header;
|
||||||
HeaderField("Content-Type",&header);
|
HeaderField("Content-Type", &header);
|
||||||
if (header.HasString("name"))
|
if (header.HasString("name"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (HeaderField("Content-Location",&header) == B_OK)
|
if (HeaderField("Content-Location", &header) == B_OK)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
BMimeType type;
|
BMimeType type;
|
||||||
@@ -107,29 +116,35 @@ bool BMailComponent::IsAttachment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BMailComponent::SetHeaderField(const char *key, const char *value, uint32 charset, mail_encoding encoding, bool replace_existing) {
|
void
|
||||||
|
BMailComponent::SetHeaderField(const char* key, const char* value,
|
||||||
|
uint32 charset, mail_encoding encoding, bool replace_existing)
|
||||||
|
{
|
||||||
if (replace_existing)
|
if (replace_existing)
|
||||||
headers.RemoveName(key);
|
headers.RemoveName(key);
|
||||||
if (value != NULL && value[0] != 0) // Empty or NULL strings mean delete header.
|
if (value != NULL && value[0] != 0) // Empty or NULL strings mean delete header.
|
||||||
headers.AddString(key,value);
|
headers.AddString(key, value);
|
||||||
|
|
||||||
// Latest setting of the character set and encoding to use when outputting
|
// Latest setting of the character set and encoding to use when outputting
|
||||||
// the headers is the one which affects all the headers. There used to be
|
// the headers is the one which affects all the headers. There used to be
|
||||||
// separate settings for each item in the headers, but it never actually
|
// separate settings for each item in the headers, but it never actually
|
||||||
// worked (can't store multiple items of different types in a BMessage).
|
// worked (can't store multiple items of different types in a BMessage).
|
||||||
if (charset != B_MAIL_NULL_CONVERSION &&
|
if (charset != B_MAIL_NULL_CONVERSION
|
||||||
headers.ReplaceInt32 (kHeaderCharsetString, charset) != B_OK)
|
&& headers.ReplaceInt32 (kHeaderCharsetString, charset) != B_OK)
|
||||||
headers.AddInt32 (kHeaderCharsetString, charset);
|
headers.AddInt32(kHeaderCharsetString, charset);
|
||||||
if (encoding != null_encoding &&
|
if (encoding != null_encoding
|
||||||
headers.ReplaceInt8 (kHeaderEncodingString, encoding) != B_OK)
|
&& headers.ReplaceInt8 (kHeaderEncodingString, encoding) != B_OK)
|
||||||
headers.AddInt8 (kHeaderEncodingString, encoding);
|
headers.AddInt8(kHeaderEncodingString, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BMailComponent::SetHeaderField(const char *key, BMessage *structure, bool replace_existing) {
|
void
|
||||||
int32 charset = B_MAIL_NULL_CONVERSION;
|
BMailComponent::SetHeaderField(const char* key, BMessage* structure,
|
||||||
int8 encoding = null_encoding;
|
bool replace_existing)
|
||||||
const char *unlabeled = "unlabeled";
|
{
|
||||||
|
int32 charset = B_MAIL_NULL_CONVERSION;
|
||||||
|
int8 encoding = null_encoding;
|
||||||
|
const char* unlabeled = "unlabeled";
|
||||||
|
|
||||||
if (replace_existing)
|
if (replace_existing)
|
||||||
headers.RemoveName(key);
|
headers.RemoveName(key);
|
||||||
@@ -138,14 +153,15 @@ void BMailComponent::SetHeaderField(const char *key, BMessage *structure, bool r
|
|||||||
if (structure->HasString(unlabeled))
|
if (structure->HasString(unlabeled))
|
||||||
value << structure->FindString(unlabeled) << "; ";
|
value << structure->FindString(unlabeled) << "; ";
|
||||||
|
|
||||||
const char *name, *sub_val;
|
const char* name;
|
||||||
|
const char* sub_val;
|
||||||
type_code type;
|
type_code type;
|
||||||
for (int32 i = 0; structure->GetInfo(B_STRING_TYPE,i,
|
for (int32 i = 0; structure->GetInfo(B_STRING_TYPE, i,
|
||||||
#if !defined(HAIKU_TARGET_PLATFORM_DANO)
|
#if !defined(HAIKU_TARGET_PLATFORM_DANO)
|
||||||
(char**)
|
(char**)
|
||||||
#endif
|
#endif
|
||||||
&name,&type) == B_OK; i++)
|
&name, &type) == B_OK; i++) {
|
||||||
{
|
|
||||||
if (strcasecmp(name, unlabeled) == 0)
|
if (strcasecmp(name, unlabeled) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -164,23 +180,31 @@ void BMailComponent::SetHeaderField(const char *key, BMessage *structure, bool r
|
|||||||
if (structure->HasInt8(kHeaderEncodingString))
|
if (structure->HasInt8(kHeaderEncodingString))
|
||||||
structure->FindInt8(kHeaderEncodingString, &encoding);
|
structure->FindInt8(kHeaderEncodingString, &encoding);
|
||||||
|
|
||||||
SetHeaderField(key,value.String(),(uint32) charset, (mail_encoding) encoding);
|
SetHeaderField(key, value.String(), (uint32) charset, (mail_encoding) encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *BMailComponent::HeaderField(const char *key, int32 index) {
|
|
||||||
const char *string = NULL;
|
|
||||||
|
|
||||||
headers.FindString(key,index,&string);
|
const char*
|
||||||
|
BMailComponent::HeaderField(const char* key, int32 index)
|
||||||
|
{
|
||||||
|
const char* string = NULL;
|
||||||
|
|
||||||
|
headers.FindString(key, index, &string);
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t BMailComponent::HeaderField(const char *key, BMessage *structure, int32 index) {
|
|
||||||
BString string = HeaderField(key,index);
|
status_t
|
||||||
|
BMailComponent::HeaderField(const char* key, BMessage* structure, int32 index)
|
||||||
|
{
|
||||||
|
BString string = HeaderField(key, index);
|
||||||
if (string == "")
|
if (string == "")
|
||||||
return B_NAME_NOT_FOUND;
|
return B_NAME_NOT_FOUND;
|
||||||
|
|
||||||
BString sub_cat,end_piece;
|
BString sub_cat;
|
||||||
int32 i = 0, end = 0;
|
BString end_piece;
|
||||||
|
int32 i = 0;
|
||||||
|
int32 end = 0;
|
||||||
|
|
||||||
// Break the header into parts, they're separated by semicolons, like this:
|
// Break the header into parts, they're separated by semicolons, like this:
|
||||||
// Content-Type: multipart/mixed;boundary= "----=_NextPart_000_00AA_354DB459.5977A1CA"
|
// Content-Type: multipart/mixed;boundary= "----=_NextPart_000_00AA_354DB459.5977A1CA"
|
||||||
@@ -188,69 +212,87 @@ status_t BMailComponent::HeaderField(const char *key, BMessage *structure, int32
|
|||||||
// parenthesis like this, which can appear anywhere white space is: (header comment)
|
// parenthesis like this, which can appear anywhere white space is: (header comment)
|
||||||
|
|
||||||
while (end < string.Length()) {
|
while (end < string.Length()) {
|
||||||
end = string.FindFirst(';',i);
|
end = string.FindFirst(';', i);
|
||||||
if (end < 0)
|
if (end < 0)
|
||||||
end = string.Length();
|
end = string.Length();
|
||||||
|
|
||||||
string.CopyInto(sub_cat,i,end - i);
|
string.CopyInto(sub_cat, i, end - i);
|
||||||
i = end + 1;
|
i = end + 1;
|
||||||
|
|
||||||
//-------Trim spaces off of beginning and end of text
|
//-------Trim spaces off of beginning and end of text
|
||||||
for (int32 h = 0; h < sub_cat.Length(); h++) {
|
for (int32 h = 0; h < sub_cat.Length(); h++) {
|
||||||
if (!isspace(sub_cat.ByteAt(h))) {
|
if (!isspace(sub_cat.ByteAt(h))) {
|
||||||
sub_cat.Remove(0,h);
|
sub_cat.Remove(0, h);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int32 h = sub_cat.Length()-1; h >= 0; h--) {
|
for (int32 h = sub_cat.Length() - 1; h >= 0; h--) {
|
||||||
if (!isspace(sub_cat.ByteAt(h))) {
|
if (!isspace(sub_cat.ByteAt(h))) {
|
||||||
sub_cat.Truncate(h+1);
|
sub_cat.Truncate(h + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//--------Split along '='
|
//--------Split along '='
|
||||||
int32 first_equal = sub_cat.FindFirst('=');
|
int32 first_equal = sub_cat.FindFirst('=');
|
||||||
if (first_equal >= 0) {
|
if (first_equal >= 0) {
|
||||||
sub_cat.CopyInto(end_piece,first_equal+1,sub_cat.Length() - first_equal - 1);
|
sub_cat.CopyInto(end_piece, first_equal + 1, sub_cat.Length() - first_equal - 1);
|
||||||
sub_cat.Truncate(first_equal);
|
sub_cat.Truncate(first_equal);
|
||||||
// Remove leading spaces from part after the equals sign.
|
// Remove leading spaces from part after the equals sign.
|
||||||
while (isspace (end_piece.ByteAt(0)))
|
while (isspace (end_piece.ByteAt(0)))
|
||||||
end_piece.Remove (0 /* index */, 1 /* number of chars */);
|
end_piece.Remove (0 /* index */, 1 /* number of chars */);
|
||||||
// Remove quote marks.
|
// Remove quote marks.
|
||||||
if (end_piece.ByteAt(0) == '\"') {
|
if (end_piece.ByteAt(0) == '\"') {
|
||||||
end_piece.Remove(0,1);
|
end_piece.Remove(0, 1);
|
||||||
end_piece.Truncate(end_piece.Length() - 1);
|
end_piece.Truncate(end_piece.Length() - 1);
|
||||||
}
|
}
|
||||||
sub_cat.ToLower();
|
sub_cat.ToLower();
|
||||||
structure->AddString(sub_cat.String(),end_piece.String());
|
structure->AddString(sub_cat.String(), end_piece.String());
|
||||||
} else {
|
} else {
|
||||||
structure->AddString("unlabeled",sub_cat.String());
|
structure->AddString("unlabeled", sub_cat.String());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t BMailComponent::RemoveHeader(const char *key) {
|
|
||||||
|
status_t
|
||||||
|
BMailComponent::RemoveHeader(const char* key)
|
||||||
|
{
|
||||||
return headers.RemoveName(key);
|
return headers.RemoveName(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *BMailComponent::HeaderAt(int32 index) {
|
|
||||||
|
const char*
|
||||||
|
BMailComponent::HeaderAt(int32 index)
|
||||||
|
{
|
||||||
#if defined(HAIKU_TARGET_PLATFORM_DANO)
|
#if defined(HAIKU_TARGET_PLATFORM_DANO)
|
||||||
const
|
const
|
||||||
#endif
|
#endif
|
||||||
char *name = NULL;
|
char* name = NULL;
|
||||||
type_code type;
|
type_code type;
|
||||||
|
|
||||||
headers.GetInfo(B_STRING_TYPE,index,&name,&type);
|
headers.GetInfo(B_STRING_TYPE, index, &name, &type);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t BMailComponent::GetDecodedData(BPositionIO *) {return B_OK;}
|
|
||||||
status_t BMailComponent::SetDecodedData(BPositionIO *) {return B_OK;}
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BMailComponent::SetToRFC822(BPositionIO *data, size_t /*length*/, bool /*parse_now*/)
|
BMailComponent::GetDecodedData(BPositionIO*)
|
||||||
|
{
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BMailComponent::SetDecodedData(BPositionIO*)
|
||||||
|
{
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BMailComponent::SetToRFC822(BPositionIO* data, size_t /*length*/, bool /*parse_now*/)
|
||||||
{
|
{
|
||||||
headers.MakeEmpty();
|
headers.MakeEmpty();
|
||||||
|
|
||||||
@@ -260,37 +302,40 @@ BMailComponent::SetToRFC822(BPositionIO *data, size_t /*length*/, bool /*parse_n
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BMailComponent::RenderToRFC822(BPositionIO *render_to) {
|
BMailComponent::RenderToRFC822(BPositionIO* render_to)
|
||||||
|
{
|
||||||
int32 charset = B_ISO15_CONVERSION;
|
int32 charset = B_ISO15_CONVERSION;
|
||||||
int8 encoding = quoted_printable;
|
int8 encoding = quoted_printable;
|
||||||
const char *key, *value;
|
const char* key;
|
||||||
char *allocd;
|
const char* value;
|
||||||
|
char* allocd;
|
||||||
ssize_t amountWritten;
|
ssize_t amountWritten;
|
||||||
BString concat;
|
BString concat;
|
||||||
type_code stupidity_personified = B_STRING_TYPE;
|
type_code stupidity_personified = B_STRING_TYPE;
|
||||||
int32 count = 0;
|
int32 count = 0;
|
||||||
|
|
||||||
if (headers.HasInt32 (kHeaderCharsetString))
|
if (headers.HasInt32(kHeaderCharsetString))
|
||||||
headers.FindInt32 (kHeaderCharsetString, &charset);
|
headers.FindInt32(kHeaderCharsetString, &charset);
|
||||||
if (headers.HasInt8 (kHeaderEncodingString))
|
if (headers.HasInt8(kHeaderEncodingString))
|
||||||
headers.FindInt8 (kHeaderEncodingString, &encoding);
|
headers.FindInt8(kHeaderEncodingString, &encoding);
|
||||||
|
|
||||||
for (int32 index = 0; headers.GetInfo(B_STRING_TYPE,index,
|
for (int32 index = 0; headers.GetInfo(B_STRING_TYPE, index,
|
||||||
#if !defined(HAIKU_TARGET_PLATFORM_DANO)
|
#if !defined(HAIKU_TARGET_PLATFORM_DANO)
|
||||||
(char**)
|
(char**)
|
||||||
#endif
|
#endif
|
||||||
&key,&stupidity_personified,&count) == B_OK; index++) {
|
&key, &stupidity_personified, &count) == B_OK; index++) {
|
||||||
for (int32 g = 0; g < count; g++) {
|
for (int32 g = 0; g < count; g++) {
|
||||||
headers.FindString(key,g,(const char **)&value);
|
headers.FindString(key, g, (const char**)&value);
|
||||||
allocd = (char *)malloc(strlen(value) + 1);
|
allocd = (char*)malloc(strlen(value) + 1);
|
||||||
strcpy(allocd,value);
|
strcpy(allocd, value);
|
||||||
|
|
||||||
concat << key << ": ";
|
concat << key << ": ";
|
||||||
concat.CapitalizeEachWord();
|
concat.CapitalizeEachWord();
|
||||||
|
|
||||||
concat.Append(allocd,utf8_to_rfc2047(&allocd, strlen(value), charset, encoding));
|
concat.Append(allocd, utf8_to_rfc2047(&allocd, strlen(value),
|
||||||
|
charset, encoding));
|
||||||
free(allocd);
|
free(allocd);
|
||||||
FoldLineAtWhiteSpaceAndAddCRLF (concat);
|
FoldLineAtWhiteSpaceAndAddCRLF(concat);
|
||||||
|
|
||||||
amountWritten = render_to->Write(concat.String(), concat.Length());
|
amountWritten = render_to->Write(concat.String(), concat.Length());
|
||||||
if (amountWritten < 0)
|
if (amountWritten < 0)
|
||||||
@@ -305,13 +350,15 @@ BMailComponent::RenderToRFC822(BPositionIO *render_to) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t BMailComponent::MIMEType(BMimeType *mime) {
|
status_t
|
||||||
|
BMailComponent::MIMEType(BMimeType* mime)
|
||||||
|
{
|
||||||
bool foundBestHeader;
|
bool foundBestHeader;
|
||||||
const char *boundaryString;
|
const char* boundaryString;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
BMessage msg;
|
BMessage msg;
|
||||||
const char *typeAsString = NULL;
|
const char* typeAsString = NULL;
|
||||||
char typeAsLowerCaseString [B_MIME_TYPE_LENGTH];
|
char typeAsLowerCaseString[B_MIME_TYPE_LENGTH];
|
||||||
|
|
||||||
// Find the best Content-Type header to use. There should really be just
|
// Find the best Content-Type header to use. There should really be just
|
||||||
// one, but evil spammers sneakily insert one for multipart (with no
|
// one, but evil spammers sneakily insert one for multipart (with no
|
||||||
@@ -322,7 +369,7 @@ status_t BMailComponent::MIMEType(BMimeType *mime) {
|
|||||||
foundBestHeader = false;
|
foundBestHeader = false;
|
||||||
for (i = 0; msg.MakeEmpty(), HeaderField("Content-Type", &msg, i) == B_OK; i++) {
|
for (i = 0; msg.MakeEmpty(), HeaderField("Content-Type", &msg, i) == B_OK; i++) {
|
||||||
typeAsString = msg.FindString("unlabeled");
|
typeAsString = msg.FindString("unlabeled");
|
||||||
if (typeAsString != NULL && strncasecmp (typeAsString, "multipart", 9) != 0) {
|
if (typeAsString != NULL && strncasecmp(typeAsString, "multipart", 9) != 0) {
|
||||||
foundBestHeader = true;
|
foundBestHeader = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -330,9 +377,9 @@ status_t BMailComponent::MIMEType(BMimeType *mime) {
|
|||||||
if (!foundBestHeader) {
|
if (!foundBestHeader) {
|
||||||
for (i = 0; msg.MakeEmpty(), HeaderField("Content-Type", &msg, i) == B_OK; i++) {
|
for (i = 0; msg.MakeEmpty(), HeaderField("Content-Type", &msg, i) == B_OK; i++) {
|
||||||
typeAsString = msg.FindString("unlabeled");
|
typeAsString = msg.FindString("unlabeled");
|
||||||
if (typeAsString != NULL && strncasecmp (typeAsString, "multipart", 9) == 0) {
|
if (typeAsString != NULL && strncasecmp(typeAsString, "multipart", 9) == 0) {
|
||||||
boundaryString = msg.FindString("boundary");
|
boundaryString = msg.FindString("boundary");
|
||||||
if (boundaryString != NULL && strlen (boundaryString) > 0) {
|
if (boundaryString != NULL && strlen(boundaryString) > 0) {
|
||||||
foundBestHeader = true;
|
foundBestHeader = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -343,19 +390,20 @@ status_t BMailComponent::MIMEType(BMimeType *mime) {
|
|||||||
// foundBestHeader is true.
|
// foundBestHeader is true.
|
||||||
|
|
||||||
if (!foundBestHeader) {
|
if (!foundBestHeader) {
|
||||||
strcpy (typeAsLowerCaseString, "text/plain"); // Hope this is an OK default.
|
strcpy(typeAsLowerCaseString, "text/plain"); // Hope this is an OK default.
|
||||||
} else {
|
} else {
|
||||||
// Some extra processing to convert mixed or upper case MIME types into
|
// Some extra processing to convert mixed or upper case MIME types into
|
||||||
// lower case, since the BeOS R5 BMimeType is case sensitive (but OpenBeOS
|
// lower case, since the BeOS R5 BMimeType is case sensitive (but OpenBeOS
|
||||||
// isn't). Also truncate the string if it is too long.
|
// isn't). Also truncate the string if it is too long.
|
||||||
for (i = 0; i < sizeof (typeAsLowerCaseString) - 1 && typeAsString[i] != 0; i++)
|
for (i = 0; i < sizeof(typeAsLowerCaseString) - 1
|
||||||
typeAsLowerCaseString[i] = tolower (typeAsString[i]);
|
&& typeAsString[i] != 0; i++)
|
||||||
|
typeAsLowerCaseString[i] = tolower(typeAsString[i]);
|
||||||
typeAsLowerCaseString[i] = 0;
|
typeAsLowerCaseString[i] = 0;
|
||||||
|
|
||||||
// Some old e-mail programs saved the type as just "TEXT", which we need to
|
// Some old e-mail programs saved the type as just "TEXT", which we need to
|
||||||
// convert to "text/plain" since the rest of the code looks for that.
|
// convert to "text/plain" since the rest of the code looks for that.
|
||||||
if (strcmp (typeAsLowerCaseString, "text") == 0)
|
if (strcmp(typeAsLowerCaseString, "text") == 0)
|
||||||
strcpy (typeAsLowerCaseString, "text/plain");
|
strcpy(typeAsLowerCaseString, "text/plain");
|
||||||
}
|
}
|
||||||
mime->SetTo(typeAsLowerCaseString);
|
mime->SetTo(typeAsLowerCaseString);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -373,7 +421,7 @@ void BMailComponent::_ReservedComponent5() {}
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
BTextMailComponent::BTextMailComponent(const char *text, uint32 defaultCharSet)
|
BTextMailComponent::BTextMailComponent(const char* text, uint32 defaultCharSet)
|
||||||
: BMailComponent(defaultCharSet),
|
: BMailComponent(defaultCharSet),
|
||||||
encoding(quoted_printable),
|
encoding(quoted_printable),
|
||||||
charset(B_ISO15_CONVERSION),
|
charset(B_ISO15_CONVERSION),
|
||||||
@@ -382,43 +430,62 @@ BTextMailComponent::BTextMailComponent(const char *text, uint32 defaultCharSet)
|
|||||||
if (text != NULL)
|
if (text != NULL)
|
||||||
SetText(text);
|
SetText(text);
|
||||||
|
|
||||||
SetHeaderField("MIME-Version","1.0");
|
SetHeaderField("MIME-Version", "1.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BTextMailComponent::~BTextMailComponent()
|
BTextMailComponent::~BTextMailComponent()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTextMailComponent::SetEncoding(mail_encoding encoding, int32 charset) {
|
|
||||||
|
void
|
||||||
|
BTextMailComponent::SetEncoding(mail_encoding encoding, int32 charset)
|
||||||
|
{
|
||||||
this->encoding = encoding;
|
this->encoding = encoding;
|
||||||
this->charset = charset;
|
this->charset = charset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTextMailComponent::SetText(const char *text) {
|
|
||||||
|
void
|
||||||
|
BTextMailComponent::SetText(const char* text)
|
||||||
|
{
|
||||||
this->text.SetTo(text);
|
this->text.SetTo(text);
|
||||||
|
|
||||||
raw_data = NULL;
|
raw_data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTextMailComponent::AppendText(const char *text) {
|
|
||||||
|
void
|
||||||
|
BTextMailComponent::AppendText(const char* text)
|
||||||
|
{
|
||||||
ParseRaw();
|
ParseRaw();
|
||||||
|
|
||||||
this->text << text;
|
this->text << text;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *BTextMailComponent::Text() {
|
|
||||||
|
const char*
|
||||||
|
BTextMailComponent::Text()
|
||||||
|
{
|
||||||
ParseRaw();
|
ParseRaw();
|
||||||
|
|
||||||
return text.String();
|
return text.String();
|
||||||
}
|
}
|
||||||
|
|
||||||
BString *BTextMailComponent::BStringText() {
|
|
||||||
|
BString*
|
||||||
|
BTextMailComponent::BStringText()
|
||||||
|
{
|
||||||
ParseRaw();
|
ParseRaw();
|
||||||
|
|
||||||
return &text;
|
return &text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTextMailComponent::Quote(const char *message, const char *quote_style) {
|
|
||||||
|
void
|
||||||
|
BTextMailComponent::Quote(const char* message, const char* quote_style)
|
||||||
|
{
|
||||||
ParseRaw();
|
ParseRaw();
|
||||||
|
|
||||||
BString string;
|
BString string;
|
||||||
@@ -430,23 +497,26 @@ void BTextMailComponent::Quote(const char *message, const char *quote_style) {
|
|||||||
text.Prepend(string.String());
|
text.Prepend(string.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t BTextMailComponent::GetDecodedData(BPositionIO *data) {
|
|
||||||
|
status_t
|
||||||
|
BTextMailComponent::GetDecodedData(BPositionIO* data)
|
||||||
|
{
|
||||||
ParseRaw();
|
ParseRaw();
|
||||||
|
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
return B_IO_ERROR;
|
return B_IO_ERROR;
|
||||||
|
|
||||||
BMimeType type;
|
BMimeType type;
|
||||||
BMimeType textAny ("text");
|
BMimeType textAny("text");
|
||||||
ssize_t written;
|
ssize_t written;
|
||||||
if (MIMEType(&type) == B_OK && textAny.Contains (&type))
|
if (MIMEType(&type) == B_OK && textAny.Contains(&type))
|
||||||
// Write out the string which has been both decoded from quoted
|
// Write out the string which has been both decoded from quoted
|
||||||
// printable or base64 etc, and then converted to UTF-8 from whatever
|
// printable or base64 etc, and then converted to UTF-8 from whatever
|
||||||
// character set the message specified. Do it for text/html,
|
// character set the message specified. Do it for text/html,
|
||||||
// text/plain and all other text datatypes. Of course, if the message
|
// text/plain and all other text datatypes. Of course, if the message
|
||||||
// is HTML and specifies a META tag for a character set, it will now be
|
// is HTML and specifies a META tag for a character set, it will now be
|
||||||
// wrong. But then we don't display HTML in BeMail, yet.
|
// wrong. But then we don't display HTML in BeMail, yet.
|
||||||
written = data->Write(text.String(),text.Length());
|
written = data->Write(text.String(), text.Length());
|
||||||
else
|
else
|
||||||
// Just write out whatever the binary contents are, only decoded from
|
// Just write out whatever the binary contents are, only decoded from
|
||||||
// the quoted printable etc format.
|
// the quoted printable etc format.
|
||||||
@@ -455,11 +525,14 @@ status_t BTextMailComponent::GetDecodedData(BPositionIO *data) {
|
|||||||
return written >= 0 ? B_OK : written;
|
return written >= 0 ? B_OK : written;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t BTextMailComponent::SetDecodedData(BPositionIO *data) {
|
|
||||||
|
status_t
|
||||||
|
BTextMailComponent::SetDecodedData(BPositionIO* data)
|
||||||
|
{
|
||||||
char buffer[255];
|
char buffer[255];
|
||||||
size_t buf_len;
|
size_t buf_len;
|
||||||
|
|
||||||
while ((buf_len = data->Read(buffer,254)) > 0) {
|
while ((buf_len = data->Read(buffer, 254)) > 0) {
|
||||||
buffer[buf_len] = 0;
|
buffer[buf_len] = 0;
|
||||||
this->text << buffer;
|
this->text << buffer;
|
||||||
}
|
}
|
||||||
@@ -471,7 +544,7 @@ status_t BTextMailComponent::SetDecodedData(BPositionIO *data) {
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BTextMailComponent::SetToRFC822(BPositionIO *data, size_t length, bool parseNow)
|
BTextMailComponent::SetToRFC822(BPositionIO* data, size_t length, bool parseNow)
|
||||||
{
|
{
|
||||||
off_t position = data->Position();
|
off_t position = data->Position();
|
||||||
BMailComponent::SetToRFC822(data, length);
|
BMailComponent::SetToRFC822(data, length);
|
||||||
@@ -508,13 +581,13 @@ BTextMailComponent::ParseRaw()
|
|||||||
|
|
||||||
charset = _charSetForTextDecoding;
|
charset = _charSetForTextDecoding;
|
||||||
if (charset == B_MAIL_NULL_CONVERSION && content_type.HasString("charset")) {
|
if (charset == B_MAIL_NULL_CONVERSION && content_type.HasString("charset")) {
|
||||||
const char * charset_string = content_type.FindString("charset");
|
const char* charset_string = content_type.FindString("charset");
|
||||||
if (strcasecmp(charset_string, "us-ascii") == 0) {
|
if (strcasecmp(charset_string, "us-ascii") == 0) {
|
||||||
charset = B_MAIL_US_ASCII_CONVERSION;
|
charset = B_MAIL_US_ASCII_CONVERSION;
|
||||||
} else if (strcasecmp(charset_string, "utf-8") == 0) {
|
} else if (strcasecmp(charset_string, "utf-8") == 0) {
|
||||||
charset = B_MAIL_UTF8_CONVERSION;
|
charset = B_MAIL_UTF8_CONVERSION;
|
||||||
} else {
|
} else {
|
||||||
const BCharacterSet * cs = BCharacterSetRoster::FindCharacterSetByName(charset_string);
|
const BCharacterSet* cs = BCharacterSetRoster::FindCharacterSetByName(charset_string);
|
||||||
if (cs != NULL) {
|
if (cs != NULL) {
|
||||||
charset = cs->GetConversionID();
|
charset = cs->GetConversionID();
|
||||||
}
|
}
|
||||||
@@ -523,7 +596,7 @@ BTextMailComponent::ParseRaw()
|
|||||||
|
|
||||||
encoding = encoding_for_cte(HeaderField("Content-Transfer-Encoding"));
|
encoding = encoding_for_cte(HeaderField("Content-Transfer-Encoding"));
|
||||||
|
|
||||||
char *buffer = (char *)malloc(raw_length + 1);
|
char* buffer = (char*)malloc(raw_length + 1);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -531,15 +604,16 @@ BTextMailComponent::ParseRaw()
|
|||||||
if ((bytes = raw_data->Read(buffer, raw_length)) < 0)
|
if ((bytes = raw_data->Read(buffer, raw_length)) < 0)
|
||||||
return B_IO_ERROR;
|
return B_IO_ERROR;
|
||||||
|
|
||||||
char *string = decoded.LockBuffer(bytes + 1);
|
char* string = decoded.LockBuffer(bytes + 1);
|
||||||
bytes = decode(encoding, string, buffer, bytes, 0);
|
bytes = decode(encoding, string, buffer, bytes, 0);
|
||||||
free (buffer);
|
free(buffer);
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
|
|
||||||
// Change line ends from \r\n to just \n. Though this won't work properly
|
// Change line ends from \r\n to just \n. Though this won't work properly
|
||||||
// for UTF-16 because \r takes up two bytes rather than one.
|
// for UTF-16 because \r takes up two bytes rather than one.
|
||||||
char *dest, *src;
|
char* dest;
|
||||||
char *end = string + bytes;
|
char* src;
|
||||||
|
char* end = string + bytes;
|
||||||
for (dest = src = string; src < end; src++) {
|
for (dest = src = string; src < end; src++) {
|
||||||
if (*src != '\r')
|
if (*src != '\r')
|
||||||
*dest++ = *src;
|
*dest++ = *src;
|
||||||
@@ -562,7 +636,8 @@ BTextMailComponent::ParseRaw()
|
|||||||
int32 state = 0;
|
int32 state = 0;
|
||||||
int32 destLength = bytes * 3 /* in case it grows */ + 1 /* +1 so it isn't zero which crashes */;
|
int32 destLength = bytes * 3 /* in case it grows */ + 1 /* +1 so it isn't zero which crashes */;
|
||||||
string = text.LockBuffer(destLength);
|
string = text.LockBuffer(destLength);
|
||||||
mail_convert_to_utf8(charset, decoded.String(), &bytes, string, &destLength, &state);
|
mail_convert_to_utf8(charset, decoded.String(), &bytes, string,
|
||||||
|
&destLength, &state);
|
||||||
if (destLength > 0)
|
if (destLength > 0)
|
||||||
text.UnlockBuffer(destLength);
|
text.UnlockBuffer(destLength);
|
||||||
else {
|
else {
|
||||||
@@ -576,7 +651,7 @@ BTextMailComponent::ParseRaw()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BTextMailComponent::RenderToRFC822(BPositionIO *render_to)
|
BTextMailComponent::RenderToRFC822(BPositionIO* render_to)
|
||||||
{
|
{
|
||||||
status_t status = ParseRaw();
|
status_t status = ParseRaw();
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
@@ -596,7 +671,7 @@ BTextMailComponent::RenderToRFC822(BPositionIO *render_to)
|
|||||||
|
|
||||||
SetHeaderField("Content-Type", content_type.String());
|
SetHeaderField("Content-Type", content_type.String());
|
||||||
|
|
||||||
const char *transfer_encoding = NULL;
|
const char* transfer_encoding = NULL;
|
||||||
switch (encoding) {
|
switch (encoding) {
|
||||||
case base64:
|
case base64:
|
||||||
transfer_encoding = "base64";
|
transfer_encoding = "base64";
|
||||||
@@ -613,7 +688,7 @@ BTextMailComponent::RenderToRFC822(BPositionIO *render_to)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetHeaderField("Content-Transfer-Encoding",transfer_encoding);
|
SetHeaderField("Content-Transfer-Encoding", transfer_encoding);
|
||||||
|
|
||||||
BMailComponent::RenderToRFC822(render_to);
|
BMailComponent::RenderToRFC822(render_to);
|
||||||
|
|
||||||
@@ -627,26 +702,27 @@ BTextMailComponent::RenderToRFC822(BPositionIO *render_to)
|
|||||||
// each character (which could just be 2 bytes in UTF-8, or even 1 byte
|
// each character (which could just be 2 bytes in UTF-8, or even 1 byte
|
||||||
// if it's regular ASCII), so it can get quite a bit larger than the
|
// if it's regular ASCII), so it can get quite a bit larger than the
|
||||||
// original text. Multiplying by 5 should make more than enough space.
|
// original text. Multiplying by 5 should make more than enough space.
|
||||||
char *raw = alt.LockBuffer(dest_len);
|
char* raw = alt.LockBuffer(dest_len);
|
||||||
int32 state = 0;
|
int32 state = 0;
|
||||||
mail_convert_from_utf8(charset,this->text.String(),&len,raw,&dest_len,&state);
|
mail_convert_from_utf8(charset, this->text.String(), &len, raw,
|
||||||
|
&dest_len, &state);
|
||||||
alt.UnlockBuffer(dest_len);
|
alt.UnlockBuffer(dest_len);
|
||||||
|
|
||||||
raw = modified.LockBuffer((alt.Length()*3)+1);
|
raw = modified.LockBuffer((alt.Length() * 3) + 1);
|
||||||
switch (encoding) {
|
switch (encoding) {
|
||||||
case base64:
|
case base64:
|
||||||
len = encode_base64(raw,alt.String(),alt.Length(),false);
|
len = encode_base64(raw, alt.String(), alt.Length(), false);
|
||||||
raw[len] = 0;
|
raw[len] = 0;
|
||||||
break;
|
break;
|
||||||
case quoted_printable:
|
case quoted_printable:
|
||||||
len = encode_qp(raw,alt.String(),alt.Length(),false);
|
len = encode_qp(raw, alt.String(), alt.Length(), false);
|
||||||
raw[len] = 0;
|
raw[len] = 0;
|
||||||
break;
|
break;
|
||||||
case eight_bit:
|
case eight_bit:
|
||||||
case seven_bit:
|
case seven_bit:
|
||||||
default:
|
default:
|
||||||
len = alt.Length();
|
len = alt.Length();
|
||||||
strcpy(raw,alt.String());
|
strcpy(raw, alt.String());
|
||||||
}
|
}
|
||||||
modified.UnlockBuffer(len);
|
modified.UnlockBuffer(len);
|
||||||
|
|
||||||
@@ -656,9 +732,8 @@ BTextMailComponent::RenderToRFC822(BPositionIO *render_to)
|
|||||||
// There seem to be a possibility of NULL bytes in the text, so lets
|
// There seem to be a possibility of NULL bytes in the text, so lets
|
||||||
// filter them out, shouldn't be any after the encoding stage.
|
// filter them out, shouldn't be any after the encoding stage.
|
||||||
|
|
||||||
char *string = modified.LockBuffer(modified.Length());
|
char* string = modified.LockBuffer(modified.Length());
|
||||||
for (int32 i = modified.Length();i-- > 0;)
|
for (int32 i = modified.Length(); i-- > 0;) {
|
||||||
{
|
|
||||||
if (string[i] != '\0')
|
if (string[i] != '\0')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -694,7 +769,7 @@ BTextMailComponent::RenderToRFC822(BPositionIO *render_to)
|
|||||||
}
|
}
|
||||||
modified << "\r\n";
|
modified << "\r\n";
|
||||||
|
|
||||||
render_to->Write(modified.String(),modified.Length());
|
render_to->Write(modified.String(), modified.Length());
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user