void SMTPClientSessionTest::testSendFailed()
{
	DialogServer server;
	server.addResponse("220 localhost SMTP ready");
	server.addResponse("250 Hello localhost");
	server.addResponse("250 OK");
	server.addResponse("250 OK");
	server.addResponse("354 Send data");
	server.addResponse("500 Error");
	server.addResponse("221 Bye");
	SMTPClientSession session("localhost", server.port());
	session.login("localhost");

	MailMessage message;
	message.setSender("*****@*****.**");
	message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, "*****@*****.**", "Jane Doe"));
	message.setSubject("Test Message");
	message.setContent("Hello\r\nblah blah\r\n\r\nJohn\r\n");
	server.clearCommands();
	try
	{
		session.sendMessage(message);
		fail("internal error - must throw");
	}
	catch (SMTPException&)
	{
	}
	
	session.close();
}
Пример #2
0
UtlBoolean EmailSendTask::handleMessage( OsMsg& rMsg )
{
   UtlBoolean handled = FALSE;
   AsynchEmailMsg* pEmailMsg = dynamic_cast <AsynchEmailMsg*> ( &rMsg );

   MailMessage msg       = pEmailMsg->getMessage();

   switch ( rMsg.getMsgType() )
   {
   case OsMsg::OS_EVENT:
   {
      UtlString response = msg.Send();
      if (!response.isNull())
      {
         if (response.length() > 0)
         {
            OsSysLog::add(FAC_ALARM, PRI_ERR, "EmailSendTask: "
                  " Error sending e-mail: response %s", response.data());
         }
      }
      handled = TRUE;
      break;
   }

   default:
      OsSysLog::add(FAC_ALARM, PRI_CRIT,
                    "EmailSendTask::handleMessage: '%s' unhandled message type %d.%d",
                    mName.data(), rMsg.getMsgType(), rMsg.getMsgSubType());
      break;
   }

   return handled;
}
Пример #3
0
void WorldSession::HandleReturnToSender(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	recv_data >> mailbox >> message_id;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_RETURNED_TO_SENDER);

	MailMessage * msg = _player->m_mailBox->GetMessage(message_id);
	if(msg == 0 || msg->Expired())
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}
	if(msg->returned_flag)
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	sMailSystem.ReturnToSender(msg);

	// finish the packet
	data << uint32(MAIL_OK);
	SendPacket(&data);
}
Пример #4
0
void MailSystem::UpdateMessages()
{
	if((++loopcount % 1200))
		return;

	QueryResult *result = CharacterDatabase.Query("SELECT * FROM mailbox WHERE expiry_time > 0 and expiry_time <= %u and deleted_flag = 0",(uint32)UNIXTIME);

	if(!result)
		return;

	MailMessage msg;
	do 
	{
		if (msg.LoadFromDB(result->Fetch()))
		{
			if (/*msg.Expired() &&*/ msg.items.size() == 0 && msg.money == 0)
			{
				if(msg.copy_made)
				{
					msg.deleted_flag = true;
					msg.SaveToDB();
				} else
				{
					CharacterDatabase.WaitExecute("DELETE FROM mailbox WHERE message_id = %u", msg.message_id);
				}
			} else
			{
				ReturnToSender(&msg);
			}

		}
	} while(result->NextRow());
	delete result;
}
Пример #5
0
void MailMessageTest::testReadQP()
{
	std::istringstream istr(
		"Content-Transfer-Encoding: quoted-printable\r\n"
		"Content-Type: text/plain\r\n"
		"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
		"From: [email protected]\r\n"
		"Subject: Test Message\r\n"
		"To: John Doe <*****@*****.**>\r\n"
		"\r\n"
		"Hello, world!\r\n"
		"This is a test for the MailMessage class.\r\n"
		"To test the quoted-printable encoding, we'll put an extra long line here. T=\r\n"
		"his should be enough.\r\n"
		"And here is some more =3Dfe.\r\n"
	);
	
	MailMessage message;
	message.read(istr);
	
	assert (message.getSender() == "*****@*****.**");
	assert (message.getContentType() == "text/plain");
	assert (message.getContent() == 
		"Hello, world!\r\n"
		"This is a test for the MailMessage class.\r\n"
		"To test the quoted-printable encoding, we'll put an extra long line here. This should be enough.\r\n"
		"And here is some more =fe.\r\n"
	);
}
Пример #6
0
bool Acount::removeMail(const int& index)
{
	MailMessage mail;
	bool remove = _mailBox.remove(index, mail);
	_size -= mail.getSize();
	if (remove)
		_msgCount--;
	return remove;
}
void MessageDetailsModel::setMessage(const MailMessage& message)
{
  clear();
  beginInsertRows(QModelIndex(), 0,
                  message.getHeaders().size() + message.getBody().size());
  this->message = message;
  endInsertRows();
  reset();
}
Пример #8
0
void POP3ClientSessionTest::testRetrieveMessages()
{
	DialogServer server;
	server.addResponse("+OK POP3 Ready...");
	server.addResponse("+OK USER");
	server.addResponse("+OK PASS");
	server.addResponse(
		"+OK Here comes the message\r\n"
		"From: [email protected]\r\n"
		"To: [email protected]\r\n"
		"Subject: test\r\n"
		"\r\n"
		"."
	);
	server.addResponse(
		"+OK Here comes the message\r\n"
		"From: [email protected]\r\n"
		"To: [email protected]\r\n"
		"Subject: test\r\n"
		"\r\n"
		"Hello Jane,\r\n"
		"\r\n"
		"blah blah blah...\r\n"
		"....\r\n"
		"\r\n"
		"Yours, John\r\n"
		"."
	);
	server.addResponse("+OK QUIT");
	POP3ClientSession session("localhost", server.port());
	session.login("user", "secret");
	server.clearCommands();
	MessageHeader header;
	session.retrieveHeader(1, header);
	std::string cmd = server.popCommand();
	assert (cmd == "TOP 1 0");
	assert (header.get("From") == "*****@*****.**");
	assert (header.get("To") == "*****@*****.**");
	assert (header.get("Subject") == "test");

	MailMessage message;
	session.retrieveMessage(2, message);
	cmd = server.popCommand();
	assert (cmd == "RETR 2");

	assert (message.getContent() ==
		"Hello Jane,\r\n"
		"\r\n"
		"blah blah blah...\r\n"
		"...\r\n"
		"\r\n"
		"Yours, John\r\n"
	);
	session.close();
}
Пример #9
0
TEST_F(ReportMailerTest, CanConstructMailMessage)
{
    string toAddress = "*****@*****.**";
    StubReport report;

    MailMessage message = ReportMailer::ConstructMailMessageTo(toAddress, &report);

    ASSERT_THAT(message.To()[0], Eq(toAddress));
    ASSERT_THAT(message.Subject(), Eq(report.Name()));
    ASSERT_THAT(message.Content(), Eq(report.Text()));
    ASSERT_THAT(message.From(), Eq("*****@*****.**"));
}
Пример #10
0
void Mailbox::OnMessageCopyDeleted(uint32 msg_id)
{
	MailMessage * msg = GetMessage(msg_id);
	if(msg == 0) return;

	msg->copy_made = false;

	if(msg->deleted_flag)   // we've deleted from inbox
		DeleteMessage(msg);   // wipe the message
	else
		msg->SaveToDB();
}
Пример #11
0
void MailMessageTest::testWriteMultiPart()
{
	MailMessage message;
	MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "*****@*****.**", "John Doe");
	message.addRecipient(r1);
	message.setSubject("Test Message");
	message.setSender("*****@*****.**");
	Timestamp ts(0);
	message.setDate(ts);
	message.addContent(new StringPartSource("Hello World!\r\n", "text/plain"), MailMessage::ENCODING_8BIT);
	StringPartSource* pSPS = new StringPartSource("This is some binary data. Really.", "application/octet-stream", "sample.dat");
	pSPS->headers().set("Content-ID", "abcd1234");
	message.addAttachment("sample", pSPS);

	assert (message.isMultipart());

	std::ostringstream str;
	message.write(str);
	std::string s = str.str();
	std::string rawMsg(
		"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
		"Content-Type: multipart/mixed; boundary=$\r\n"
		"Subject: Test Message\r\n"
		"From: [email protected]\r\n"
		"To: John Doe <*****@*****.**>\r\n"
		"Mime-Version: 1.0\r\n"
		"\r\n"
		"--$\r\n"
		"Content-Type: text/plain\r\n"
		"Content-Transfer-Encoding: 8bit\r\n"
		"Content-Disposition: inline\r\n"
		"\r\n"
		"Hello World!\r\n"
		"\r\n"
		"--$\r\n"
		"Content-ID: abcd1234\r\n"
		"Content-Type: application/octet-stream; name=sample\r\n"
		"Content-Transfer-Encoding: base64\r\n"
		"Content-Disposition: attachment; filename=sample.dat\r\n"
		"\r\n"
		"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
		"--$--\r\n"
	);
	std::string::size_type p1 = s.find('=') + 1;
	std::string::size_type p2 = s.find('\r', p1);
	std::string boundary(s, p1, p2 - p1);
	std::string msg;
	for (std::string::const_iterator it = rawMsg.begin(); it != rawMsg.end(); ++it)
	{
		if (*it == '$')
			msg += boundary;
		else
			msg += *it;
	}

	assert (s == msg);
}
Пример #12
0
void Mailbox::Load(QueryResult * result)
{
	if(!result)
		return;

	MailMessage msg;
	do 
	{
		if (msg.LoadFromDB(result->Fetch()))
		{
			AddMessage(&msg);// Add to the mailbox
		}
	} while(result->NextRow());
}
void SMTPClientSessionTest::testSend()
{
	DialogServer server;
	server.addResponse("220 localhost SMTP ready");
	server.addResponse("250 Hello localhost");
	server.addResponse("250 OK");
	server.addResponse("250 OK");
	server.addResponse("354 Send data");
	server.addResponse("250 OK");
	server.addResponse("221 Bye");
	SMTPClientSession session("localhost", server.port());
	session.login("localhost");

	MailMessage message;
	message.setSender("*****@*****.**");
	message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, "*****@*****.**", "Jane Doe"));
	message.setSubject("Test Message");
	message.setContent("Hello\r\nblah blah\r\n\r\nJohn\r\n");
	server.clearCommands();
	session.sendMessage(message);
	std::string cmd = server.popCommandWait();
	assert (cmd == "MAIL FROM: <*****@*****.**>");
	cmd = server.popCommandWait();
	assert (cmd == "RCPT TO: <*****@*****.**>");
	cmd = server.popCommandWait();
	assert (cmd == "DATA");
	cmd = server.popCommandWait();
	assert (cmd.substr(0, 4) == "Date");
	cmd = server.popCommandWait();
	assert (cmd == "Content-Type: text/plain");
	cmd = server.popCommandWait();
	assert (cmd == "From: [email protected]");
	cmd = server.popCommandWait();
	assert (cmd == "Subject: Test Message");
	cmd = server.popCommandWait();
	assert (cmd == "Content-Transfer-Encoding: quoted-printable");
	cmd = server.popCommandWait();
	assert (cmd == "To: Jane Doe <*****@*****.**>");
	cmd = server.popCommandWait();
	assert (cmd == "Hello");
	cmd = server.popCommandWait();
	assert (cmd == "blah blah");
	cmd = server.popCommandWait();
	assert (cmd == "John");
	cmd = server.popCommandWait();
	assert (cmd == ".");

	session.close();
}
Пример #14
0
void send(const MailMessage& msg)
{
    /// Just a skeleton.
    /// Assuming that there is a third party send
    /// API which is responsible for sending email.
    print( "Sender: " + msg.getSender() );

    print("Recipients:");
    MailMessage::Recipients recipients = msg.getRecipients();
    for ( auto start = recipients.begin(); start != recipients.end(); ++start )
        print( (*start).getAddress() );

    print("Subject: " + msg.getSubject() );
    print("Content: " + msg.getContent() );
}
Пример #15
0
void WorldSession::HandleTakeMoney(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	recv_data >> mailbox >> message_id;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_MONEY_TAKEN);

	MailMessage * message = _player->m_mailBox->GetMessage(message_id);
	if(message == 0 || message->Expired() || !message->money)
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	// add the money to the player
	if((_player->GetUInt32Value(PLAYER_FIELD_COINAGE) + message->money) >= PLAYER_MAX_GOLD )
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);
		return;
	}
	else
		_player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, message->money);
	
	// force save
	_player->SaveToDB(false);

	// message no longer has any money
	message->money = 0;

	if ((message->items.size() == 0) && (message->money == 0))
	{
		// mail now has a 3 day expiry time
		if(!sMailSystem.MailOption(MAIL_FLAG_NO_EXPIRY))
			message->expire_time = (uint32)UNIXTIME + (TIME_DAY * 3);
	}
	// update in sql!
	message->SaveToDB();

	// send result
	data << uint32(MAIL_OK);
	SendPacket(&data);
}
Пример #16
0
void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	recv_data >> mailbox >> message_id;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_MADE_PERMANENT);

	ItemPrototype * proto = ItemPrototypeStorage.LookupEntry(8383);
	MailMessage * message = _player->m_mailBox->GetMessage(message_id);
	if(message == 0 || message->Expired() || message->copy_made || !proto)
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	SlotResult result = _player->GetItemInterface()->FindFreeInventorySlot(proto);
	if(result.Result == 0)
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);

		return;
	}

	ItemPointer pItem = objmgr.CreateItem(8383, _player);
	pItem->SetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID, message_id);
	if( _player->GetItemInterface()->AddItemToFreeSlot(pItem) )
	{
		// mail now has an item after it
		message->copy_made = true;
		// update in sql
		message->SaveToDB();

		data << uint32(MAIL_OK);
		SendPacket(&data);
	}
	else
	{
		pItem->Destructor();
		pItem = NULLITEM;
	}
}
Пример #17
0
void MailMessageTest::testWriteBase64()
{
	MailMessage message;
	MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "*****@*****.**", "John Doe");
	message.addRecipient(r1);
	message.setSubject("Test Message");
	message.setSender("*****@*****.**");
	message.setContent(
		"Hello, world!\r\n"
		"This is a test for the MailMessage class.\r\n",
		MailMessage::ENCODING_BASE64
	);
	Timestamp ts(0);
	message.setDate(ts);

	std::ostringstream str;
	message.write(str);
	std::string s = str.str();
	assert (s == 
		"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
		"Content-Type: text/plain\r\n"
		"Subject: Test Message\r\n"
		"From: [email protected]\r\n"
		"Content-Transfer-Encoding: base64\r\n"
		"To: John Doe <*****@*****.**>\r\n"
		"\r\n"
		"SGVsbG8sIHdvcmxkIQ0KVGhpcyBpcyBhIHRlc3QgZm9yIHRoZSBNYWlsTWVzc2FnZSBjbGFz\r\n"
		"cy4NCg=="
	);
}
Пример #18
0
void MailMessageTest::testWrite8Bit()
{
	MailMessage message;
	MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "*****@*****.**", "John Doe");
	message.addRecipient(r1);
	message.setSubject("Test Message");
	message.setSender("*****@*****.**");
	message.setContent(
		"Hello, world!\r\n"
		"This is a test for the MailMessage class.\r\n",
		MailMessage::ENCODING_8BIT
	);
	Timestamp ts(0);
	message.setDate(ts);
	
	std::ostringstream str;
	message.write(str);
	std::string s = str.str();
	assert (s == 
		"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
		"Content-Type: text/plain\r\n"
		"Subject: Test Message\r\n"
		"From: [email protected]\r\n"
		"Content-Transfer-Encoding: 8bit\r\n"
		"To: John Doe <*****@*****.**>\r\n"
		"\r\n"
		"Hello, world!\r\n"
		"This is a test for the MailMessage class.\r\n"
	);
}
Пример #19
0
void SMTPClientSession::sendCommands(const MailMessage& message, const Recipients* pRecipients)
{
	std::string response;
	int status = 0;
	const std::string& fromField = message.getSender();
	std::string::size_type emailPos = fromField.find('<');
	if (emailPos == std::string::npos)
	{
		std::string sender("<");
		sender.append(fromField);
		sender.append(">");
		status = sendCommand("MAIL FROM:", sender, response);
	}
	else
	{
		status = sendCommand("MAIL FROM:", fromField.substr(emailPos, fromField.size() - emailPos), response);
	}

	if (!isPositiveCompletion(status)) throw SMTPException("Cannot send message", response, status);
	
	std::ostringstream recipient;
	if (pRecipients)
	{
		for (Recipients::const_iterator it = pRecipients->begin(); it != pRecipients->end(); ++it)
		{
			recipient << '<' << *it << '>';
			int status = sendCommand("RCPT TO:", recipient.str(), response);
			if (!isPositiveCompletion(status)) throw SMTPException(std::string("Recipient rejected: ") + recipient.str(), response, status);
			recipient.str("");
		}
	}
	else
	{
		for (MailMessage::Recipients::const_iterator it = message.recipients().begin(); it != message.recipients().end(); ++it)
		{
			recipient << '<' << it->getAddress() << '>';
			int status = sendCommand("RCPT TO:", recipient.str(), response);
			if (!isPositiveCompletion(status)) throw SMTPException(std::string("Recipient rejected: ") + recipient.str(), response, status);
			recipient.str("");
		}
	}

	status = sendCommand("DATA", response);
	if (!isPositiveIntermediate(status)) throw SMTPException("Cannot send message data", response, status);
}
Пример #20
0
int main (int argc, char **argv)
{
  try
    {
      MailMessage msg;

      msg.addRecipient (MailRecipient (MailRecipient::PRIMARY_RECIPIENT,
                                       "*****@*****.**",
                                       "Alice Moralis"));
      msg.addRecipient (MailRecipient (MailRecipient::CC_RECIPIENT,
                                       "*****@*****.**",
                                       "Patrick Kilpatrick"));
      msg.addRecipient (MailRecipient (MailRecipient::BCC_RECIPIENT,
                                       "*****@*****.**",
                                       "Michael Carmichael"));

      msg.setSender ("Roy Kilroy <*****@*****.**>");

      msg.setSubject ("Rosetta Code");
      msg.setContent ("Sending mail from C++ using POCO C++ Libraries");

      SMTPClientSession smtp ("mail.example.com"); // SMTP server name
      smtp.login ();
      smtp.sendMessage (msg);
      smtp.close ();
      std::cerr << "Sent mail successfully!" << std::endl;
    }
  catch (std::exception &e)
    {
      std::cerr << "failed to send mail: " << e.what() << std::endl;
      return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}
Пример #21
0
void WorldSession::HandleMarkAsRead(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	recv_data >> mailbox >> message_id;

	MailMessage * message = _player->m_mailBox->GetMessage(message_id);
	if(message == 0 || message->Expired()) return;

	message->read_flag = true;
	if(!message->returned_flag)
	{
		// mail now has a 3 day expiry time
		if(!sMailSystem.MailOption(MAIL_FLAG_NO_EXPIRY))
			message->expire_time = (uint32)UNIXTIME + (TIME_DAY * 3);
	}
	message->SaveToDB();
}
Пример #22
0
void POP3ClientSession::retrieveMessage(int id, MailMessage& message, PartHandler& handler)
{
	std::string response;
	sendCommand("RETR", NumberFormatter::format(id), response);
	if (!isPositive(response)) throw POP3Exception("Cannot get message list", response);
	DialogInputStream sis(_socket);
	MailInputStream mis(sis);
	message.read(mis, handler);
	while (mis.good()) mis.get(); // read any remaining junk
}
Пример #23
0
void SMTPClientSession::transportMessage(const MailMessage& message)
{
	SocketOutputStream socketStream(_socket);
	MailOutputStream mailStream(socketStream);
	message.write(mailStream);
	mailStream.close();
	socketStream.flush();
	
	std::string response;
	int status = _socket.receiveStatusMessage(response);
	if (!isPositiveCompletion(status)) throw SMTPException("The server rejected the message", response, status);
}
Пример #24
0
void SendMail::sendMessage(const std::string& content)
{
    try {
        const Poco::Util::AbstractConfiguration* config = Poco::Util::Application::instance().config().createView("ion.mail");
        MailMessage message;
        message.setSender(config->getString("sender"));
        message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, config->getString("recipient")));
        message.setSubject(MailMessage::encodeWord(config->getString("subject"), "UTF-8"));
        message.setContentType("text/plain; charset=UTF-8");
        message.addContent(new Poco::Net::StringPartSource(content));
        Poco::Net::SocketAddress address(config->getString("host"), config->getInt("port"));
        Poco::SharedPtr<Poco::Net::StreamSocket> socket(nullptr);
        if (config->getBool("ssl")) {
            socket = new Poco::Net::SecureStreamSocket(address);
        }
        else {

            socket = new Poco::Net::StreamSocket(address);
        }
        _logger.debug("Connecting to %s", address.toString());
        SMTPClientSession session(*socket);
        session.login(getLoginMethod(config->getString("loginmethod")), config->getString("user"), config->getString("password"));
        session.sendMessage(message);
        session.close();
        _logger.debug("Message sent");
    }
    catch (Poco::Exception& ex) {
        _logger.error(ex.displayText());
        throw;
    }
}
Пример #25
0
void MailMessageTest::testReadMultiPart()
{
	std::istringstream istr(
		"Content-Type: multipart/mixed; boundary=MIME_boundary_01234567\r\n"
		"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
		"From: [email protected]\r\n"
		"Mime-Version: 1.0\r\n"
		"Subject: Test Message\r\n"
		"To: John Doe <*****@*****.**>\r\n"
		"\r\n"
		"\r\n"
		"--MIME_boundary_01234567\r\n"
		"Content-Disposition: inline\r\n"
		"Content-Transfer-Encoding: 8bit\r\n"
		"Content-Type: text/plain\r\n"
		"\r\n"
		"Hello World!\r\n"
		"\r\n"
		"--MIME_boundary_01234567\r\n"
		"Content-Disposition: attachment; filename=sample.dat\r\n"
		"Content-Transfer-Encoding: base64\r\n"
		"Content-Type: application/octet-stream; name=sample\r\n"
		"\r\n"
		"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
		"--MIME_boundary_01234567--\r\n"
	);
	
	StringPartHandler handler;
	MailMessage message;
	message.read(istr, handler);
	
	assert (handler.data().size() == 2);
	assert (handler.data()[0] == "Hello World!\r\n");
	assert (handler.type()[0] == "text/plain");
	assert (handler.disp()[0] == "inline");

	assert (handler.data()[1] == "This is some binary data. Really.");
	assert (handler.type()[1] == "application/octet-stream; name=sample");
	assert (handler.disp()[1] == "attachment; filename=sample.dat");
}
Пример #26
0
void WorldSession::HandleMailDelete(WorldPacket & recv_data )
{
	uint64 mailbox;
	uint32 message_id;
	recv_data >> mailbox >> message_id;

	WorldPacket data(SMSG_SEND_MAIL_RESULT, 12);
	data << message_id << uint32(MAIL_RES_DELETED);

	MailMessage * message = _player->m_mailBox->GetMessage(message_id);
	if(message == 0 || message->Expired())
	{
		data << uint32(MAIL_ERR_INTERNAL_ERROR);
		SendPacket(&data);
		return;
	}

	_player->m_mailBox->DeleteMessage(message);

	data << uint32(MAIL_OK);
	SendPacket(&data);
}
Пример #27
0
void MailMessageTest::testWriteQP()
{
	MailMessage message;
	MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "*****@*****.**", "John Doe");
	MailRecipient r2(MailRecipient::CC_RECIPIENT, "*****@*****.**", "Jane Doe");
	MailRecipient r3(MailRecipient::BCC_RECIPIENT, "*****@*****.**", "Frank Foo");
	MailRecipient r4(MailRecipient::BCC_RECIPIENT, "*****@*****.**", "Bernie Bar");
	message.addRecipient(r1);
	message.addRecipient(r2);
	message.addRecipient(r3);
	message.addRecipient(r4);
	message.setSubject("Test Message");
	message.setSender("*****@*****.**");
	message.setContent(
		"Hello, world!\r\n"
		"This is a test for the MailMessage class.\r\n"
		"To test the quoted-printable encoding, we'll put an extra long line here. This should be enough.\r\n"
		"And here is some more =fe.\r\n"
	);
	Timestamp ts(0);
	message.setDate(ts);
	
	assert (!message.isMultipart());
	
	std::ostringstream str;
	message.write(str);
	std::string s = str.str();

	assert (s == 
		"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
		"Content-Type: text/plain\r\n"
		"Subject: Test Message\r\n"
		"From: [email protected]\r\n"
		"Content-Transfer-Encoding: quoted-printable\r\n"
		"To: John Doe <*****@*****.**>\r\n"
		"CC: Jane Doe <*****@*****.**>\r\n"
		"\r\n"
		"Hello, world!\r\n"
		"This is a test for the MailMessage class.\r\n"
		"To test the quoted-printable encoding, we'll put an extra long line here. T=\r\n"
		"his should be enough.\r\n"
		"And here is some more =3Dfe.\r\n"
	);
}
Пример #28
0
void MailMessageTest::testReadDefaultTransferEncoding()
{
	std::istringstream istr(
		"Content-Type: text/plain\r\n"
		"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
		"From: [email protected]\r\n"
		"Subject: Test Message\r\n"
		"To: John Doe <*****@*****.**>\r\n"
		"\r\n"
		"Hello, world!\r\n"
		"This is a test for the MailMessage class.\r\n"
	);

	MailMessage message;
	message.read(istr);

	assert (message.getSender() == "*****@*****.**");
	assert (message.getContentType() == "text/plain");
	assert (message.getContent() ==
		"Hello, world!\r\n"
		"This is a test for the MailMessage class.\r\n"
	);
}
Пример #29
0
void MailMessageTest::testReadWriteMultiPart()
{
	std::string msgin(
		"Content-Type: multipart/mixed; boundary=MIME_boundary_31E8A8D61DF53389\r\n"
		"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
		"From: [email protected]\r\n"
		"Mime-Version: 1.0\r\n"
		"Subject: Test Message\r\n"
		"To: John Doe <*****@*****.**>\r\n"
		"\r\n"
		"--MIME_boundary_31E8A8D61DF53389\r\n"
		"Content-Disposition: inline\r\n"
		"Content-Transfer-Encoding: 8bit\r\n"
		"Content-Type: text/plain\r\n"
		"\r\n"
		"Hello World!\r\n"
		"\r\n"
		"--MIME_boundary_31E8A8D61DF53389\r\n"
		"Content-Disposition: attachment; filename=sample.dat\r\n"
		"Content-ID: abcd1234\r\n"
		"Content-Transfer-Encoding: base64\r\n"
		"Content-Type: application/octet-stream; name=sample\r\n"
		"\r\n"
		"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
		"--MIME_boundary_31E8A8D61DF53389--\r\n"
	);

	std::istringstream istr(msgin);
	std::ostringstream ostr;
	MailMessage message;

	message.read(istr);
	message.write(ostr);
	
	std::string msgout(ostr.str());
	assert (msgout == msgin);
}
Пример #30
0
void SMTPChannel::log(const Message& msg)
{
	try
	{
		MailMessage message;
		message.setSender(_sender);
		message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, _recipient));
		message.setSubject("Log Message from " + _sender);
		std::stringstream content;
		content << "Log Message\r\n"
			<< "===========\r\n\r\n"
			<< "Host: " << Environment::nodeName() << "\r\n"
			<< "Logger: " << msg.getSource() << "\r\n";

		if (_local)
		{
			DateTime dt(msg.getTime());
			content	<< "Timestamp: " << DateTimeFormatter::format(LocalDateTime(dt), DateTimeFormat::RFC822_FORMAT) << "\r\n";
		}
		else
			content	<< "Timestamp: " << DateTimeFormatter::format(msg.getTime(), DateTimeFormat::RFC822_FORMAT) << "\r\n";

		content	<< "Priority: " << NumberFormatter::format(msg.getPriority()) << "\r\n"
			<< "Process ID: " << NumberFormatter::format(msg.getPid()) << "\r\n"
			<< "Thread: " << msg.getThread() << " (ID: " << msg.getTid() << ")\r\n"
			<< "Message text: " << msg.getText() << "\r\n\r\n";

		message.addContent(new StringPartSource(content.str()));
	
		if (!_attachment.empty())
		{
			{
				Poco::FileInputStream fis(_attachment, std::ios::in | std::ios::binary | std::ios::ate);
				if (fis.good())
				{
					int size = fis.tellg();
					char* pMem = new char [size];
					fis.seekg(std::ios::beg);
					fis.read(pMem, size);
					message.addAttachment(_attachment, new StringPartSource(std::string(pMem, size), _type, _attachment));
					delete [] pMem;
				}
			}
			if (_delete) File(_attachment).remove();
		}

		SMTPClientSession session(_mailHost);
		session.login();
		session.sendMessage(message);
		session.close();
	} 
	catch (Exception&) 
	{ 
		if (_throw) throw; 
	}
}