com.openexchange.mail.json.parser
Class MessageParser

java.lang.Object
  extended by com.openexchange.mail.json.parser.MessageParser

public final class MessageParser
extends java.lang.Object

MessageParser - Parses instances of JSONObject to instances of MailMessage.

Author:
Thorben Betten, Tobias Prinz - parseBasics(JSONObject, MailMessage, TimeZone)

Method Summary
static javax.mail.internet.InternetAddress[] getFromField(org.json.JSONObject jo)
          Parses "From" field out of passed JSON object.
static void parse(org.json.JSONObject jsonObj, MailMessage mail, com.openexchange.session.Session session, int accountId)
          Parses given instance of JSONObject to given instance of MailMessage.
static void parse(org.json.JSONObject jsonObj, MailMessage mail, java.util.TimeZone timeZone, com.openexchange.session.Session session, int accountId)
          Parses given instance of JSONObject to given instance of MailMessage.
static ComposedMailMessage parse4Draft(org.json.JSONObject jsonObj, com.openexchange.groupware.upload.impl.UploadEvent uploadEvent, com.openexchange.session.Session session, int accountId)
          Completely parses given instance of JSONObject and given instance of UploadEvent to a corresponding ComposedMailMessage object dedicated for being saved as a draft message.
static ComposedMailMessage[] parse4Transport(org.json.JSONObject jsonObj, com.openexchange.groupware.upload.impl.UploadEvent uploadEvent, com.openexchange.session.Session session, int accountId, java.lang.String protocol, java.lang.String hostName)
          Completely parses given instance of JSONObject and given instance of UploadEvent to corresponding ComposedMailMessage objects dedicated for being sent.
static javax.mail.internet.InternetAddress[] parseAddressKey(java.lang.String key, org.json.JSONObject jo)
          Parses address field out of passed JSON object.
static javax.mail.internet.InternetAddress[] parseAddressKey(java.lang.String key, org.json.JSONObject jo, boolean failOnError)
          Parses address field out of passed JSON object.
static void parseBasics(org.json.JSONObject jsonObj, MailMessage mail, java.util.TimeZone timeZone)
          Takes a mail as jsonObj and extracts the values into a given MailMessage object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parse4Draft

public static ComposedMailMessage parse4Draft(org.json.JSONObject jsonObj,
                                              com.openexchange.groupware.upload.impl.UploadEvent uploadEvent,
                                              com.openexchange.session.Session session,
                                              int accountId)
                                       throws MailException
Completely parses given instance of JSONObject and given instance of UploadEvent to a corresponding ComposedMailMessage object dedicated for being saved as a draft message. Moreover the user's quota limitations are considered.

Parameters:
jsonObj - The JSON object
uploadEvent - The upload event containing the uploaded files to attach
session - The session
accountId - The account ID
Returns:
A corresponding instance of ComposedMailMessage
Throws:
MailException - If parsing fails

parse4Transport

public static ComposedMailMessage[] parse4Transport(org.json.JSONObject jsonObj,
                                                    com.openexchange.groupware.upload.impl.UploadEvent uploadEvent,
                                                    com.openexchange.session.Session session,
                                                    int accountId,
                                                    java.lang.String protocol,
                                                    java.lang.String hostName)
                                             throws MailException
Completely parses given instance of JSONObject and given instance of UploadEvent to corresponding ComposedMailMessage objects dedicated for being sent. Moreover the user's quota limitations are considered.

Parameters:
jsonObj - The JSON object
uploadEvent - The upload event containing the uploaded files to attach
session - The session
accountId - The account ID
protocol - The server's protocol
hostname - The server's host name
Returns:
The corresponding instances of ComposedMailMessage
Throws:
MailException - If parsing fails

parse

public static void parse(org.json.JSONObject jsonObj,
                         MailMessage mail,
                         com.openexchange.session.Session session,
                         int accountId)
                  throws MailException
Parses given instance of JSONObject to given instance of MailMessage. Moreover the user's quota limitations are considered.

Parameters:
jsonObj - The JSON object (source)
mail - The mail(target), which should be empty
session - The session
accountId - The account ID
Throws:
MailException - If parsing fails

parse

public static void parse(org.json.JSONObject jsonObj,
                         MailMessage mail,
                         java.util.TimeZone timeZone,
                         com.openexchange.session.Session session,
                         int accountId)
                  throws MailException
Parses given instance of JSONObject to given instance of MailMessage. Moreover the user's quota limitations are considered.

Parameters:
jsonObj - The JSON object (source)
mail - The mail(target), which should be empty
timeZone - The user time zone
session - The session
accountId - The account ID
Throws:
MailException - If parsing fails

parseBasics

public static void parseBasics(org.json.JSONObject jsonObj,
                               MailMessage mail,
                               java.util.TimeZone timeZone)
                        throws org.json.JSONException,
                               javax.mail.internet.AddressException,
                               MailException
Takes a mail as jsonObj and extracts the values into a given MailMessage object. Handles all basic values that do not need information about the session, like attachments.

Parameters:
jsonObj -
mail -
timeZone -
Throws:
org.json.JSONException
javax.mail.internet.AddressException
MailException

getFromField

public static javax.mail.internet.InternetAddress[] getFromField(org.json.JSONObject jo)
                                                          throws javax.mail.internet.AddressException,
                                                                 org.json.JSONException
Parses "From" field out of passed JSON object.

Parameters:
jo - The JSON object
Returns:
The parsed "From" address
Throws:
javax.mail.internet.AddressException - If parsing the address fails
org.json.JSONException - If a JSON error occurred

parseAddressKey

public static javax.mail.internet.InternetAddress[] parseAddressKey(java.lang.String key,
                                                                    org.json.JSONObject jo)
                                                             throws org.json.JSONException,
                                                                    javax.mail.internet.AddressException
Parses address field out of passed JSON object.

Parameters:
key - The key of the address field
jo - The JSON object
Returns:
The parsed address(es)
Throws:
org.json.JSONException - If a JSON error occurred
javax.mail.internet.AddressException - If parsing an address fails

parseAddressKey

public static javax.mail.internet.InternetAddress[] parseAddressKey(java.lang.String key,
                                                                    org.json.JSONObject jo,
                                                                    boolean failOnError)
                                                             throws org.json.JSONException,
                                                                    javax.mail.internet.AddressException
Parses address field out of passed JSON object.

Parameters:
key - The key of the address field
jo - The JSON object
Returns:
The parsed address(es)
Throws:
org.json.JSONException - If a JSON error occurred
javax.mail.internet.AddressException - If parsing an address fails