Class MailToBuilder

java.lang.Object
com.ptc.windchill.enterprise.mail.MailToBuilder

public class MailToBuilder extends Object
Builder for creating mail-client specific compliant mailto: links following guidelines from RFC-2368. The mail-client is used to process differences between some of the major Email clients such as Microsoft Outlook and Mozilla Thunderbird.

On certain platforms, such as Microsoft Windows, mailto links can only be processed if their total length is less than a defined characters limit (see CHARACTER_LIMIT). By default, the MailToBuilder will enforce this character limit on calls to toString( ) unless otherwise stated through the constructor MailToBuilder( boolean ). If the limit is exceeded, a StringIndexOutOfBoundsException will be thrown from calls to toString( ).

All header keys and values will be escaped in the URI Query string.

Supported API: true
  • Constructor Details

    • MailToBuilder

      public MailToBuilder() throws WTException
      Creates a new mailto builder. The user's preferred Email client will be used to setup the mailto link separator.

      Supported API: true
      Throws:
      WTException - Thrown if an error occurs obtaining the users preferred Email client.
    • MailToBuilder

      public MailToBuilder(boolean enforceLimit) throws WTException
      Creates a new mailto builder that will conditionally enforce the character limit on mailto creation. The user's preferred Email client will be used to setup the mailto link separator.

      Supported API: true
      Parameters:
      enforceLimit - Whether to enforce the character limit
      Throws:
      WTException - Thrown if an error occurs obtaining the users preferred Email client.
  • Method Details

    • isCharacterLimitEnforced

      public boolean isCharacterLimitEnforced()
      Whether the character limit is enforced for mailto generation.

      Supported API: true
      Returns:
      The enforcement flag.
    • setCharacterLimitEnforced

      public void setCharacterLimitEnforced(boolean enforce)
      Set whether the character limit is enforced for mailto generation.

      Supported API: true
      Parameters:
      enforce -
    • addRecipient

      public void addRecipient(String email)
      Add the specified recipient's Email to the list of recipients.

      Supported API: true
      Parameters:
      email - The recipient's email to add
    • addRecipients

      public void addRecipients(Collection<String> emails)
      Add the collection of recipients.

      Supported API: true
      Parameters:
      emails - Collection of emails to add as recipients.
    • getRecipients

      public List<String> getRecipients()
      Return all current recipients.

      Supported API: true
      Returns:
      The list of recipient Emails.
    • addHeader

      public void addHeader(String key, String value)
      Add a header key/value pair to the generated mailto link. Both the key and value will be URI encoded. The output will be separated by a '='.

      Supported API: true
      Parameters:
      key - The key of the header
      value - The value of the header.
    • setSubject

      public void setSubject(String subject)
      Sets the subject header of the mailto link. The subject will be URI encoded.

      Supported API: true
      Parameters:
      subject - The subject to add.
    • setBody

      public void setBody(String body)
      Sets the body header of the mailto link. The body will be URI encoded.

      Supported API: true
      Parameters:
      body -
    • output

      public void output(StringBuilder buf)
      Will output the mailto link to the specified buffer in an URI-compliant manner. If no recipients are present, the content of the mailto link will start with the "?" query string.

      Note: This method does not enforce the character limit. It only outputs a URI-compliant mailto link. The toString() method should be used to generate mailto links for most usages.

      Supported API: true
      Parameters:
      buf - The string builder to append the mailto link to.
    • toString

      public String toString() throws StringIndexOutOfBoundsException
      Convert the MailToBuilder to a URI-compliant string. If the character limit is being enforced, and the generated URI-compliant string exceeds the character limit a StringIndexOutOfBoundsException will be thrown.

      Supported API: true
      Overrides:
      toString in class Object
      Returns:
      The generated string for the URI-compliant mailto link.
      Throws:
      StringIndexOutOfBoundsException - output exceeds character limit if enabled.
    • getSeparator

      public static String getSeparator() throws WTException
      Retrieves the separator character for use with the user's preferred Email client. The preference /PreferredEmailClient will be checked for a valid known email client and the correct separator returned.

      If no preference is defined, or it is not a known Email client, the value W3C_SEPARATOR will be used.

      Supported API: true
      Returns:
      The defined separator for the user's preferred Email client.
      Throws:
      WTException - Thrown if the preferred client can not be determined.
      See Also: