Exemplo n.º 1
0
	VMIME_TEST_LIST_END


	static const vmime::string getStructure(vmime::ref <vmime::bodyPart> part)
	{
		vmime::ref <vmime::body> bdy = part->getBody();

		vmime::string res = part->getBody()->getContentType().generate();

		if (bdy->getPartCount() == 0)
			return res;

		res += "[";

		for (size_t i = 0 ; i < bdy->getPartCount() ; ++i)
		{
			vmime::ref <vmime::bodyPart> subPart = bdy->getPartAt(i);

			if (i != 0)
				res += ",";

			res += getStructure(subPart);
		}

		return res + "]";
	}
Exemplo n.º 2
0
  virtual void verify(vmime::ref<vmime::security::cert::certificateChain> chain)
  {
    std::cout<<"\n"<<chain->getCount()<<" certificates in chain\n";
    vmime::utility::outputStreamAdapter os(std::cout);
    for(int i=chain->getCount()-1; i>=0; --i)
    {
      vmime::ref<X509Certificate> tmp=chain->getAt(i).dynamicCast<X509Certificate>();
      std::cout<<"------------ CERT # "<<chain->getCount()-i<<" ----------------\n";
      tmp->write(os, X509Certificate::FORMAT_PEM);
    }

  }
Exemplo n.º 3
0
void sendMessage(string fromstr, string tostr, string subjectstr, string contentstr, string urlString)
{
	try
	{
		vmime::utility::url url(urlString);
		vmime::ref <vmime::net::transport> tr = g_session->getTransport(url);
		// Enable TLS support if available
		tr->setProperty("connection.tls", true);

		tr->setCertificateVerifier(vmime::create <NonInteractiveCertificateVerifier>());
		vmime::mailbox from(fromstr);
		vmime::mailboxList to;
        to.appendMailbox(vmime::create <vmime::mailbox>(tostr));
		std::ostringstream data;
        data << "From: " << fromstr << "\r\nTo: " << tostr << "\r\nSubject: " << subjectstr << "\r\n" << contentstr << "\r\n";
		// Connect to server
		tr->connect();
        vmime::string msgData = data.str();
        vmime::utility::inputStreamStringAdapter vis(msgData);
        tr->send(from, to, vis, msgData.length());
		tr->disconnect();
	}
	catch (vmime::exception& e)
	{
	}
	catch (std::exception& e)
	{
	}
}
Exemplo n.º 4
0
void extractContentHandlerToFile(vmime::ref<const vmime::contentHandler> content_handler, string file_name) {
	ofstream file;
	file.open(file_name.c_str(), ios::out | ios::binary);		
	vmime::utility::outputStreamAdapter out(file);
	content_handler->extract(out);
	file.close();		
}
	static const vmime::string extractContents(const vmime::ref <const vmime::contentHandler> cts)
	{
		std::ostringstream oss;
		vmime::utility::outputStreamAdapter os(oss);

		cts->extract(os);

		return oss.str();
	}
Exemplo n.º 6
0
bool MailBoxSetting::isIgnoredFolder(vmime::ref<vmime::net::folder> const & folder) const {
    //O(n) -> O(log(n)) ?
    std::string folderName = folder->getFullPath().getLastComponent().generate();
    for (auto ignored_folder : ignored_folder_name_) {
        if(folderName == ignored_folder) {
            return true;
        }
    }
    return false;
}
Exemplo n.º 7
0
vmime::ref<vmime::message> convertMessage(vmime::ref<vmime::net::message> message) {
	vmime::string data;
	vmime::utility::outputStreamStringAdapter out(data);
	message->extract(out);	
	// in string data - message data 
	
	vmime::ref<vmime::message> msg = vmime::create<vmime::message>();	
	msg->parse(data);
	
	return msg;
}
Exemplo n.º 8
0
	static const vmime::string extractBodyContents(vmime::ref <const vmime::bodyPart> part)
	{
		vmime::ref <const vmime::contentHandler> cth = part->getBody()->getContents();

		vmime::string data;
		vmime::utility::outputStreamStringAdapter os(data);

		cth->extract(os);

		return data;
	}
Exemplo n.º 9
0
		void EMailImapService::returningMailCheck(vmime::ref<vmime::net::message> &msg)
		{
			dtn::data::BundleID bid;

			bool bidFound = false;

			std::string s;
			vmime::utility::outputStreamStringAdapter out(s);

			vmime::messageParser mp(msg->getParsedMessage());

			for(int i = 0; i < mp.getTextPartCount(); ++i)
			{
				s.clear();
				mp.getTextPartAt(i)->getText()->extract(out);

				try {
					bid = extractBID(s);
					bidFound = true;
					break;
				}catch(InvalidConversion&) {}
			}

			if(!bidFound)
			{
				for(int i = 0; i < mp.getAttachmentCount(); ++i)
				{
					s.clear();
					mp.getAttachmentAt(i)->getData()->extract(out);

					try {
						bid = extractBID(s);
						bidFound = true;
						break;
					}catch(InvalidConversion&) {}
				}
			}

			{
				ibrcommon::Mutex l(_processedTasksMutex);
				for(std::list<EMailSmtpService::Task*>::iterator iter = _processedTasks.begin(); iter != _processedTasks.end(); ++iter)
				{
					if((*iter)->getJob().getBundle() == bid)
					{
						dtn::routing::RequeueBundleEvent::raise((*iter)->getNode().getEID(), bid, dtn::core::Node::CONN_EMAIL);
						_processedTasks.erase(iter);
						break;
					}
				}
			}

			if(!bidFound)
				throw BidNotFound("Found no bundle ID");
		}
