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.

* should be deleted.<br />

*/<br />

public boolean keepMail(MimeMessage message)<br />

{<br />

try<br />

{<br />

try<br />

{<br />

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

Debugger.debug(getClass(), 1, "Testing if it is a notificationmail....");<br />

String[] note = message.getHeader(Config.headerNotificationName);<br />

if(note == null || note.length == 0)<br />

throw new Exception("Could not read notificationinfo.");<br />

try<br />

{<br />

Debugger.debug(getClass(), 1, "It is a notificationmail.");<br />

NotificationHeader header =<br />

(NotificationHeader)MimeTools.getCoinsHeader(message);<br />

long serial = header.serialNumber;<br />

//Verify signature...<br />

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

(message.getRecipients(Message.RecipientType.TO)[0]).toString());<br />

if(Cryptotools.verify((RSAPublicKey)control.getCertificate().getPublicKey(),header.getSig<br />

nature(),hash))<br />

{<br />

Debugger.debug(getClass(), 1, "Verifying signature...success");<br />

if(control.deleteCoinWithSerial(header.serialNumber))<br />

{<br />

Debugger.debug(getClass(), 1, "C-coin deleted<br />

successfully.");<br />

}<br />

else<br />

{<br />

Debugger.debug(getClass(), 1, "Could not delete C-coin.");<br />

}<br />

}<br />

else<br />

Debugger.debug(getClass(), 1, "Verifying signature...failed");<br />

return false;<br />

}<br />

catch(Exception ex)<br />

{<br />

Debugger.debug(getClass(), 3, "Error reading notificationdata.",ex);<br />

return false;<br />

}<br />

}<br />

catch(Exception ex)<br />

{<br />

Debugger.debug(getClass(), 3, "Error handling notificationmail.",ex);<br />

}<br />

Debugger.debug(getClass(), 1, "It is NOT a notificationmail.");<br />

String[] from = message.getHeader("From");<br />

if(from.length > 1)<br />

{<br />

Debugger.debug(getClass(), 1,<br />

"FATAL! more than one sender. Unable to filter mail<br />

correctly. Deleting mail!");<br />

return false;<br />

}<br />

//If the sender is on the whitelist we should keep the mail.<br />

if(control.isOnWhitelist(from[0]))<br />

{<br />

266

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

Saved successfully!

Ooh no, something went wrong!