29.07.2013 Views

Master of Science thesis Fighting Spam

Master of Science thesis Fighting Spam

Master of Science thesis Fighting Spam

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

public OutgoingMailProcessor(Control control)<br />

{<br />

this.control = control;<br />

}<br />

public MimeMessage processMail(MimeMessage extm) throws MessagingException, Exception<br />

{<br />

MimeTools.writeMimeFile(extm,"d:\\original.msg");<br />

Address[] to = extm.getRecipients(Message.RecipientType.TO);<br />

String receivers = "";<br />

for(int i = 0; i < to.length; i++)<br />

receivers += to[i].toString();<br />

Debugger.debug(getClass(), 1, "Processing mail to: " + receivers);<br />

//try<br />

//{<br />

Debugger.debug(getClass(), 2, "Attaching coin...");<br />

//Just using 1 coin at the moment<br />

Coin[] coins = control.getCoinsToSend(1,to);<br />

//Create signature 1<br />

Signature recipientSignature =<br />

createRecipientSignature(coins[0].getSerialNumber(), extm);<br />

//Create signature 2<br />

Signature mailSignature = createMailSignature(extm);<br />

//Add all the parts to the email...<br />

CoinHeader header = new CoinHeader(recipientSignature, mailSignature,<br />

coins[0], control.getCertificate());<br />

}<br />

MimeMessage extm2 = MimeTools.addAttachmentHeader(extm, header);<br />

Debugger.debug(getClass(), 2, "Done.");<br />

//MimeTools.writeMimeFile(extm2,"d:\\outgoing.msg");<br />

return extm2;<br />

// Allow sending without attachment<br />

/*}<br />

catch(Exception e)<br />

{<br />

Debugger.debug(getClass(), 2, "Exception...cannot attach.", e);<br />

Debugger.debug(getClass(), 2, "Sending without attachment...");<br />

return extm;<br />

}*/<br />

private Signature createRecipientSignature(long serialNumber, MimeMessage msg) throws<br />

Exception<br />

{<br />

Debugger.debug(getClass(), 2, "Creating Recipient signature...");<br />

Fingerprint recipientHash = Coin.getHash2(serialNumber,<br />

((InternetAddress)msg.getRecipients(Message.RecipientType.TO)[0]).getAddress());<br />

return Cryptotools.sign(control.getPrivateKey(), recipientHash);<br />

}<br />

private Signature createMailSignature(MimeMessage extm) throws MessagingException,<br />

Exception<br />

{<br />

Debugger.debug(getClass(), 2, "Creating Mail signature...");<br />

return Cryptotools.sign(control.getPrivateKey(),<br />

MailFunctions.createMailHash(extm));<br />

}<br />

}<br />

269

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!