Exemplo n.º 10
0
void dumpToLog(vmime::ref<vmime::net::session> session)
{
    typedef std::vector<vmime::ref<vmime::propertySet::property> >
        PropertyList;
    PropertyList list = session->getProperties().getPropertyList();
    PropertyList::const_iterator end = list.end();
    for(PropertyList::const_iterator it = list.begin(); it != end; ++it) {
        qLog() << QString("%1 %2").arg(
            (*it)->getName().c_str()).arg((*it)->getValue().c_str());
    }

}
	VMIME_TEST_LIST_END


	static const vmime::string extractContent
		(vmime::ref <const vmime::contentHandler> cth)
	{
		std::ostringstream oss;
		vmime::utility::outputStreamAdapter osa(oss);

		cth->extract(osa);

		return oss.str();
	}
Exemplo n.º 12
0
	void verify(vmime::ref <vmime::security::cert::certificateChain> chain)
	{
		try
		{
			setX509TrustedCerts(m_trustedCerts);

			defaultCertificateVerifier::verify(chain);
		}
		catch (vmime::exceptions::certificate_verification_exception&)
		{
			// Obtain subject's certificate
			vmime::ref <vmime::security::cert::certificate> cert = chain->getAt(0);


            // Accept it, and remember user's choice for later
            if (cert->getType() == "X.509")
            {
                m_trustedCerts.push_back(cert.dynamicCast
                    <vmime::security::cert::X509Certificate>());
            }

		}
	}
