library/src/network/email/BP-Email.cc
/** Connect to a message store interactively.
  */
Connect to a message store interactively.
Connect to a message store interactively .
P_BP_EMAIL_SESSION BP_CreateNewEmailSession(char *connect_str, char *folder_name)
{
	vmime::platform::setHandler<vmime::platforms::posix::posixHandler>();
	if(!connect_str)
		return NULL;
	P_BP_EMAIL_SESSION email_session = (P_BP_EMAIL_SESSION) bpcalloc(sizeof(BP_EMAIL_SESSION), 1);
	if(!email_session)
		return NULL;
		vmime::string * url_str = new vmime::string(connect_str);
		email_session->urlString = url_str; 
		email_session->url_object = new vmime::utility::url(*email_session->urlString);
		if (
				email_session->url_object->getUsername().empty() ||
				email_session->url_object->getPassword().empty()
		)
		{
			email_session->st = g_session->getStore(*email_session->url_object, vmime::create <interactiveAuthenticator>());
		}
		else
		{
			email_session->st = g_session->getStore(*email_session->url_object);
		}
#if VMIME_HAVE_TLS_SUPPORT
		email_session->st->setProperty("connection.tls", true);
		email_session->st->setCertificateVerifier(vmime::create <interactiveCertificateVerifier>());
#endif 
		email_session->st->connect();
		email_session->ci = email_session->st->getConnectionInfos();
		email_session->remote_host = new vmime::string(email_session->ci->getHost());
		email_session->remote_port = email_session->ci->getPort();
		email_session->connection_secure = email_session->st->isSecuredConnection();
		email_session->remote_host_c_str = bpstrdup((char *) email_session->remote_host->c_str());
		if(!folder_name)
			email_session->f = email_session->st->getDefaultFolder();
		else
			email_session->f = email_session->st->getFolder(vmime::utility::path(folder_name));
		email_session->f->open(vmime::net::folder::MODE_READ_WRITE);
		email_session->message_count = email_session->f->getMessageCount();
		printf("\n Remote Connection: %s", email_session->remote_host_c_str);
		printf("\n Remote Port:       %d", email_session->remote_port);
		printf("\n Message Count:     %d", email_session->message_count);
		printf("\n");
		email_session->message_list = new MessageList();
		return email_session;
}
P_BP_EMAIL_SESSION BP_CreateNewEmailSession ( char * connect_str , char * folder_name ) { vmime :: platform :: setHandler < vmime :: platforms :: posix :: posixHandler > ( ) ; if ( ! connect_str ) return NULL ; P_BP_EMAIL_SESSION email_session = ( P_BP_EMAIL_SESSION ) bpcalloc ( sizeof ( BP_EMAIL_SESSION ) , 1 ) ; if ( ! email_session ) return NULL ; vmime :: string * url_str = new vmime :: string ( connect_str ) ; email_session -> urlString = url_str ; email_session -> url_object = new vmime :: utility :: url ( * email_session -> urlString ) ; if ( email_session -> url_object -> getUsername ( ) . empty ( ) || email_session -> url_object -> getPassword ( ) . empty ( ) ) { email_session -> st = g_session -> getStore ( * email_session -> url_object , vmime :: create < interactiveAuthenticator > ( ) ) ; } else { email_session -> st = g_session -> getStore ( * email_session -> url_object ) ; } #if VMIME_HAVE_TLS_SUPPORT email_session -> st -> setProperty ( " " , true ) ; email_session -> st -> setCertificateVerifier ( vmime :: create < interactiveCertificateVerifier > ( ) ) ; #endif email_session -> st -> connect ( ) ; email_session -> ci = email_session -> st -> getConnectionInfos ( ) ; email_session -> remote_host = new vmime :: string ( email_session -> ci -> getHost ( ) ) ; email_session -> remote_port = email_session -> ci -> getPort ( ) ; email_session -> connection_secure = email_session -> st -> isSecuredConnection ( ) ; email_session -> remote_host_c_str = bpstrdup ( ( char * ) email_session -> remote_host -> c_str ( ) ) ; if ( ! folder_name ) email_session -> f = email_session -> st -> getDefaultFolder ( ) ; else email_session -> f = email_session -> st -> getFolder ( vmime :: utility :: path ( folder_name ) ) ; email_session -> f -> open ( vmime :: net :: folder :: MODE_READ_WRITE ) ; email_session -> message_count = email_session -> f -> getMessageCount ( ) ; printf ( " \n " , email_session -> remote_host_c_str ) ; printf ( " \n " , email_session -> remote_port ) ; printf ( " \n " , email_session -> message_count ) ; printf ( " \n " ) ; email_session -> message_list = new MessageList ( ) ; return email_session ; }
Connect to a message store interactively.
Connect to a message store interactively .
// VMime initialization // check connect string (cannot be null) // create new email session structure // create new string // set class pointer // new std::string(connect_str, bpstrlen(connect_str)); // create new url object // If the user/pass wasn't set in the url string, attempt to get them here. // Additional TLS checks below. // Enable TLS support if available // Set the object responsible for verifying certificates, in the // case a secured connection is used (TLS/SSL) // VMIME_HAVE_TLS_SUPPORT // Connect to the mail store // Display some information about the connection // save remote host we're connected to // save the remote port we're connected on // save whether or not the connection is secured // set the C styled string in the struct for ease of use // open default folder // retrieve the number of messages that are in the inbox // message info // create new messagelist for later message retrieval // return the new session /*

		// retrieve the foldern_name or default for opening




*/ /*
		for (bool cont = true ; cont ; )
		{
			typedef std::map <int, vmime::ref <vmime::net::message> > MessageList;
			MessageList msgList;

			try
			{


				// Show message flags
//				case 1:

					f->fetchMessage(msg, vmime::net::folder::FETCH_FLAGS);

					if (msg->getFlags() & vmime::net::message::FLAG_SEEN)
						std::cout << "FLAG_SEEN" << std::endl;
					if (msg->getFlags() & vmime::net::message::FLAG_RECENT)
						std::cout << "FLAG_RECENT" << std::endl;
					if (msg->getFlags() & vmime::net::message::FLAG_REPLIED)
						std::cout << "FLAG_REPLIED" << std::endl;
					if (msg->getFlags() & vmime::net::message::FLAG_DELETED)
						std::cout << "FLAG_DELETED" << std::endl;
					if (msg->getFlags() & vmime::net::message::FLAG_MARKED)
						std::cout << "FLAG_MARKED" << std::endl;
					if (msg->getFlags() & vmime::net::message::FLAG_PASSED)
						std::cout << "FLAG_PASSED" << std::endl;

					break;

				// Show message structure
	//			case 2:

					f->fetchMessage(msg, vmime::net::folder::FETCH_STRUCTURE);
					printStructure(msg->getStructure());
					break;

				// Show message header
		//		case 3:

					f->fetchMessage(msg, vmime::net::folder::FETCH_FULL_HEADER);
					std::cout << msg->getHeader()->generate() << std::endl;
					break;

				// Show message envelope
			//	case 4:

					f->fetchMessage(msg, vmime::net::folder::FETCH_ENVELOPE);

#define ENV_HELPER(x) \
	try { std::cout << msg->getHeader()->x()->generate() << std::endl; } \
	catch (vmime::exception) {  }

					ENV_HELPER(From)
					ENV_HELPER(To)
					ENV_HELPER(Date)
					ENV_HELPER(Subject)

#undef ENV_HELPER

				//	break;

				// Extract whole message
				// case 5:
				{
					vmime::utility::outputStreamAdapter out(std::cout);
					msg->extract(out);

				//	break;
				}




				// Change folder
//				case 7:

					std::cout << "Enter folder path (eg. /root/subfolder):" << std::endl;
					std::cout.flush();

					std::string path;
					std::getline(std::cin, path);

					vmime::ref<vmime::net::folder> newFolder = st->getRootFolder();

					for (std::string::size_type s = 0, p = 0;; s = p + 1) {
						p = path.find_first_of('/', s);

						const std::string x = (p == std::string::npos) ? std::string(path.begin() + s, path.end())
								: std::string(path.begin() + s, path.begin() + p);

						if (!x.empty())
							newFolder = newFolder->getFolder(x);

						if (p == std::string::npos)
							break;
					}

					newFolder->open(vmime::net::folder::MODE_READ_WRITE);

					count = newFolder->getMessageCount();

					std::cout << std::endl;
					std::cout << count << " message(s) in this folder" << std::endl;

					f->close(true); // 'true' to expunge deleted messages
					f = newFolder;


				// Main menu
				// case 8:

					f->close(true);  // 'true' to expunge deleted messages
					cont = false;
					break;




		// Append message
		std::istringstream iss(
			"From: me@localhost\r\n"
			"To: you@localhost\r\n"
			"Subject: Message Text\r\n"
			"\r\n"
			"This is a test message...\r\n"
			"Bye bye!\r\n"
		);

		f->addMessage(iss, iss.str().size());

		// Folder renaming
		{
			vmime::ref <vmime::net::folder> f = st->getFolder(vmime::net::folder::path("c"));
			f->rename(vmime::net::folder::path("c2"));

			vmime::ref <vmime::net::folder> g = st->getFolder(vmime::net::folder::path("c2"));
			g->rename(vmime::net::folder::path("c"));
		}

		// Message copy: copy all messages from 'f' to 'g'
		{
			vmime::ref <vmime::net::folder> g = st->getFolder(vmime::net::folder::path("TEMP"));

			if (!g->exists())
				g->create(vmime::net::folder::TYPE_CONTAINS_MESSAGES);

			f->copyMessages(g->getFullPath());
		}

			}


			catch (vmime::exception& e)
			{
				std::cerr << std::endl;
				std::cerr << e << std::endl;
			}
			catch (std::exception& e)
			{
				std::cerr << std::endl;
				std::cerr << "std::exception: " << e.what() << std::endl;
			}

		// }
			*/