예제 #1
0
BEmailMessage *
BEmailMessage::ForwardMessage(bool accountFromMail, bool includeAttachments)
{
	BString header = "------ Forwarded Message: ------\n";
	header << "To: " << To() << '\n';
	header << "From: " << From() << '\n';
	if (CC() != NULL) {
		// Can use CC rather than "Cc" since display only.
		header << "CC: " << CC() << '\n';
	}
	header << "Subject: " << Subject() << '\n';
	header << "Date: " << Date() << "\n\n";
	if (_text_body != NULL)
		header << _text_body->Text() << '\n';
	BEmailMessage *message = new BEmailMessage();
	message->SetBodyTextTo(header.String());

	// set the subject
	BString subject = Subject();
	if (subject.IFindFirst("fwd") == B_ERROR
		&& subject.IFindFirst("forward") == B_ERROR
		&& subject.FindFirst("FW") == B_ERROR)
		subject << " (fwd)";
	message->SetSubject(subject.String());

	if (includeAttachments) {
		for (int32 i = 0; i < CountComponents(); i++) {
			BMailComponent *cmpt = GetComponent(i);
			if (cmpt == _text_body || cmpt == NULL)
				continue;

			//---I am ashamed to have the written the code between here and the next comment
			// ... and you still managed to get it wrong ;-)), axeld.
			// we should really move this stuff into copy constructors
			// or something like that

			BMallocIO io;
			cmpt->RenderToRFC822(&io);
			BMailComponent *clone = cmpt->WhatIsThis();
			io.Seek(0, SEEK_SET);
			clone->SetToRFC822(&io, io.BufferLength(), true);
			message->AddComponent(clone);
		}
	}
	if (accountFromMail)
		message->SendViaAccountFrom(this);

	return message;
}
예제 #2
0
void 
TEnclosuresView::AddEnclosuresFromMail(BEmailMessage *mail)
{
	for (int32 i = 0; i < mail->CountComponents(); i++)
	{
		BMailComponent *component = mail->GetComponent(i);
		if (component == mail->Body())
			continue;
		
		if (component->ComponentType() == B_MAIL_MULTIPART_CONTAINER)
			recursive_attachment_search(this,dynamic_cast<BMIMEMultipartMailContainer *>(component),mail->Body());

		fList->AddItem(new TListItem(component));
	}
}
예제 #3
0
static void recursive_attachment_search(TEnclosuresView *us,BMailContainer *mail,BMailComponent *body) {
	if (mail == NULL)
		return;
	for (int32 i = 0; i < mail->CountComponents(); i++)
	{
		BMailComponent *component = mail->GetComponent(i);
		if (component == body)
			continue;
			
		if (component->ComponentType() == B_MAIL_MULTIPART_CONTAINER)
			recursive_attachment_search(us,dynamic_cast<BMIMEMultipartMailContainer *>(component),body);	

		us->fList->AddItem(new TListItem(component));
	}
}
예제 #4
0
status_t BMIMEMultipartMailContainer::RenderToRFC822(BPositionIO *render_to) {
	BMailComponent::RenderToRFC822(render_to);

	BString delimiter;
	delimiter << "\r\n--" << _boundary << "\r\n";

	if (_MIME_message_warning != NULL) {
		render_to->Write(_MIME_message_warning,strlen(_MIME_message_warning));
		render_to->Write("\r\n",2);
	}

	for (int32 i = 0; i < _components_in_code.CountItems() /* both have equal length, so pick one at random */; i++) {
		render_to->Write(delimiter.String(),delimiter.Length());
		if (_components_in_code.ItemAt(i) != NULL) { //---- _components_in_code has precedence

			BMailComponent *code = (BMailComponent *)_components_in_code.ItemAt(i);
			status_t status = code->RenderToRFC822(render_to); //----Easy enough
			if (status < B_OK)
				return status;
		} else {
			// copy message contents

			uint8 buffer[1024];
			ssize_t amountWritten, length;
			message_part *part = (message_part *)_components_in_raw.ItemAt(i);

			for (off_t begin = part->start; begin < part->end;
				begin += sizeof(buffer)) {
				length = (((off_t)part->end - begin) >= (off_t)sizeof(buffer))
					? sizeof(buffer) : (part->end - begin);

				_io_data->ReadAt(begin,buffer,length);
				amountWritten = render_to->Write(buffer,length);
				if (amountWritten < 0)
					return amountWritten; // IO error of some sort.
			}
		}
	}

	render_to->Write(delimiter.String(),delimiter.Length() - 2);	// strip CRLF
	render_to->Write("--\r\n",4);

	return B_OK;
}
예제 #5
0
bool
BEmailMessage::IsComponentAttachment(int32 i)
{
	if ((i >= _num_components) || (_num_components == 0))
		return false;

	if (_num_components == 1)
		return _body->IsAttachment();

	BMIMEMultipartMailContainer *container
		= dynamic_cast<BMIMEMultipartMailContainer *>(_body);
	if (container == NULL)
		return false;

	BMailComponent *component = container->GetComponent(i);
	if (component == NULL)
		return false;
	return component->IsAttachment();
}
예제 #6
0
BMailComponent *BMIMEMultipartMailContainer::GetComponent(int32 index, bool parse_now) {
	if (index >= CountComponents())
		return NULL;
	
	if (BMailComponent *component = (BMailComponent *)_components_in_code.ItemAt(index))
		return component;	//--- Handle easy case

	message_part *part = (message_part *)(_components_in_raw.ItemAt(index));
	if (part == NULL)
		return NULL;

	_io_data->Seek(part->start,SEEK_SET);

	BMailComponent component (_charSetForTextDecoding);
	if (component.SetToRFC822(_io_data,part->end - part->start) < B_OK)
		return NULL;

	BMailComponent *piece = component.WhatIsThis();

	/* Debug code
	_io_data->Seek(part->start,SEEK_SET);
	char *data = new char[part->end - part->start + 1];
	_io_data->Read(data,part->end - part->start);
	data[part->end - part->start] = 0;
	puts((char *)(data));
	printf("Instantiating from %d to %d (%d octets)\n",part->start, part->end, part->end - part->start);
	*/
	_io_data->Seek(part->start,SEEK_SET);
	if (piece->SetToRFC822(_io_data,part->end - part->start, parse_now) < B_OK)
	{
		delete piece;
		return NULL;
	}
	_components_in_code.ReplaceItem(index,piece);

	return piece;
}