cern.jira.emailhandler
Class MessageParser

java.lang.Object
  extended by cern.jira.emailhandler.MessageParser

public class MessageParser
extends java.lang.Object

A class containing some useful method to parse a message.

Released under the BSD License: see file license.txt for details.

Version:
3.0 (19-3-2009)
Author:
Daniele Raffo

Field Summary
private static Category log
           
static java.lang.String REGEX_ANYCHAR
          Regex for "any number of characters, even zero".
 
Constructor Summary
MessageParser()
           
 
Method Summary
static java.lang.String emailAddressToRegex(java.lang.String emailAddress)
          Transforms an email address into a regular expression matching that address.
static java.lang.String getFullnameFromHeader(java.lang.String emailAddress, java.lang.String fullEmail)
          Extract the "Full Name" part from a full email address (which could be contained in a From:, To:, Cc:, or Bcc: header).
static java.lang.String getRecipientFromMessage(java.lang.String recipient, Message message)
          Retrieves the To:, CCc:, or Bcc: header purporting to a given recipient of a email message.
static IssueDescriptor parse(Message message, java.lang.String[] emailAddresses)
          Parses a message that contains directives about an issue.
private static void parseSubject(java.lang.String subject, IssueDescriptorImpl issue)
          Extracts issue attributes from the email subject and assign them to issue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Category log

REGEX_ANYCHAR

public static final java.lang.String REGEX_ANYCHAR
Regex for "any number of characters, even zero".

See Also:
Constant Field Values
Constructor Detail

MessageParser

public MessageParser()
Method Detail

parse

public static final IssueDescriptor parse(Message message,
                                          java.lang.String[] emailAddresses)
Parses a message that contains directives about an issue.

Parameters:
message - the message to parse
emailAddresses - an array defining all JIRA email addresses
Returns:
a descriptor of the issue, following the directives extracted from message

parseSubject

private static final void parseSubject(java.lang.String subject,
                                       IssueDescriptorImpl issue)
Extracts issue attributes from the email subject and assign them to issue.


getRecipientFromMessage

public static final java.lang.String getRecipientFromMessage(java.lang.String recipient,
                                                             Message message)
                                                      throws MessagingException
Retrieves the To:, CCc:, or Bcc: header purporting to a given recipient of a email message.

Parameters:
recipient - a regex describing the recipient email address
message - an email message
Returns:
the header of message containing recipient, or null if the recipient was not found
Throws:
MessagingException - if there were problems handling the message

getFullnameFromHeader

public static final java.lang.String getFullnameFromHeader(java.lang.String emailAddress,
                                                           java.lang.String fullEmail)
Extract the "Full Name" part from a full email address (which could be contained in a From:, To:, Cc:, or Bcc: header). E.g. if fullEmail is "Arthur Dent <arthur@vogon.org>" and emailAddress is "arthur@vogon\\.org", it returns "Arthur Dent". This method correctly manages the fact that the emailclient could surround email address and/or full name with characters like <> " ' () , etc.

Parameters:
emailAddress - a regex specifying the bare email address to extract
fullEmail - the full email address
Returns:
the Full Name

emailAddressToRegex

public static final java.lang.String emailAddressToRegex(java.lang.String emailAddress)
Transforms an email address into a regular expression matching that address.

Parameters:
emailAddress - an email address of kind user.login@domain.xx
Returns:
a regex matching emailAddress