* Cleanup - this is very ugly code, and the API is also not really good; we

really should get rid of the current mail kit some day.
* Fixed another memory leak I stumpled upon.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38245 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2010-08-18 18:20:42 +00:00
parent 02b5d2e4e3
commit 6ec5758fe7

View File

@ -1,34 +1,34 @@
/* BMailAttachment - classes which handle mail attachments
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
/*
* Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
#include <DataIO.h>
#include <String.h>
#include <File.h>
#include <Entry.h>
#include <Mime.h>
#include <ByteOrder.h>
#include <NodeInfo.h>
/*! Classes which handle mail attachments */
#include <MailAttachment.h>
#include <stdlib.h>
#include <stdio.h>
#include <ByteOrder.h>
#include <DataIO.h>
#include <Entry.h>
#include <File.h>
#include <Mime.h>
#include <NodeInfo.h>
#include <String.h>
#include <AutoDeleter.h>
class _EXPORT BSimpleMailAttachment;
class _EXPORT BAttributedMailAttachment;
class _EXPORT BMailAttachment;
#include <MailAttachment.h>
#include <mail_encoding.h>
#include <NodeMessage.h>
//--------------BSimpleMailAttachment-No attributes or awareness of the file system at large-----
/*! No attributes or awareness of the file system at large
*/
BSimpleMailAttachment::BSimpleMailAttachment()
: BMailAttachment(),
:
fStatus(B_NO_INIT),
_data(NULL),
_raw_data(NULL),
@ -37,8 +37,10 @@ BSimpleMailAttachment::BSimpleMailAttachment()
Initialize(base64);
}
BSimpleMailAttachment::BSimpleMailAttachment(BPositionIO *data, mail_encoding encoding)
: BMailAttachment(),
BSimpleMailAttachment::BSimpleMailAttachment(BPositionIO *data,
mail_encoding encoding)
:
_data(data),
_raw_data(NULL),
_we_own_data(false)
@ -48,8 +50,10 @@ BSimpleMailAttachment::BSimpleMailAttachment(BPositionIO *data, mail_encoding en
Initialize(encoding);
}
BSimpleMailAttachment::BSimpleMailAttachment(const void *data, size_t length, mail_encoding encoding)
: BMailAttachment(),
BSimpleMailAttachment::BSimpleMailAttachment(const void *data, size_t length,
mail_encoding encoding)
:
_data(new BMemoryIO(data,length)),
_raw_data(NULL),
_we_own_data(true)
@ -59,18 +63,20 @@ BSimpleMailAttachment::BSimpleMailAttachment(const void *data, size_t length, ma
Initialize(encoding);
}
BSimpleMailAttachment::BSimpleMailAttachment(BFile *file, bool delete_when_done)
: BMailAttachment(),
BSimpleMailAttachment::BSimpleMailAttachment(BFile *file, bool deleteWhenDone)
:
_data(NULL),
_raw_data(NULL),
_we_own_data(false)
{
Initialize(base64);
SetTo(file,delete_when_done);
SetTo(file, deleteWhenDone);
}
BSimpleMailAttachment::BSimpleMailAttachment(entry_ref *ref)
: BMailAttachment(),
:
_data(NULL),
_raw_data(NULL),
_we_own_data(false)
@ -79,19 +85,24 @@ BSimpleMailAttachment::BSimpleMailAttachment(entry_ref *ref)
SetTo(ref);
}
BSimpleMailAttachment::~BSimpleMailAttachment()
{
if (_we_own_data)
delete _data;
}
void BSimpleMailAttachment::Initialize(mail_encoding encoding)
void
BSimpleMailAttachment::Initialize(mail_encoding encoding)
{
SetEncoding(encoding);
SetHeaderField("Content-Disposition","BMailAttachment");
}
status_t BSimpleMailAttachment::SetTo(BFile *file, bool delete_file_when_done)
status_t
BSimpleMailAttachment::SetTo(BFile *file, bool deleteFileWhenDone)
{
char type[B_MIME_TYPE_LENGTH] = "application/octet-stream";
@ -99,11 +110,11 @@ status_t BSimpleMailAttachment::SetTo(BFile *file, bool delete_file_when_done)
if (nodeInfo.InitCheck() == B_OK)
nodeInfo.GetType(type);
SetHeaderField("Content-Type",type);
//---No way to get file name (see SetTo(entry_ref *))
SetHeaderField("Content-Type", type);
// TODO: No way to get file name (see SetTo(entry_ref *))
//SetFileName(ref->name);
if (delete_file_when_done)
if (deleteFileWhenDone)
SetDecodedDataAndDeleteWhenDone(file);
else
SetDecodedData(file);
@ -111,71 +122,76 @@ status_t BSimpleMailAttachment::SetTo(BFile *file, bool delete_file_when_done)
return fStatus = B_OK;
}
status_t BSimpleMailAttachment::SetTo(entry_ref *ref)
{
BFile *file = new BFile(ref,B_READ_ONLY);
if ((fStatus = file->InitCheck()) < B_OK)
{
status_t
BSimpleMailAttachment::SetTo(entry_ref *ref)
{
BFile *file = new BFile(ref, B_READ_ONLY);
if ((fStatus = file->InitCheck()) < B_OK) {
delete file;
return fStatus;
}
if (SetTo(file,true) < B_OK)
// fStatus is set by SetTo()
if (SetTo(file, true) != B_OK)
return fStatus;
SetFileName(ref->name);
return fStatus = B_OK;
}
status_t BSimpleMailAttachment::InitCheck()
status_t
BSimpleMailAttachment::InitCheck()
{
return fStatus;
}
status_t BSimpleMailAttachment::FileName(char *text) {
BMessage content_type;
HeaderField("Content-Type",&content_type);
const char *fileName = content_type.FindString("name");
status_t
BSimpleMailAttachment::FileName(char *text)
{
BMessage contentType;
HeaderField("Content-Type", &contentType);
const char *fileName = contentType.FindString("name");
if (!fileName)
fileName = content_type.FindString("filename");
if (!fileName)
{
content_type.MakeEmpty();
HeaderField("Content-Disposition",&content_type);
fileName = content_type.FindString("name");
fileName = contentType.FindString("filename");
if (!fileName) {
contentType.MakeEmpty();
HeaderField("Content-Disposition", &contentType);
fileName = contentType.FindString("name");
}
if (!fileName)
fileName = content_type.FindString("filename");
if (!fileName)
{
content_type.MakeEmpty();
HeaderField("Content-Location",&content_type);
fileName = content_type.FindString("unlabeled");
fileName = contentType.FindString("filename");
if (!fileName) {
contentType.MakeEmpty();
HeaderField("Content-Location", &contentType);
fileName = contentType.FindString("unlabeled");
}
if (!fileName)
return B_NAME_NOT_FOUND;
strncpy(text,fileName,B_FILE_NAME_LENGTH);
strncpy(text, fileName, B_FILE_NAME_LENGTH);
return B_OK;
}
void BSimpleMailAttachment::SetFileName(const char *name) {
BMessage content_type;
void
BSimpleMailAttachment::SetFileName(const char *name)
{
BMessage contentType;
HeaderField("Content-Type", &contentType);
HeaderField("Content-Type",&content_type);
if (content_type.ReplaceString("name",name) != B_OK)
content_type.AddString("name",name);
if (contentType.ReplaceString("name", name) != B_OK)
contentType.AddString("name", name);
// Request that the file name header be encoded in UTF-8 if it has weird
// characters. If it is just a plain name, the header will appear normal.
if (content_type.ReplaceInt32(kHeaderCharsetString, B_MAIL_UTF8_CONVERSION) != B_OK)
content_type.AddInt32(kHeaderCharsetString, B_MAIL_UTF8_CONVERSION);
if (contentType.ReplaceInt32(kHeaderCharsetString, B_MAIL_UTF8_CONVERSION)
!= B_OK)
contentType.AddInt32(kHeaderCharsetString, B_MAIL_UTF8_CONVERSION);
SetHeaderField ("Content-Type", &content_type);
SetHeaderField ("Content-Type", &contentType);
}
@ -193,8 +209,8 @@ BSimpleMailAttachment::GetDecodedData(BPositionIO *data)
ssize_t length;
_data->Seek(0,SEEK_SET);
while ((length = _data->Read(buffer,sizeof(buffer))) > 0)
data->Write(buffer,length);
while ((length = _data->Read(buffer, sizeof(buffer))) > 0)
data->Write(buffer, length);
return B_OK;
}
@ -204,11 +220,13 @@ BPositionIO *
BSimpleMailAttachment::GetDecodedData()
{
ParseNow();
return _data;
}
status_t BSimpleMailAttachment::SetDecodedDataAndDeleteWhenDone(BPositionIO *data) {
status_t
BSimpleMailAttachment::SetDecodedDataAndDeleteWhenDone(BPositionIO *data)
{
_raw_data = NULL;
if (_we_own_data)
@ -220,7 +238,10 @@ status_t BSimpleMailAttachment::SetDecodedDataAndDeleteWhenDone(BPositionIO *dat
return B_OK;
}
status_t BSimpleMailAttachment::SetDecodedData(BPositionIO *data) {
status_t
BSimpleMailAttachment::SetDecodedData(BPositionIO *data)
{
_raw_data = NULL;
if (_we_own_data)
@ -232,7 +253,10 @@ status_t BSimpleMailAttachment::SetDecodedData(BPositionIO *data) {
return B_OK;
}
status_t BSimpleMailAttachment::SetDecodedData(const void *data, size_t length) {
status_t
BSimpleMailAttachment::SetDecodedData(const void *data, size_t length)
{
_raw_data = NULL;
if (_we_own_data)
@ -244,7 +268,10 @@ status_t BSimpleMailAttachment::SetDecodedData(const void *data, size_t length)
return B_OK;
}
void BSimpleMailAttachment::SetEncoding(mail_encoding encoding) {
void
BSimpleMailAttachment::SetEncoding(mail_encoding encoding)
{
_encoding = encoding;
const char *cte = NULL; //--Content Transfer Encoding
@ -270,20 +297,27 @@ void BSimpleMailAttachment::SetEncoding(mail_encoding encoding) {
break;
}
SetHeaderField("Content-Transfer-Encoding",cte);
SetHeaderField("Content-Transfer-Encoding", cte);
}
mail_encoding BSimpleMailAttachment::Encoding() {
mail_encoding
BSimpleMailAttachment::Encoding()
{
return _encoding;
}
status_t BSimpleMailAttachment::SetToRFC822(BPositionIO *data, size_t length, bool parse_now) {
status_t
BSimpleMailAttachment::SetToRFC822(BPositionIO *data, size_t length,
bool parseNow)
{
//---------Massive memory squandering!---ALERT!----------
if (_we_own_data)
delete _data;
off_t position = data->Position();
BMailComponent::SetToRFC822(data,length,parse_now);
BMailComponent::SetToRFC822(data, length, parseNow);
// this actually happens...
if (data->Position() - position > length)
@ -309,25 +343,33 @@ status_t BSimpleMailAttachment::SetToRFC822(BPositionIO *data, size_t length, bo
else
_encoding = no_encoding;
if (parse_now)
if (parseNow)
ParseNow();
return B_OK;
}
void BSimpleMailAttachment::ParseNow() {
void
BSimpleMailAttachment::ParseNow()
{
if (_raw_data == NULL || _raw_length == 0)
return;
_raw_data->Seek(_raw_offset,SEEK_SET);
_raw_data->Seek(_raw_offset, SEEK_SET);
char *src = (char *)malloc(_raw_length);
if (src == NULL)
return;
size_t size = _raw_length;
size = _raw_data->Read(src,_raw_length);
size = _raw_data->Read(src, _raw_length);
BMallocIO *buffer = new BMallocIO;
buffer->SetSize(size); //-------8bit is *always* more efficient than an encoding, so the buffer will *never* be larger than before
buffer->SetSize(size);
// 8bit is *always* more efficient than an encoding, so the buffer
// will *never* be larger than before
size = decode(_encoding,(char *)(buffer->Buffer()),src,size,0);
free(src);
@ -342,13 +384,15 @@ void BSimpleMailAttachment::ParseNow() {
return;
}
status_t BSimpleMailAttachment::RenderToRFC822(BPositionIO *render_to) {
ParseNow();
BMailComponent::RenderToRFC822(render_to);
//---------Massive memory squandering!---ALERT!----------
// now with error checks, dumb :-) -- axeld.
_data->Seek(0,SEEK_END);
status_t
BSimpleMailAttachment::RenderToRFC822(BPositionIO *renderTo)
{
ParseNow();
BMailComponent::RenderToRFC822(renderTo);
//---------Massive memory squandering!---ALERT!----------
_data->Seek(0, SEEK_END);
off_t size = _data->Position();
char *src = (char *)malloc(size);
if (src == NULL)
@ -356,16 +400,16 @@ status_t BSimpleMailAttachment::RenderToRFC822(BPositionIO *render_to) {
MemoryDeleter sourceDeleter(src);
_data->Seek(0,SEEK_SET);
_data->Seek(0, SEEK_SET);
ssize_t read = _data->Read(src,size);
ssize_t read = _data->Read(src, size);
if (read < B_OK)
return read;
// The encoded text will never be more than twice as large with any
// conceivable encoding. But just in case, there's a function call which
// will tell us how much space is needed.
ssize_t destSize = max_encoded_length(_encoding,read);
ssize_t destSize = max_encoded_length(_encoding, read);
if (destSize < B_OK) // Invalid encodings like uuencode rejected here.
return destSize;
char *dest = (char *)malloc(destSize);
@ -379,18 +423,19 @@ status_t BSimpleMailAttachment::RenderToRFC822(BPositionIO *render_to) {
return destSize;
if (destSize > 0)
read = render_to->Write(dest,destSize);
read = renderTo->Write(dest, destSize);
return (read > 0) ? B_OK : read;
return read > 0 ? B_OK : read;
}
//-------BAttributedMailAttachment--Awareness of bfs, sends attributes--
// #pragma mark -
/*! Supports and sends attributes.
*/
BAttributedMailAttachment::BAttributedMailAttachment()
: BMailAttachment(),
:
fContainer(NULL),
fStatus(B_NO_INIT),
_data(NULL),
@ -398,17 +443,20 @@ BAttributedMailAttachment::BAttributedMailAttachment()
{
}
BAttributedMailAttachment::BAttributedMailAttachment(BFile *file, bool delete_when_done)
: BMailAttachment(),
BAttributedMailAttachment::BAttributedMailAttachment(BFile *file,
bool deleteWhenDone)
:
fContainer(NULL),
_data(NULL),
_attributes_attach(NULL)
{
SetTo(file,delete_when_done);
SetTo(file, deleteWhenDone);
}
BAttributedMailAttachment::BAttributedMailAttachment(entry_ref *ref)
: BMailAttachment(),
:
fContainer(NULL),
_data(NULL),
_attributes_attach(NULL)
@ -416,13 +464,16 @@ BAttributedMailAttachment::BAttributedMailAttachment(entry_ref *ref)
SetTo(ref);
}
BAttributedMailAttachment::~BAttributedMailAttachment() {
BAttributedMailAttachment::~BAttributedMailAttachment()
{
// Our SimpleAttachments are deleted by fContainer
delete fContainer;
}
status_t BAttributedMailAttachment::Initialize()
status_t
BAttributedMailAttachment::Initialize()
{
// _data & _attributes_attach will be deleted by the container
delete fContainer;
@ -434,21 +485,23 @@ status_t BAttributedMailAttachment::Initialize()
_attributes_attach = new BSimpleMailAttachment();
_attributes.MakeEmpty();
_attributes_attach->SetHeaderField("Content-Type","application/x-be_attribute; name=\"BeOS Attributes\"");
_attributes_attach->SetHeaderField("Content-Type",
"application/x-be_attribute; name=\"BeOS Attributes\"");
fContainer->AddComponent(_attributes_attach);
fContainer->SetHeaderField("Content-Type","multipart/x-bfile");
fContainer->SetHeaderField("Content-Disposition","BMailAttachment");
fContainer->SetHeaderField("Content-Type", "multipart/x-bfile");
fContainer->SetHeaderField("Content-Disposition", "BMailAttachment");
// also set the header fields of this component, in case someone asks
SetHeaderField("Content-Type","multipart/x-bfile");
SetHeaderField("Content-Disposition","BMailAttachment");
SetHeaderField("Content-Type", "multipart/x-bfile");
SetHeaderField("Content-Disposition", "BMailAttachment");
return B_OK;
}
status_t BAttributedMailAttachment::SetTo(BFile *file, bool delete_file_when_done)
status_t
BAttributedMailAttachment::SetTo(BFile *file, bool deleteFileWhenDone)
{
if (file == NULL)
return fStatus = B_BAD_VALUE;
@ -458,21 +511,24 @@ status_t BAttributedMailAttachment::SetTo(BFile *file, bool delete_file_when_don
_attributes << *file;
if ((fStatus = _data->SetTo(file,delete_file_when_done)) < B_OK)
if ((fStatus = _data->SetTo(file, deleteFileWhenDone)) < B_OK)
return fStatus;
// Set boundary
//---Also, we have the make up the boundary out of whole cloth
//------This is likely to give a completely random string---
// Also, we have the make up the boundary out of whole cloth
// This is likely to give a completely random string
BString boundary;
boundary << "BFile--" << (int32(file) ^ time(NULL)) << "-" << ~((int32)file ^ (int32)&fStatus ^ (int32)&_attributes) << "--";
boundary << "BFile--" << (int32(file) ^ time(NULL)) << "-"
<< ~((int32)file ^ (int32)&fStatus ^ (int32)&_attributes) << "--";
fContainer->SetBoundary(boundary.String());
return fStatus = B_OK;
}
status_t BAttributedMailAttachment::SetTo(entry_ref *ref)
status_t
BAttributedMailAttachment::SetTo(entry_ref *ref)
{
if (ref == NULL)
return fStatus = B_BAD_VALUE;
@ -491,36 +547,42 @@ status_t BAttributedMailAttachment::SetTo(entry_ref *ref)
// Set boundary
//------This is likely to give a completely random string---
// This is likely to give a completely random string
BString boundary;
char buffer[512];
strcpy(buffer, ref->name);
for (int32 i = strlen(buffer);i-- > 0;)
{
for (int32 i = strlen(buffer); i-- > 0;) {
if (buffer[i] & 0x80)
buffer[i] = 'x';
else if (buffer[i] == ' ' || buffer[i] == ':')
buffer[i] = '_';
}
buffer[32] = '\0';
boundary << "BFile-" << buffer << "--" << ((int32)_data ^ time(NULL)) << "-" << ~((int32)_data ^ (int32)&buffer ^ (int32)&_attributes) << "--";
boundary << "BFile-" << buffer << "--" << ((int32)_data ^ time(NULL))
<< "-" << ~((int32)_data ^ (int32)&buffer ^ (int32)&_attributes)
<< "--";
fContainer->SetBoundary(boundary.String());
return fStatus = B_OK;
}
status_t BAttributedMailAttachment::InitCheck()
status_t
BAttributedMailAttachment::InitCheck()
{
return fStatus;
}
void BAttributedMailAttachment::SaveToDisk(BEntry *entry) {
void
BAttributedMailAttachment::SaveToDisk(BEntry *entry)
{
BString path = "/tmp/";
char name[255] = "";
_data->FileName(name);
path << name;
BFile file(path.String(),B_READ_WRITE | B_CREATE_FILE);
BFile file(path.String(), B_READ_WRITE | B_CREATE_FILE);
(BNode&)file << _attributes;
_data->GetDecodedData(&file);
file.Sync();
@ -528,25 +590,40 @@ void BAttributedMailAttachment::SaveToDisk(BEntry *entry) {
entry->SetTo(path.String());
}
void BAttributedMailAttachment::SetEncoding(mail_encoding encoding) {
void
BAttributedMailAttachment::SetEncoding(mail_encoding encoding)
{
_data->SetEncoding(encoding);
if (_attributes_attach != NULL)
_attributes_attach->SetEncoding(encoding);
}
mail_encoding BAttributedMailAttachment::Encoding() {
mail_encoding
BAttributedMailAttachment::Encoding()
{
return _data->Encoding();
}
status_t BAttributedMailAttachment::FileName(char *name) {
status_t
BAttributedMailAttachment::FileName(char *name)
{
return _data->FileName(name);
}
void BAttributedMailAttachment::SetFileName(const char *name) {
void
BAttributedMailAttachment::SetFileName(const char *name)
{
_data->SetFileName(name);
}
status_t BAttributedMailAttachment::GetDecodedData(BPositionIO *data) {
status_t
BAttributedMailAttachment::GetDecodedData(BPositionIO *data)
{
BNode *node = dynamic_cast<BNode *>(data);
if (node != NULL)
*node << _attributes;
@ -555,7 +632,10 @@ status_t BAttributedMailAttachment::GetDecodedData(BPositionIO *data) {
return B_OK;
}
status_t BAttributedMailAttachment::SetDecodedData(BPositionIO *data) {
status_t
BAttributedMailAttachment::SetDecodedData(BPositionIO *data)
{
BNode *node = dynamic_cast<BNode *>(data);
if (node != NULL)
_attributes << *node;
@ -564,39 +644,52 @@ status_t BAttributedMailAttachment::SetDecodedData(BPositionIO *data) {
return B_OK;
}
status_t BAttributedMailAttachment::SetToRFC822(BPositionIO *data, size_t length, bool parse_now)
status_t
BAttributedMailAttachment::SetToRFC822(BPositionIO *data, size_t length,
bool parseNow)
{
status_t err = Initialize();
if (err < B_OK)
return err;
err = fContainer->SetToRFC822(data,length,parse_now);
err = fContainer->SetToRFC822(data, length, parseNow);
if (err < B_OK)
return err;
BMimeType type;
fContainer->MIMEType(&type);
if (strcmp(type.Type(),"multipart/x-bfile") != 0)
if (strcmp(type.Type(), "multipart/x-bfile") != 0)
return B_BAD_TYPE;
// get data and attributes
if ((_data = dynamic_cast<BSimpleMailAttachment *>(fContainer->GetComponent(0))) == NULL)
if ((_data = dynamic_cast<BSimpleMailAttachment *>(
fContainer->GetComponent(0))) == NULL)
return B_BAD_VALUE;
if (parse_now)
_data->GetDecodedData(); // Force it to make a copy of the data. Needed for forwarding messages hack.
if ((_attributes_attach = dynamic_cast<BSimpleMailAttachment *>(fContainer->GetComponent(1))) == NULL
if (parseNow) {
// Force it to make a copy of the data. Needed for forwarding
// messages hack.
_data->GetDecodedData();
}
if ((_attributes_attach = dynamic_cast<BSimpleMailAttachment *>(
fContainer->GetComponent(1))) == NULL
|| _attributes_attach->GetDecodedData() == NULL)
return B_OK;
return B_OK;
// Convert the attribute binary attachment into a convenient easy to use BMessage.
// Convert the attribute binary attachment into a convenient easy to use
// BMessage.
int32 len = ((BMallocIO *)(_attributes_attach->GetDecodedData()))->BufferLength();
int32 len
= ((BMallocIO *)(_attributes_attach->GetDecodedData()))->BufferLength();
char *start = (char *)malloc(len);
if (start == NULL)
return B_NO_MEMORY;
if (_attributes_attach->GetDecodedData()->ReadAt(0,start,len) < len)
MemoryDeleter deleter(start);
if (_attributes_attach->GetDecodedData()->ReadAt(0, start, len) < len)
return B_IO_ERROR;
int32 index = 0;
@ -618,56 +711,64 @@ status_t BAttributedMailAttachment::SetToRFC822(BPositionIO *data, size_t length
_attributes.AddData(name, code, &start[index], buf_length);
index += buf_length;
}
free(start);
return B_OK;
}
status_t BAttributedMailAttachment::RenderToRFC822(BPositionIO *render_to) {
status_t
BAttributedMailAttachment::RenderToRFC822(BPositionIO *renderTo)
{
BMallocIO *io = new BMallocIO;
#if defined(HAIKU_TARGET_PLATFORM_DANO)
const
#endif
char *name;
type_code type, swap_typed;
for (int32 i = 0; _attributes.GetInfo(B_ANY_TYPE,i,&name,&type) == B_OK; i++) {
type_code type;
for (int32 i = 0; _attributes.GetInfo(B_ANY_TYPE, i, &name, &type) == B_OK;
i++) {
const void *data;
ssize_t dataLen;
_attributes.FindData(name,type,&data,&dataLen);
io->Write(name,strlen(name) + 1);
swap_typed = B_HOST_TO_BENDIAN_INT32(type);
io->Write(&swap_typed,sizeof(type_code));
_attributes.FindData(name, type, &data, &dataLen);
io->Write(name, strlen(name) + 1);
type_code swappedType = B_HOST_TO_BENDIAN_INT32(type);
io->Write(&swappedType, sizeof(type_code));
int64 length, swapped;
length = dataLen;
swapped = B_HOST_TO_BENDIAN_INT64(length);
io->Write(&swapped,sizeof(int64));
void *allocd = malloc(dataLen);
if (allocd == NULL) {
void *buffer = malloc(dataLen);
if (buffer == NULL) {
delete io;
return B_NO_MEMORY;
}
memcpy(allocd,data,dataLen);
swap_data(type, allocd, dataLen, B_SWAP_HOST_TO_BENDIAN);
io->Write(allocd,dataLen);
free(allocd);
memcpy(buffer, data, dataLen);
swap_data(type, buffer, dataLen, B_SWAP_HOST_TO_BENDIAN);
io->Write(buffer, dataLen);
free(buffer);
}
if (_attributes_attach == NULL)
_attributes_attach = new BSimpleMailAttachment;
_attributes_attach->SetDecodedDataAndDeleteWhenDone(io);
return fContainer->RenderToRFC822(render_to);
return fContainer->RenderToRFC822(renderTo);
}
status_t BAttributedMailAttachment::MIMEType(BMimeType *mime) {
status_t
BAttributedMailAttachment::MIMEType(BMimeType *mime)
{
return _data->MIMEType(mime);
}
// The reserved function stubs
// #pragma mark -
// #pragma mark - The reserved function stubs
void BMailAttachment::_ReservedAttachment1() {}
void BMailAttachment::_ReservedAttachment2() {}