org.semanticdesktop.aperture.crawler.mail
Class MailUtil

java.lang.Object
  extended by org.semanticdesktop.aperture.crawler.mail.MailUtil

public class MailUtil
extends Object

Utility methods for JavaMail.


Nested Class Summary
static class MailUtil.LiberalInternetAddress
           
 
Constructor Summary
MailUtil()
           
 
Method Summary
static void addAddressMetadata(javax.mail.internet.InternetAddress address, URI predicate, RDFContainer metadata)
          Add statements modeling the specified address metadata to the RDFContainer, using the specified predicate to connect the address resource to the mail resource.
static void addAddressMetadata(MailUtil.LiberalInternetAddress address, URI predicate, RDFContainer metadata)
          Add statements modeling the specified address metadata to the RDFContainer, using the specified predicate to connect the address resource to the mail resource.
static String decodeText(String encodedText)
          Alternative for MimeUtility.decodeText(String) with a less strict parsing algorithm.
static List<MailUtil.LiberalInternetAddress> getAddressHeader(javax.mail.Message msg, String name)
           
static String getHash(javax.mail.internet.MimeMessage msg)
          Returns the hash of the message.
static String getMessageId(javax.mail.internet.MimeMessage message)
          Returns a string containing the id of the message together with its hash.
static String getMessageIdWithHeadersHash(javax.mail.Message message)
          Returns a string containing the id of the message together with its hash.
static URI getParent(DataObject object)
           Returns the URI of the object's parent in the containment hierachy.
static String getPersonURI(String email, String name)
          Derive a URI for a person based on an email address and a name that can be used in an RDF graph.
static Date getStereotypicalContentCreatedDate(javax.mail.Message message)
          Returns the stereotypical date of a Message.
static List<MailUtil.LiberalInternetAddress> parseAddressHeaderValue(String header)
          Parses a value of an address header and extracts email addresses.
static Date parseReceivedHeader(String st)
          Parses a single "Received" header and extracts the date time from it.
static void registerParentRelationshipInAccessData(DataObject object, AccessData accessData)
           Stores in the AccessData the fact that the given object has a parent.
static String utf7Decode(String input)
          Converts in the UTF7 encoding to it's "normal" UTF16 representation.
static String utf7Encode(String input)
          Converts a string (possibly containing non-ascii characters) to it's representation in the UTF7-IMAP encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MailUtil

public MailUtil()
Method Detail

utf7Encode

public static String utf7Encode(String input)
Converts a string (possibly containing non-ascii characters) to it's representation in the UTF7-IMAP encoding. E.g for 'Böser' 'B&APY-ser' is returned.

Parameters:
input - the input string
Returns:
a representation of the input string with all non-ascii characters converted to their UTF7 escape sequences

utf7Decode

public static String utf7Decode(String input)
Converts in the UTF7 encoding to it's "normal" UTF16 representation.

Parameters:
input - the input string in UTF7
Returns:
a 'normal' representation of the input string with UTF7 escape sequences converted to single UTF16 characters

getAddressHeader

public static List<MailUtil.LiberalInternetAddress> getAddressHeader(javax.mail.Message msg,
                                                                     String name)
                                                              throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

parseAddressHeaderValue

public static List<MailUtil.LiberalInternetAddress> parseAddressHeaderValue(String header)
Parses a value of an address header and extracts email addresses.

Parameters:
header -
Returns:

decodeText

public static String decodeText(String encodedText)
Alternative for MimeUtility.decodeText(String) with a less strict parsing algorithm. The algorithm is (and will be) tuned to what we see "in the wild".

Parameters:
encodedText - The RFC 2047 encoded text.
Returns:
The decoded text.

getStereotypicalContentCreatedDate

public static Date getStereotypicalContentCreatedDate(javax.mail.Message message)
                                               throws javax.mail.MessagingException
Returns the stereotypical date of a Message. This is equal to the sent date or, if not available, the received date.