Exemplo n.º 13
0
vmime::datetime getDate(vmime::ref<vmime::net::message> message) {
	vmime::ref<const vmime::headerFieldValue> headerValue = message->getHeader()->Date()->getValue();
	vmime::ref<const vmime::datetime> headerDateTime = headerValue.dynamicCast<const vmime::datetime>();
		
	return *headerDateTime;
}
Exemplo n.º 14
0
string getName(vmime::ref<vmime::net::message> message) {
	vmime::ref<const vmime::headerFieldValue> headerValue = message->getHeader()->Subject()->getValue();
	vmime::ref<const vmime::text> headerText = headerValue.dynamicCast<const vmime::text>();
		
	return headerText->getConvertedText(vmime::charset());
}
Exemplo n.º 15
0
		void EMailImapService::generateBundle(vmime::ref<vmime::net::message> &msg)
		{

			// Create new Bundle
			dtn::data::Bundle newBundle;

			// Clear all blocks
			newBundle.clear();

			// Get header of mail
			vmime::ref<const vmime::header> header = msg->getHeader();
			std::string mailID = " (ID: " + msg->getUniqueId() + ")";

			// Check EMailCL version
			try {
				int version = toInt(header->findField("Bundle-EMailCL-Version")->getValue()->generate());
				if(version != 1)
					throw IMAPException("Wrong EMailCL version found in mail" + mailID);
			}catch(vmime::exceptions::no_such_field&) {
				throw IMAPException("Field \"Bundle-EMailCL-Version\" not found in mail" + mailID);
			}catch(InvalidConversion&) {
				throw IMAPException("Field \"Bundle-EMailCL-Version\" wrong formatted in mail" + mailID);
			}

			try {
				newBundle.procflags = toInt(header->findField("Bundle-Flags")->getValue()->generate());
				newBundle.destination = header->findField("Bundle-Destination")->getValue()->generate();
				newBundle.source = dtn::data::EID(header->findField("Bundle-Source")->getValue()->generate());
				newBundle.reportto = header->findField("Bundle-Report-To")->getValue()->generate();
				newBundle.custodian = header->findField("Bundle-Custodian")->getValue()->generate();
				newBundle.timestamp = toInt(header->findField("Bundle-Creation-Time")->getValue()->generate());
				newBundle.sequencenumber = toInt(header->findField("Bundle-Sequence-Number")->getValue()->generate());
				newBundle.lifetime = toInt(header->findField("Bundle-Lifetime")->getValue()->generate());
			}catch(vmime::exceptions::no_such_field&) {
				throw IMAPException("Missing bundle headers in mail" + mailID);
			}catch(InvalidConversion&) {
				throw IMAPException("Wrong formatted bundle headers in mail" + mailID);
			}

			// If bundle is a fragment both fields need to be set
			try {
				newBundle.fragmentoffset = toInt(header->findField("Bundle-Fragment-Offset")->getValue()->generate());
				newBundle.appdatalength = toInt(header->findField("Bundle-Total-Application-Data-Unit-Length")->getValue()->generate());
			}catch(vmime::exceptions::no_such_field&) {
				newBundle.fragmentoffset = 0;
				newBundle.appdatalength = 0;
			}catch(InvalidConversion&) {
				throw IMAPException("Wrong formatted fragment offset in mail" + mailID);
			}

			//Check if bundle is already in the storage
			try {
				if(dtn::core::BundleCore::getInstance().getRouter().isKnown(newBundle))
					throw IMAPException("Bundle in mail" + mailID + " already processed");
			} catch (dtn::storage::NoBundleFoundException&) {
				// Go ahead
			}

			// Validate the primary block
			try {
				dtn::core::BundleCore::getInstance().validate((dtn::data::PrimaryBlock)newBundle);
			}catch(dtn::data::Validator::RejectedException&) {
				throw IMAPException("Bundle in mail" + mailID + " was rejected by validator");
			}

			// Get names of additional blocks
			std::vector<vmime::ref<vmime::headerField> > additionalBlocks =
					header.constCast<vmime::header>()->findAllFields("Bundle-Additional-Block");
			std::vector<std::string> additionalBlockNames;
			for(std::vector<vmime::ref<vmime::headerField> >::iterator it = additionalBlocks.begin();
					it != additionalBlocks.end(); ++it)
			{
				additionalBlockNames.push_back((*it)->getValue()->generate());
			}

			// Get all attachments
			std::vector<vmime::ref<const vmime::attachment> > attachments =
					vmime::attachmentHelper::findAttachmentsInMessage(msg->getParsedMessage());

			// Extract payload block info
			size_t payloadFlags;
			std::string payloadName;
			try {
				payloadFlags = toInt(header->findField("Bundle-Payload-Flags")->getValue()->generate());
				// Payload length will be calculated automatically
				//length = toInt(header->findField("Bundle-Payload-Block-Length")->getValue()->generate());
				payloadName = header->findField("Bundle-Payload-Data-Name")->getValue()->generate();
			}catch(vmime::exceptions::no_such_field&) {
				// No payload block there
			}catch(InvalidConversion&) {
				throw IMAPException("Wrong formatted payload flags in mail" + mailID);
			}

			// Create new bundle builder
			dtn::data::BundleBuilder builder(newBundle);

			// Download attachments
			for(std::vector<vmime::ref<const vmime::attachment> >::iterator it = attachments.begin(); it != attachments.end(); ++it)
			{
				if((*it)->getName().getBuffer() == payloadName && !payloadName.empty()) {
					dtn::data::PayloadBlock &pb = newBundle.push_back<dtn::data::PayloadBlock>();
					// Set data
					ibrcommon::BLOB::Reference ref = pb.getBLOB();
					ibrcommon::BLOB::iostream payloadData = ref.iostream();
					vmime::utility::outputStreamAdapter data((*payloadData));
					(*it)->getData()->extract(data);
					// Set flags
					setProcFlags(pb, payloadFlags);
					continue;
				}

				// If current attachment name is contained in additional attachment list
				if(std::find(additionalBlockNames.begin(), additionalBlockNames.end(), (*it)->getName().getBuffer()) != additionalBlockNames.end())
				{
					// Search for the block type
					block_t blockType;
					try {
						blockType = toInt((*it)->getHeader()->findField("Block-Type")->getValue()->generate());
					}catch(vmime::exceptions::no_such_field&) {
						throw IMAPException("Block type not found in attachment of mail" + mailID);
					}

					// Search for processing flags
					size_t flags;
					try {
						flags = toInt((*it)->getHeader()->findField("Block-Processing-Flags")->getValue()->generate());
					}catch(vmime::exceptions::no_such_field&) {
						throw IMAPException("Missing block processing flags in extension attachment of mail" + mailID);
					}catch(InvalidConversion&) {
						throw IMAPException("Wrong formatted processing flags in extension attachment of mail" + mailID);
					}

					// Create a block object
					dtn::data::Block &block = builder.insert(blockType, flags);

					// Add EIDs
					try {
						addEIDList(block, (*it));
					}catch(InvalidConversion&) {
						throw IMAPException("Wrong formatted EID list in extension attachment of mail" + mailID);
					}

					// Get payload of current block
					std::stringstream ss;
					vmime::utility::outputStreamAdapter data(ss);
					(*it)->getData()->extract(data);

					block.deserialize(ss, ss.str().length());
				}
			}

			// Validate whole bundle
			try {
				dtn::core::BundleCore::getInstance().validate(newBundle);
			}catch(dtn::data::Validator::RejectedException&) {
				throw IMAPException("Bundle in mail" + mailID + " was rejected by validator");
			}

			// create a filter context
			dtn::core::FilterContext context;
			context.setProtocol(dtn::core::Node::CONN_EMAIL);

			// push bundle through the filter routines
			context.setBundle(newBundle);
			BundleFilter::ACTION ret = dtn::core::BundleCore::getInstance().filter(dtn::core::BundleFilter::INPUT, context, newBundle);

			if (ret == BundleFilter::ACCEPT)
			{
				// Raise default bundle received event
				dtn::net::BundleReceivedEvent::raise(newBundle.source, newBundle, false);
			}
		}