Пример #1
0
  private static final String getAppleMailParam(final String subject, final String body) {
    final List<String> l = new ArrayList<String>(3);
    l.add("visible:true");
    if (subject != null) l.add(createASParam("subject", subject));
    if (body != null) l.add(createASParam("content", body));

    return CollectionUtils.join(l, ", ");
  }
Пример #2
0
  // see http://kb.mozillazine.org/Command_line_arguments_(Thunderbird)
  // The escape mechanism isn't specified, it turns out we can pass percent encoded strings
  private static final String getTBParam(
      final String to, final String subject, final String body, final File... attachments) {
    // "to='[email protected],[email protected]',cc='*****@*****.**',subject='dinner',body='How
    // about dinner
    // tonight?',attachment='file:///C:/cygwin/Cygwin.bat,file:///C:/cygwin/Cygwin.ico'";

    final List<String> l = new ArrayList<String>(4);
    if (to != null) l.add(createEncodedParam("to", to));
    if (subject != null) l.add(createEncodedParam("subject", subject));
    if (body != null) l.add(createEncodedParam("body", body));
    final List<String> urls = new ArrayList<String>(attachments.length);
    for (final File attachment : attachments) {
      // Thunderbird doesn't parse java URI file:/C:/
      final String rawPath = attachment.toURI().getRawPath();
      // handle UNC paths
      final String tbURL = (rawPath.startsWith("//") ? "file:///" : "file://") + rawPath;
      urls.add(tbURL);
    }
    l.add(createEncodedParam("attachment", CollectionUtils.join(urls, ",")));

    return DesktopEnvironment.getDE().quoteParamForExec(CollectionUtils.join(l, ","));
  }
Пример #3
0
  /**
   * Create a mailto URI.
   *
   * @param to the recipient, can be <code>null</code>.
   * @param subject the subject, can be <code>null</code>.
   * @param body the body of the email, can be <code>null</code>.
   * @param attachments files to attach, for security reason this parameter is ignored by at least
   *     Outlook 2007, Apple Mail and Thunderbird.
   * @return the mailto URI.
   * @throws IOException if an encoding error happens.
   * @see <a href="http://tools.ietf.org/html/rfc2368">RFC 2368</a>
   * @see <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=67254">Don&apos;t allow attachment
   *     of local file from non-local link</a>
   */
  public static final URI getMailToURI(
      final String to, final String subject, final String body, final File... attachments)
      throws IOException {
    // mailto:[email protected]?subject=Sujet%20du%20courrier&[email protected]&[email protected]&body=Bonjour

    // Outlook doesn't support the to header as mandated by 2. of the RFC
    final String encodedTo = to == null ? "" : PercentEncoder.encode(to, StringUtils.UTF8);
    final List<String> l = new ArrayList<String>(4);
    if (subject != null) l.add(createEncodedParam("subject", subject));
    if (body != null) l.add(createEncodedParam("body", body));
    for (final File attachment : attachments)
      l.add(createEncodedParam("attachment", attachment.getAbsolutePath()));
    final String query = CollectionUtils.join(l, "&");
    try {
      return new URI("mailto:" + encodedTo + "?" + query);
    } catch (URISyntaxException e) {
      throw new IOException("Couldn't create mailto URI", e);
    }
  }