library/src/network/email/BP-Email.cc
// Retrieve A Messages At The Specified Start Position, and Retrieve X Records
Retrieve A Messages At The Specified Start Position, and Retrieve X Records
Retrieve A Messages At The Specified Start Position and Retrieve X Records
BP_ERROR_T BP_RecieveMessagesFromSession(P_BP_EMAIL_SESSION email_session, size_t msg_start_number, size_t msg_retrieve_count)
{
	if(!email_session || !msg_retrieve_count)
		return ERR_FAILURE;
    vmime::ref <vmime::net::message> msg;
    MessageList * msgList = email_session->message_list;
    size_t i = msg_start_number;
    for(; i < msg_start_number + msg_retrieve_count; i++)
    {
    	msg = email_session->f->getMessage(i);
    	msgList->insert(MessageList::value_type(i, msg));
    	vmime::utility::outputStreamAdapter out(std::cout);
    	vmime::string email_content;
    	vmime::utility::outputStreamStringAdapter bufferStream(email_content);
    	msg->extract(bufferStream);
    	vmime::message * stored_parsed_message = new vmime::message;
    	stored_parsed_message->parse(email_content);
   		email_session->messages_fetched++;
   		email_session->messages = (P_BP_EMAIL_MESSAGE) bprealloc(email_session->messages, sizeof(BP_EMAIL_MESSAGE) * email_session->message_count);
   		memset(&email_session->messages[email_session->messages_fetched - 1], 0x00, sizeof(BP_EMAIL_MESSAGE));
   		BP_EMAIL_MESSAGE * current_message = &email_session->messages[email_session->messages_fetched - 1];
   		current_message->msg_inbox_number = i;
   		current_message->message          = bpstrdup((char *) email_content.c_str());
   		current_message->message_length   = email_content.length();
   		vmime::text outText;
   		vmime:: charset ch(vmime::charsets::UTF_8);
   		vmime:: charset ch2(vmime::charsets::UTF_8);
   		vmime::ref <vmime::header> hdr = stored_parsed_message->getHeader();
   		vmime::string subject = hdr->Subject()->getValue().dynamicCast <vmime::text>()->getConvertedText(ch);
   		current_message->subject = bpstrdup((char *) subject.c_str());
   		vmime::string from = hdr->From()->getValue().dynamicCast<vmime::mailbox>()->getName().getConvertedText(ch);
   		vmime::string from_email = hdr->From()->getValue().dynamicCast<vmime::mailbox>()->getEmail();
   		current_message->from       = bpstrdup((char *) from.c_str());
   		current_message->from_email = bpstrdup((char *) from_email.c_str());
    }
	return ERR_FAILURE;
}
BP_ERROR_T BP_RecieveMessagesFromSession ( P_BP_EMAIL_SESSION email_session , size_t msg_start_number , size_t msg_retrieve_count ) { if ( ! email_session || ! msg_retrieve_count ) return ERR_FAILURE ; vmime :: ref < vmime :: net :: message > msg ; MessageList * msgList = email_session -> message_list ; size_t i = msg_start_number ; for ( ; i < msg_start_number + msg_retrieve_count ; i ++ ) { msg = email_session -> f -> getMessage ( i ) ; msgList -> insert ( MessageList :: value_type ( i , msg ) ) ; vmime :: utility :: outputStreamAdapter out ( std :: cout ) ; vmime :: string email_content ; vmime :: utility :: outputStreamStringAdapter bufferStream ( email_content ) ; msg -> extract ( bufferStream ) ; vmime :: message * stored_parsed_message = new vmime :: message ; stored_parsed_message -> parse ( email_content ) ; email_session -> messages_fetched ++ ; email_session -> messages = ( P_BP_EMAIL_MESSAGE ) bprealloc ( email_session -> messages , sizeof ( BP_EMAIL_MESSAGE ) * email_session -> message_count ) ; memset ( & email_session -> messages [ email_session -> messages_fetched - 1 ] , 0x00 , sizeof ( BP_EMAIL_MESSAGE ) ) ; BP_EMAIL_MESSAGE * current_message = & email_session -> messages [ email_session -> messages_fetched - 1 ] ; current_message -> msg_inbox_number = i ; current_message -> message = bpstrdup ( ( char * ) email_content . c_str ( ) ) ; current_message -> message_length = email_content . length ( ) ; vmime :: text outText ; vmime :: charset ch ( vmime :: charsets :: UTF_8 ) ; vmime :: charset ch2 ( vmime :: charsets :: UTF_8 ) ; vmime :: ref < vmime :: header > hdr = stored_parsed_message -> getHeader ( ) ; vmime :: string subject = hdr -> Subject ( ) -> getValue ( ) . dynamicCast < vmime :: text > ( ) -> getConvertedText ( ch ) ; current_message -> subject = bpstrdup ( ( char * ) subject . c_str ( ) ) ; vmime :: string from = hdr -> From ( ) -> getValue ( ) . dynamicCast < vmime :: mailbox > ( ) -> getName ( ) . getConvertedText ( ch ) ; vmime :: string from_email = hdr -> From ( ) -> getValue ( ) . dynamicCast < vmime :: mailbox > ( ) -> getEmail ( ) ; current_message -> from = bpstrdup ( ( char * ) from . c_str ( ) ) ; current_message -> from_email = bpstrdup ( ( char * ) from_email . c_str ( ) ) ; } return ERR_FAILURE ; }
Retrieve A Messages At The Specified Start Position, and Retrieve X Records
Retrieve A Messages At The Specified Start Position and Retrieve X Records
// return indicating failure // local message structure // message list // set message retrieval loop index base at start index // get message // insert message into list // message output stream // extract email // create stored message // parse out email content // ------------------------------------------- // store message in session // increase the message count and allocate space for message // bpreallocate message structure // zero out the new last element // set current message for ease of use // set current message content, length, and inbox number in the message structure (ease of use) // set subject // current_message->subject // extract header // get subject // save the subject // get subject // get email // save the from name and email address