Parameters:
message - the message we want to get the date for
Returns:
the stereotypical date of a message, or 'null' when there is no such date.
Throws:
javax.mail.MessagingException

addAddressMetadata

public static void addAddressMetadata(javax.mail.internet.InternetAddress address,
                                      URI predicate,
                                      RDFContainer metadata)
Add statements modeling the specified address metadata to the RDFContainer, using the specified predicate to connect the address resource to the mail resource.

Parameters:
address - The InternetAddress that will be encoded in the RDF model.
predicate - The property URI that will be used to connect the address metadata to the mail resource.
metadata - The RDFContainer that will receive the RDF statements and whose described URI is expected to represent the mail resource.

addAddressMetadata

public static void addAddressMetadata(MailUtil.LiberalInternetAddress address,
                                      URI predicate,
                                      RDFContainer metadata)
Add statements modeling the specified address metadata to the RDFContainer, using the specified predicate to connect the address resource to the mail resource.

Parameters:
address - The InternetAddress that will be encoded in the RDF model.
predicate - The property URI that will be used to connect the address metadata to the mail resource.
metadata - The RDFContainer that will receive the RDF statements and whose described URI is expected to represent the mail resource.

getPersonURI

public static String getPersonURI(String email,
                                  String name)
                           throws IllegalArgumentException
Derive a URI for a person based on an email address and a name that can be used in an RDF graph. At least one of these properties has to have a real value.

Parameters:
email - The email address of the person (optional).
name - The name of the person (optional).
Returns:
A URI String that can be used to model the person.
Throws:
IllegalArgumentException - when both the email address and the name do not have reasonable values.

registerParentRelationshipInAccessData

public static void registerParentRelationshipInAccessData(DataObject object,
                                                          AccessData accessData)

Stores in the AccessData the fact that the given object has a parent.

This method first searches for the parent for the given data object (see getParent(DataObject) If it finds one, it puts a reference between the two. (see AccessData.putReferredID(String, String)).

The parent must already exist within the access data. (see AccessData.isKnownId(String)). Otherwise this method won't do anything. This enforces that parents must be crawled and stored in the access data before their children.

Parameters:
object - the object whose parent is to be recorded in the access data
accessData - the access data where the parent-child relationship is to be recorded, it must already know the parent (AccessData.isKnownId(String))

getParent

public static URI getParent(DataObject object)

Returns the URI of the object's parent in the containment hierachy.

B is a parent of A is there exists a triple A nie:isPartOf B. In case there is more than one such resource, or the resource is not an URI, this method returns null.

Parameters:
object - the object whose parent we're looking
Returns:
the parent of the given object or null if none exists

parseReceivedHeader

public static Date parseReceivedHeader(String st)
                                throws ParseException
Parses a single "Received" header and extracts the date time from it. Returns it as a Date instance

Parameters:
st - the "Received" header content (without the 'Received: ') prefix itself.
Returns:
an instance of Date for the reception date extracted from this header
Throws:
ParseException

getMessageId

public static String getMessageId(javax.mail.internet.MimeMessage message)
                           throws javax.mail.MessagingException
Returns a string containing the id of the message together with its hash. It is of the form
 <messageIdValue>-<messageHash>
where:

Parameters:
message -
Returns:
Throws:
javax.mail.MessagingException

getHash

public static String getHash(javax.mail.internet.MimeMessage msg)
                      throws javax.mail.MessagingException,
                             IOException
Returns the hash of the message.
The entire content (headers + body) is taken into account.

Parameters:
msg -
Returns:
Throws:
javax.mail.MessagingException
IOException

getMessageIdWithHeadersHash

public static String getMessageIdWithHeadersHash(javax.mail.Message message)
                                          throws javax.mail.MessagingException
Returns a string containing the id of the message together with its hash. It is of the form
 <messageIdValue>-<messageHash>
where:

Parameters:
message -
Returns:
Throws:
javax.mail.MessagingException


Copyright © 2010 Aperture Development Team. All Rights Reserved.