commons-email-1.5-src/README.txt 0100664 0001750 0001750 00000003170 13137110666 017574 0 ustar 00stefan stefan 0000000 0000000
Email
-----
Getting started:
1) Build the jar file
If you have the source distribution you will need to build the jar file
using Maven 2. For instructions on downloading and installing Maven see
http://maven.apache.org/.
To build execute the command 'mvn package'. The jar file will be built in the
target directory.
2) Generate the documentation
Run the 'mvn site' command. The documentation will be written
to the target/site directory. The documentation has some examples of
how to use this package as well as a FAQ.
3) Create source and binary distributions
Run the 'mvn site assembly:assembly' command. The source and binary
distributions are created in the 'target' directory.
4) Use
Simply include the jar file built in step #1 in your classpath. Import the
classes that you want to use and you are ready to go!
commons-email-1.5-src/NOTICE.txt 0100664 0001750 0001750 00000000256 13137110665 017621 0 ustar 00stefan stefan 0000000 0000000 Apache Commons Email
Copyright 2001-2017 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
commons-email-1.5-src/LICENSE.txt 0100664 0001750 0001750 00000026136 13137110665 017727 0 ustar 00stefan stefan 0000000 0000000
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
commons-email-1.5-src/RELEASE-NOTES.txt 0100664 0001750 0001750 00000025330 13137110665 020606 0 ustar 00stefan stefan 0000000 0000000 Commons Email Package
Version 1.5
Release Notes
INTRODUCTION:
-------------
Commons Email aims to provide a API for sending email. It builds on the JavaMail
API with the aim of presenting a simplified API which is easy for developers who
are not mail experts to use. It is a compact component with a small number of
classes.
The Commons Email website is the source for the most recent information,
downloads, reports, and bug status:
http://commons.apache.org/email/
This is a major release which adds some new features and fixes several bugs
present in the 1.4.0 release. All current users are encouraged to upgrade.
CHANGES FROM 1.4:
-----------------
== Compatibility ==
* Java 6 or later is required.
* JavaMail dependency has been upgraded to version 1.5.6,
as a consequence, the maven dependency has changed to:
DataSource
based on an URL.
*
* @since 1.3
*/
public class DataSourceUrlResolver extends DataSourceBaseResolver
{
/** the base url of the resource when resolving relative paths */
private final URL baseUrl;
/**
* Constructor.
*
* @param baseUrl the base URL used for resolving relative resource locations
*/
public DataSourceUrlResolver(final URL baseUrl)
{
super();
this.baseUrl = baseUrl;
}
/**
* Constructor.
*
* @param baseUrl the base URL used for resolving relative resource locations
* @param lenient shall we ignore resources not found or complain with an exception
*/
public DataSourceUrlResolver(final URL baseUrl, final boolean lenient)
{
super(lenient);
this.baseUrl = baseUrl;
}
/**
* Get the base URL used for resolving relative resource locations.
*
* @return the baseUrl
*/
public URL getBaseUrl()
{
return baseUrl;
}
/** {@inheritDoc} */
@Override
public DataSource resolve(final String resourceLocation) throws IOException
{
return resolve(resourceLocation, isLenient());
}
/** {@inheritDoc} */
@Override
public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
{
DataSource result = null;
try
{
if (!isCid(resourceLocation))
{
final URL url = createUrl(resourceLocation);
result = new URLDataSource(url);
result.getInputStream();
}
return result;
}
catch (final IOException e)
{
if (isLenient)
{
return null;
}
throw e;
}
}
/**
* Create an URL based on a base URL and a resource location suitable for loading
* the resource.
*
* @param resourceLocation a resource location
* @return the corresponding URL
* @throws java.net.MalformedURLException creating the URL failed
*/
protected URL createUrl(final String resourceLocation) throws MalformedURLException
{
// if we get an non-existing base url than the resource can
// be directly used to create an URL
if (baseUrl == null)
{
return new URL(resourceLocation);
}
// if we get an non-existing location what we shall do?
if (resourceLocation == null || resourceLocation.length() == 0)
{
throw new IllegalArgumentException("No resource defined");
}
// if we get a stand-alone resource than ignore the base url
if (isFileUrl(resourceLocation) || isHttpUrl(resourceLocation))
{
return new URL(resourceLocation);
}
return new URL(getBaseUrl(), resourceLocation.replaceAll("&", "&"));
}
}
././@LongLink 0100644 0000000 0000000 00000000146 13137110666 011640 L ustar 0000000 0000000 commons-email-1.5-src/src/main/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java commons-email-1.5-src/src/main/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.jav0100664 0001750 0001750 00000007356 13137110666 035153 0 ustar 00stefan stefan 0000000 0000000 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.mail.resolver;
import org.apache.commons.mail.DataSourceResolver;
import javax.activation.DataSource;
import java.io.IOException;
/**
* A composite data source resolver. It allows to resolve data sources coming from
* multiple locations such as the classpath, the file system or an URL.
*
* @since 1.3
*/
public class DataSourceCompositeResolver extends DataSourceBaseResolver
{
/** the list of resolvers */
private final DataSourceResolver[] dataSourceResolvers;
/**
* Constructor.
*
* @param dataSourceResolvers a list of of resolvers being used
*/
public DataSourceCompositeResolver(final DataSourceResolver[] dataSourceResolvers)
{
this.dataSourceResolvers = new DataSourceResolver[dataSourceResolvers.length];
System.arraycopy(dataSourceResolvers, 0, this.dataSourceResolvers, 0, dataSourceResolvers.length);
}
/**
* Constructor.
*
* @param dataSourceResolvers a list of of resolvers being used
* @param isLenient shall we ignore resources not found or throw an exception?
*/
public DataSourceCompositeResolver(final DataSourceResolver[] dataSourceResolvers, final boolean isLenient)
{
super(isLenient);
this.dataSourceResolvers = new DataSourceResolver[dataSourceResolvers.length];
System.arraycopy(dataSourceResolvers, 0, this.dataSourceResolvers, 0, dataSourceResolvers.length);
}
/**
* Get the underlying data source resolvers.
*
* @return underlying data source resolvers
*/
public DataSourceResolver[] getDataSourceResolvers()
{
// clone the internal array to prevent external modification (see EMAIL-116)
final DataSourceResolver[] resolvers = new DataSourceResolver[dataSourceResolvers.length];
System.arraycopy(dataSourceResolvers, 0, resolvers, 0, dataSourceResolvers.length);
return resolvers;
}
/** {@inheritDoc} */
@Override
public DataSource resolve(final String resourceLocation) throws IOException
{
final DataSource result = resolve(resourceLocation, true);
if (isLenient() || result != null)
{
return result;
}
throw new IOException("The following resource was not found : " + resourceLocation);
}
/** {@inheritDoc} */
@Override
public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
{
for (int i = 0; i < getDataSourceResolvers().length; i++)
{
final DataSourceResolver dataSourceResolver = getDataSourceResolvers()[i];
final DataSource dataSource = dataSourceResolver.resolve(resourceLocation, isLenient);
if (dataSource != null)
{
return dataSource;
}
}
if (isLenient)
{
return null;
}
throw new IOException("The following resource was not found : " + resourceLocation);
}
}
commons-email-1.5-src/src/main/java/org/apache/commons/mail/resolver/DataSourceFileResolver.java 0100664 0001750 0001750 00000006241 13137110666 034221 0 ustar 00stefan stefan 0000000 0000000 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.mail.resolver;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import java.io.File;
import java.io.IOException;
/**
* Creates a DataSource
based on an URL. The implementation
* also resolves file resources.
*
* @since 1.3
*/
public class DataSourceFileResolver extends DataSourceBaseResolver
{
/** the base directory of the resource when resolving relative paths */
private final File baseDir;
/**
* Constructor.
*/
public DataSourceFileResolver()
{
baseDir = new File(".");
}
/**
* Constructor.
*
* @param baseDir the base directory of the resource when resolving relative paths
*/
public DataSourceFileResolver(final File baseDir)
{
this.baseDir = baseDir;
}
/**
* Constructor.
*
* @param baseDir the base directory of the resource when resolving relative paths
* @param lenient shall we ignore resources not found or complain with an exception
*/
public DataSourceFileResolver(final File baseDir, final boolean lenient)
{
super(lenient);
this.baseDir = baseDir;
}
/**
* Get the base directory used for resolving relative resource locations.
*
* @return the baseUrl
*/
public File getBaseDir()
{
return baseDir;
}
/** {@inheritDoc} */
@Override
public DataSource resolve(final String resourceLocation) throws IOException
{
return resolve(resourceLocation, isLenient());
}
/** {@inheritDoc} */
@Override
public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
{
File file;
DataSource result = null;
if (!isCid(resourceLocation))
{
file = new File(resourceLocation);
if (!file.isAbsolute())
{
file = getBaseDir() != null ? new File(getBaseDir(), resourceLocation) : new File(resourceLocation);
}
if (file.exists())
{
result = new FileDataSource(file);
}
else
{
if (!isLenient)
{
throw new IOException("Cant resolve the following file resource :" + file.getAbsolutePath());
}
}
}
return result;
}
}
././@LongLink 0100644 0000000 0000000 00000000146 13137110666 011640 L ustar 0000000 0000000 commons-email-1.5-src/src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java commons-email-1.5-src/src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.jav0100664 0001750 0001750 00000011002 13137110666 035052 0 ustar 00stefan stefan 0000000 0000000 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.mail.resolver;
import javax.activation.DataSource;
import javax.activation.FileTypeMap;
import javax.mail.util.ByteArrayDataSource;
import java.io.IOException;
import java.io.InputStream;
/**
* Creates a DataSource
based on an class path.
*
* @since 1.3
*/
public class DataSourceClassPathResolver extends DataSourceBaseResolver
{
/** the base string of the resource relative to the classpath when resolving relative paths */
private final String classPathBase;
/**
* Constructor
*/
public DataSourceClassPathResolver()
{
this.classPathBase = "/";
}
/**
* Constructor.
*
* @param classPathBase a base class path
*/
public DataSourceClassPathResolver(final String classPathBase)
{
this.classPathBase = classPathBase.endsWith("/") ? classPathBase : classPathBase + "/";
}
/**
* Constructor.
*
* @param classPathBase a base class path
* @param lenient shall we ignore resources not found or throw an exception?
*/
public DataSourceClassPathResolver(final String classPathBase, final boolean lenient)
{
super(lenient);
this.classPathBase = classPathBase.endsWith("/") ? classPathBase : classPathBase + "/";
}
/**
* @return the classPathBase
*/
public String getClassPathBase()
{
return classPathBase;
}
/** {@inheritDoc} */
@Override
public DataSource resolve(final String resourceLocation) throws IOException
{
return resolve(resourceLocation, isLenient());
}
/** {@inheritDoc} */
@Override
public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
{
DataSource result = null;
try
{
if (!isCid(resourceLocation) && !isHttpUrl(resourceLocation))
{
final String mimeType = FileTypeMap.getDefaultFileTypeMap().getContentType(resourceLocation);
final String resourceName = getResourceName(resourceLocation);
final InputStream is = DataSourceClassPathResolver.class.getResourceAsStream(resourceName);
if (is != null)
{
try
{
final ByteArrayDataSource ds = new ByteArrayDataSource(is, mimeType);
// EMAIL-125: set the name of the DataSource to the normalized resource URL
// similar to other DataSource implementations, e.g. FileDataSource, URLDataSource
ds.setName(DataSourceClassPathResolver.class.getResource(resourceName).toString());
result = ds;
}
finally
{
is.close();
}
}
else
{
if (isLenient)
{
return null;
}
throw new IOException("The following class path resource was not found : " + resourceLocation);
}
}
return result;
}
catch (final IOException e)
{
if (isLenient)
{
return null;
}
throw e;
}
}
/**
* Returns the resource name for a given resource location.
*
* @param resourceLocation the resource location
* @return {@link #getClassPathBase()} + {@code resourceLocation}
* @see #getClassPathBase()
*/
private String getResourceName(final String resourceLocation)
{
return (getClassPathBase() + resourceLocation).replaceAll("//", "/");
}
}
commons-email-1.5-src/src/main/java/org/apache/commons/mail/resolver/DataSourceBaseResolver.java 0100664 0001750 0001750 00000004663 13137110666 034222 0 ustar 00stefan stefan 0000000 0000000 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.mail.resolver;
import org.apache.commons.mail.DataSourceResolver;
/**
* Base class for various resolvers.
*
* @since 1.3
*/
public abstract class DataSourceBaseResolver implements DataSourceResolver
{
/** shall we ignore resources not found or complain with an exception */
private final boolean lenient;
/**
* Constructor.
*/
public DataSourceBaseResolver()
{
this.lenient = false;
}
/**
* Constructor.
*
* @param lenient shall we ignore resources not found or throw an exception?
*/
public DataSourceBaseResolver(final boolean lenient)
{
this.lenient = lenient;
}
/**
* Shall we ignore resources not found or throw an exception?
*
* @return the lenient flag
*/
public boolean isLenient()
{
return lenient;
}
/**
* Is this a content id?
*
* @param resourceLocation the resource location
* @return true if it is a CID
*/
protected boolean isCid(final String resourceLocation)
{
return resourceLocation.startsWith("cid:");
}
/**
* Is this a file URL?
*
* @param urlString the URL string
* @return true if it is a file URL
*/
protected boolean isFileUrl(final String urlString)
{
return urlString.startsWith("file:/");
}
/**
* Is this a HTTP/HTTPS URL?
*
* @param urlString the URL string
* @return true if it is a HTTP/HTTPS URL
*/
protected boolean isHttpUrl(final String urlString)
{
return urlString.startsWith("http://") || urlString.startsWith("https://");
}
}
commons-email-1.5-src/src/main/java/org/apache/commons/mail/resolver/package-info.java 0100664 0001750 0001750 00000002003 13137110666 032161 0 ustar 00stefan stefan 0000000 0000000 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Contains implementation classes to resolve data sources from the following locations:
*
* From version 1.3.1, it is possible to set a name for this DataSource, * and it is recommended to do so. * * @since 1.0 * @deprecated since 1.4, use {@link javax.mail.util.ByteArrayDataSource} instead */ @Deprecated public class ByteArrayDataSource implements DataSource { /** Define the buffer size. */ public static final int BUFFER_SIZE = 512; /** Stream containing the Data. */ private ByteArrayOutputStream baos; /** The Content-type. */ private final String type; // = "application/octet-stream"; /** * The name associated with this data source. * By default, the name is an empty string, similar to javax.mail.util.ByteArrayDataSource. * @since 1.3.1 */ private String name = ""; /** * Create a datasource from a byte array. * * @param data A byte[]. * @param aType A String. * @throws IOException IOException * @since 1.0 */ public ByteArrayDataSource(final byte[] data, final String aType) throws IOException { this.type = aType; ByteArrayInputStream bis = null; try { bis = new ByteArrayInputStream(data); this.byteArrayDataSource(bis); } finally { if (bis != null) { bis.close(); } } } /** * Create a datasource from an input stream. * * @param aIs An InputStream. * @param aType A String. * @throws IOException IOException * @since 1.0 */ public ByteArrayDataSource(final InputStream aIs, final String aType) throws IOException { this.type = aType; this.byteArrayDataSource(aIs); } /** * Create a datasource from a String. * N.B. assumes the data string can be converted using the charset iso-8859-1. * * @param data A String. * @param aType A String. * @throws IOException IOException * @since 1.0 */ public ByteArrayDataSource(final String data, final String aType) throws IOException { this.type = aType; try { baos = new ByteArrayOutputStream(); // Assumption that the string contains only ASCII characters! // Else just pass in a charset into this constructor and use it in getBytes(). baos.write(data.getBytes("iso-8859-1")); baos.flush(); baos.close(); } catch (final UnsupportedEncodingException uex) { throw new IOException("The Character Encoding is not supported."); } finally { if (baos != null) { baos.close(); } } } /** * Create a datasource from an input stream. * * @param aIs An InputStream. * @throws IOException IOException */ private void byteArrayDataSource(final InputStream aIs) throws IOException { BufferedInputStream bis = null; BufferedOutputStream osWriter = null; try { int length = 0; final byte[] buffer = new byte[ByteArrayDataSource.BUFFER_SIZE]; bis = new BufferedInputStream(aIs); baos = new ByteArrayOutputStream(); osWriter = new BufferedOutputStream(baos); // Write the InputData to OutputStream while ((length = bis.read(buffer)) != -1) { osWriter.write(buffer, 0, length); } osWriter.flush(); osWriter.close(); } finally { if (bis != null) { bis.close(); } if (baos != null) { baos.close(); } if (osWriter != null) { osWriter.close(); } } } /** * Get the content type. * * @return A String. * @since 1.0 */ @Override public String getContentType() { return type == null ? "application/octet-stream" : type; } /** * Get the input stream. * * @return An InputStream. * @throws IOException IOException * @since 1.0 */ @Override public InputStream getInputStream() throws IOException { if (baos == null) { throw new IOException("no data"); } return new ByteArrayInputStream(baos.toByteArray()); } /** * Sets the name for this DataSource. * * @param name The name. * @since 1.3.1 */ public void setName(final String name) { this.name = name; } /** * Get the name. * * @return A String. * @since 1.0 */ @Override public String getName() { return name; } /** * Get the OutputStream to write to. * * @return An OutputStream * @since 1.0 */ @Override public OutputStream getOutputStream() { baos = new ByteArrayOutputStream(); return baos; } } commons-email-1.5-src/src/main/java/org/apache/commons/mail/EmailAttachment.java 0100664 0001750 0001750 00000006712 13137110666 031047 0 ustar 00stefan stefan 0000000 0000000 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.mail; import java.net.URL; /** * This class models an email attachment. Used by MultiPartEmail. * * @since 1.0 */ public class EmailAttachment { /** Definition of the part being an attachment. */ public static final String ATTACHMENT = javax.mail.Part.ATTACHMENT; /** Definition of the part being inline. */ public static final String INLINE = javax.mail.Part.INLINE; /** The name of this attachment. */ private String name = ""; /** The description of this attachment. */ private String description = ""; /** The path to this attachment (ie c:/path/to/file.jpg). */ private String path = ""; /** The HttpURI where the file can be got. */ private URL url; /** The disposition. */ private String disposition = EmailAttachment.ATTACHMENT; /** * Get the description. * * @return A String. * @since 1.0 */ public String getDescription() { return description; } /** * Get the name. * * @return A String. * @since 1.0 */ public String getName() { return name; } /** * Get the path. * * @return A String. * @since 1.0 */ public String getPath() { return path; } /** * Get the URL. * * @return A URL. * @since 1.0 */ public URL getURL() { return url; } /** * Get the disposition. * * @return A String. * @since 1.0 */ public String getDisposition() { return disposition; } /** * Set the description. * * @param desc A String. * @since 1.0 */ public void setDescription(final String desc) { this.description = desc; } /** * Set the name. * * @param aName A String. * @since 1.0 */ public void setName(final String aName) { this.name = aName; } /** * Set the path to the attachment. The path can be absolute or relative * and should include the filename. *
* Example: /home/user/images/image.jpg
* Example: images/image.jpg
*
* @param aPath A String.
* @since 1.0
*/
public void setPath(final String aPath)
{
this.path = aPath;
}
/**
* Set the URL.
*
* @param aUrl A URL.
* @since 1.0
*/
public void setURL(final URL aUrl)
{
this.url = aUrl;
}
/**
* Set the disposition.
*
* @param aDisposition A String.
* @since 1.0
*/
public void setDisposition(final String aDisposition)
{
this.disposition = aDisposition;
}
}
commons-email-1.5-src/src/main/java/org/apache/commons/mail/EmailUtils.java 0100664 0001750 0001750 00000023367 13137110666 030064 0 ustar 00stefan stefan 0000000 0000000 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.mail;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.BitSet;
import java.util.Random;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.apache.commons.mail.util.MimeMessageUtils;
/**
* Utility methods used by commons-email.
*
*
* These methods are copied from other commons components (commons-lang) to avoid creating * a dependency for such a small component. *
* ** This is a package scoped class, and should not be used directly by users. *
* * @since 1.0 */ final class EmailUtils { /** * Random object used by random method. This has to be not local to the random method * so as to not return the same value in the same millisecond. */ private static final Random RANDOM = new Random(); /** * The default charset used for URL encoding. */ private static final String US_ASCII = "US-ASCII"; /** * Radix used in encoding. */ private static final int RADIX = 16; /** * The escape character used for the URL encoding scheme. */ private static final char ESCAPE_CHAR = '%'; /** * BitSet of RFC 2392 safe URL characters. */ private static final BitSet SAFE_URL = new BitSet(256); // Static initializer for safe_uri static { // alpha characters for (int i = 'a'; i <= 'z'; i++) { SAFE_URL.set(i); } for (int i = 'A'; i <= 'Z'; i++) { SAFE_URL.set(i); } // numeric characters for (int i = '0'; i <= '9'; i++) { SAFE_URL.set(i); } // safe chars SAFE_URL.set('-'); SAFE_URL.set('_'); SAFE_URL.set('.'); SAFE_URL.set('*'); SAFE_URL.set('+'); SAFE_URL.set('$'); SAFE_URL.set('!'); SAFE_URL.set('\''); SAFE_URL.set('('); SAFE_URL.set(')'); SAFE_URL.set(','); SAFE_URL.set('@'); } /** * Constructs a newEmailException
with no detail message.
*/
private EmailUtils()
{
super();
}
/**
* Checks if a String is empty ("") or null.
*
* @param str the String to check, may be null
*
* @return true
if the String is empty or null
*
* @since Commons Lang v2.1, svn 240418
*/
static boolean isEmpty(final String str)
{
return (str == null) || (str.length() == 0);
}
/**
* Checks if a String is not empty ("") and not null.
*
* @param str the String to check, may be null
*
* @return true
if the String is not empty and not null
*
* @since Commons Lang v2.1, svn 240418
*/
static boolean isNotEmpty(final String str)
{
return (str != null) && (str.length() > 0);
}
/**
* Validate an argument, throwing IllegalArgumentException
* if the argument is null
.
*
* @param object the object to check is not null
* @param message the exception message you would like to see if the object is null
*
* @throws IllegalArgumentException if the object is null
*
* @since Commons Lang v2.1, svn 201930
*/
static void notNull(final Object object, final String message)
{
if (object == null)
{
throw new IllegalArgumentException(message);
}
}
/**
* Creates a random string whose length is the number of characters specified.
*
* * Characters will be chosen from the set of alphabetic characters. *
* * @param count the length of random string to create * * @return the random string * * @since Commons Lang v2.1, svn 201930 */ static String randomAlphabetic(final int count) { return random(count, 0, 0, true, false, null, RANDOM); } /** * Creates a random string based on a variety of options, using supplied source of randomness. * *
* If start and end are both 0
, start and end are set to ' '
and 'z'
,
* the ASCII printable characters, will be used, unless letters and numbers are both false
,
* in which case, start and end are set to 0
and Integer.MAX_VALUE
.
*
* If set is not null
, characters between start and end are chosen.
*
* This method accepts a user-supplied {@link Random} instance to use as a source of randomness. By seeding a * single {@link Random} instance with a fixed seed and using it for each call, the same random sequence of strings * can be generated repeatedly and predictably. *
* * @param count the length of random string to create * @param start the position in set of chars to start at * @param end the position in set of chars to end before * @param letters only allow letters? * @param numbers only allow numbers? * @param chars the set of chars to choose randoms from. Ifnull
,
* then it will use the set of all chars.
* @param random a source of randomness.
*
* @return the random string
*
* @throws IllegalArgumentException if count
< 0.
*
* @since Commons Lang v2.1, svn 201930
*/
private static String random(
int count,
int start,
int end,
final boolean letters,
final boolean numbers,
final char [] chars,
final Random random)
{
if (count == 0)
{
return "";
}
else if (count < 0)
{
throw new IllegalArgumentException("Requested random string length " + count + " is less than 0.");
}
if ((start == 0) && (end == 0))
{
end = 'z' + 1;
start = ' ';
if (!letters && !numbers)
{
start = 0;
end = Integer.MAX_VALUE;
}
}
final StringBuffer buffer = new StringBuffer();
final int gap = end - start;
while (count-- != 0)
{
char ch;
if (chars == null)
{
ch = (char) (random.nextInt(gap) + start);
}
else
{
ch = chars[random.nextInt(gap) + start];
}
if ((letters && numbers && Character.isLetterOrDigit(ch)) || (letters && Character.isLetter(ch))
|| (numbers && Character.isDigit(ch)) || (!letters && !numbers))
{
buffer.append(ch);
}
else
{
count++;
}
}
return buffer.toString();
}
/**
* Replaces end-of-line characters with spaces.
*
* @param input the input string to be scanned.
* @return a clean string
*/
static String replaceEndOfLineCharactersWithSpaces(final String input)
{
return input == null ? null : input.replace('\n', ' ').replace('\r', ' ');
}
/**
* Encodes an input string according to RFC 2392. Unsafe characters are escaped.
*
* @param input the input string to be URL encoded
* @return a URL encoded string
* @throws UnsupportedEncodingException if "US-ASCII" charset is not available
* @see RFC 2392
*/
static String encodeUrl(final String input) throws UnsupportedEncodingException
{
if (input == null)
{
return null;
}
final StringBuilder builder = new StringBuilder();
for (final byte c : input.getBytes(US_ASCII))
{
int b = c;
if (b < 0)
{
b = 256 + b;
}
if (SAFE_URL.get(b))
{
builder.append((char) b);
}
else
{
builder.append(ESCAPE_CHAR);
final char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, RADIX));
final char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, RADIX));
builder.append(hex1);
builder.append(hex2);
}
}
return builder.toString();
}
/**
* Convenience method to write a MimeMessage into a file.
*
* @param resultFile the file containing the MimeMessgae
* @param mimeMessage the MimeMessage to write
* @throws IOException writing the MimeMessage failed
* @throws MessagingException writing the MimeMessage failed
*/
static void writeMimeMessage(final File resultFile, final MimeMessage mimeMessage)
throws IOException, MessagingException
{
MimeMessageUtils.writeMimeMessage(mimeMessage, resultFile);
}
}
commons-email-1.5-src/src/main/java/org/apache/commons/mail/util/MimeMessageParser.java 0100664 0001750 0001750 00000033541 13137110666 032335 0 ustar 00stefan stefan 0000000 0000000 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.mail.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.internet.ContentType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimePart;
import javax.mail.internet.MimeUtility;
import javax.mail.internet.ParseException;
import javax.mail.util.ByteArrayDataSource;
/**
* Parses a MimeMessage and stores the individual parts such a plain text,
* HTML text and attachments.
*
* @since 1.3
*/
public class MimeMessageParser
{
/** The MimeMessage to convert */
private final MimeMessage mimeMessage;
/** Plain mail content from MimeMessage */
private String plainContent;
/** Html mail content from MimeMessage */
private String htmlContent;
/** List of attachments of MimeMessage */
private final List
* The content-ids are stripped of any angle brackets, i.e. "part1" instead
* of "<part1>".
*
* @return the collection of content ids.
* @since 1.3.4
*/
public Collection
* The content-id must be stripped of any angle brackets,
* i.e. "part1" instead of "<part1>".
*
* @param cid the content-id of the attachment
* @return the corresponding datasource or null if nothing was found
* @since 1.3.4
*/
public DataSource findAttachmentByCid(final String cid)
{
final DataSource dataSource = cidMap.get(cid);
return dataSource;
}
/**
* Determines the name of the data source if it is not already set.
*
* @param part the mail part
* @param dataSource the data source
* @return the name of the data source or {@code null} if no name can be determined
* @throws MessagingException accessing the part failed
* @throws UnsupportedEncodingException decoding the text failed
*/
protected String getDataSourceName(final Part part, final DataSource dataSource)
throws MessagingException, UnsupportedEncodingException
{
String result = dataSource.getName();
if (result == null || result.length() == 0)
{
result = part.getFileName();
}
if (result != null && result.length() > 0)
{
result = MimeUtility.decodeText(result);
}
else
{
result = null;
}
return result;
}
/**
* Read the content of the input stream.
*
* @param is the input stream to process
* @return the content of the input stream
* @throws IOException reading the input stream failed
*/
private byte[] getContent(final InputStream is)
throws IOException
{
int ch;
byte[] result;
final ByteArrayOutputStream os = new ByteArrayOutputStream();
final BufferedInputStream isReader = new BufferedInputStream(is);
final BufferedOutputStream osWriter = new BufferedOutputStream(os);
while ((ch = isReader.read()) != -1)
{
osWriter.write(ch);
}
osWriter.flush();
result = os.toByteArray();
osWriter.close();
return result;
}
/**
* Parses the mimeType.
*
* @param fullMimeType the mime type from the mail api
* @return the real mime type
*/
private String getBaseMimeType(final String fullMimeType)
{
final int pos = fullMimeType.indexOf(';');
if (pos >= 0)
{
return fullMimeType.substring(0, pos);
}
return fullMimeType;
}
}
commons-email-1.5-src/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java 0100664 0001750 0001750 00000012123 13137110666 032172 0 ustar 00stefan stefan 0000000 0000000 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.mail.util;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Static helper methods.
*
* @since 1.3
*/
public final class MimeMessageUtils
{
/**
* Instances should NOT be constructed in standard programming.
*/
private MimeMessageUtils()
{
super();
}
/**
* Create a MimeMessage.
*
* @param session the mail session
* @param source the input data
* @return the MimeMessage
* @throws MessagingException creating the MimeMessage failed
* @throws IOException creating the MimeMessage failed
*/
public static MimeMessage createMimeMessage(final Session session, final byte[] source)
throws MessagingException, IOException
{
ByteArrayInputStream is = null;
try
{
is = new ByteArrayInputStream(source);
return new MimeMessage(session, is);
}
finally
{
if (is != null)
{
is.close();
}
}
}
/**
* Create a MimeMessage.
*
* @param session the mail session
* @param source the input data
* @return the MimeMessage
* @throws MessagingException creating the MimeMessage failed
* @throws IOException creating the MimeMessage failed
*/
public static MimeMessage createMimeMessage(final Session session, final File source)
throws MessagingException, IOException
{
FileInputStream is = null;
try
{
is = new FileInputStream(source);
return createMimeMessage(session, is);
}
finally
{
if (is != null)
{
is.close();
}
}
}
/**
* Create a MimeMessage.
*
* @param session the mail session
* @param source the input data
* @return the MimeMessage
* @throws MessagingException creating the MimeMessage failed
*/
public static MimeMessage createMimeMessage(final Session session, final InputStream source)
throws MessagingException
{
return new MimeMessage(session, source);
}
/**
* Create a MimeMessage using the platform's default character encoding.
*
* @param session the mail session
* @param source the input data
* @return the MimeMessage
* @throws MessagingException creating the MimeMessage failed
* @throws IOException creating the MimeMessage failed
*/
public static MimeMessage createMimeMessage(final Session session, final String source)
throws MessagingException, IOException
{
ByteArrayInputStream is = null;
try
{
final byte[] byteSource = source.getBytes();
is = new ByteArrayInputStream(byteSource);
return createMimeMessage(session, is);
}
finally
{
if (is != null)
{
is.close();
}
}
}
/**
* Convenience method to write a MimeMessage into a file.
*
* @param mimeMessage the MimeMessage to write
* @param resultFile the file containing the MimeMessgae
* @throws MessagingException accessing MimeMessage failed
* @throws IOException writing the MimeMessage failed
*/
public static void writeMimeMessage(final MimeMessage mimeMessage, final File resultFile)
throws MessagingException, IOException
{
FileOutputStream fos = null;
try
{
if (!resultFile.getParentFile().exists() && !resultFile.getParentFile().mkdirs())
{
throw new IOException(
"Failed to create the following parent directories: "
+ resultFile.getParentFile());
}
fos = new FileOutputStream(resultFile);
mimeMessage.writeTo(fos);
fos.flush();
fos.close();
fos = null;
}
finally
{
if (fos != null)
{
fos.close();
}
}
}
}
commons-email-1.5-src/src/main/java/org/apache/commons/mail/util/IDNEmailAddressConverter.java 0100664 0001750 0001750 00000007230 13137110666 033540 0 ustar 00stefan stefan 0000000 0000000 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.mail.util;
import javax.mail.internet.InternetAddress;
import java.net.IDN;
/**
* Converts email addresses containing International Domain Names into an ASCII
* representation suitable for sending an email.
*
* @see https://docs.oracle.com/javase/tutorial/i18n/network/idn.html
* @see https://en.wikipedia.org/wiki/Punycode
* @see https://tools.ietf.org/html/rfc5891
* @see https://en.wikipedia.org/wiki/Punycode
*
* @since 1.5
*/
public class IDNEmailAddressConverter
{
/**
* Convert an email address to its ASCII representation using "Punycode".
*
* @param email email address.
* @return The ASCII representation
*/
public String toASCII(final String email)
{
final int idx = findAtSymbolIndex(email);
if (idx < 0)
{
return email;
}
return getLocalPart(email, idx) + '@' + IDN.toASCII(getDomainPart(email, idx));
}
/**
* Convert the address part of an InternetAddress to its Unicode representation.
*
* @param address email address.
* @return The Unicode representation
*/
String toUnicode(final InternetAddress address)
{
return address != null ? toUnicode(address.getAddress()) : null;
}
/**
* Convert an "Punycode" email address to its Unicode representation.
*
* @param email email address.
* @return The Unicode representation
*/
String toUnicode(final String email)
{
final int idx = findAtSymbolIndex(email);
if (idx < 0)
{
return email;
}
return getLocalPart(email, idx) + '@' + IDN.toUnicode(getDomainPart(email, idx));
}
/**
* Extracts the local part of the email address.
*
* @param email email address.
* @param idx index of '@' character.
* @return local part of email
*/
private String getLocalPart(final String email, final int idx)
{
return email.substring(0, idx);
}
/**
* Extracts the domain part of the email address.
*
* @param email email address.
* @param idx index of '@' character.
* @return domain part of email
*/
private String getDomainPart(final String email, final int idx)
{
return email.substring(idx + 1);
}
/**
* Null-safe wrapper for {@link String#indexOf} to find the '@' character.
*
* @param value String value.
* @return index of first '@' character or {@code -1}
*/
private int findAtSymbolIndex(final String value)
{
if (value == null)
{
return -1;
}
return value.indexOf('@');
}
}
commons-email-1.5-src/src/main/java/org/apache/commons/mail/util/package-info.java 0100664 0001750 0001750 00000001577 13137110666 031314 0 ustar 00stefan stefan 0000000 0000000 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This package provides some utility classes.
*/
package org.apache.commons.mail.util;
commons-email-1.5-src/src/main/java/org/apache/commons/mail/ImageHtmlEmail.java 0100664 0001750 0001750 00000015746 13137110666 030635 0 ustar 00stefan stefan 0000000 0000000 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.mail;
import javax.activation.DataSource;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Small wrapper class on top of HtmlEmail which encapsulates the required logic
* to retrieve images that are contained in "<img src=../>" elements in the HTML
* code. This is done by replacing all img-src-elements with "cid:"-entries and
* embedding images in the email.
*
* For local files the class tries to either load them via an absolute path or -
* if available - use a relative path starting from a base directory. For files
* that are not found locally, the implementation tries to download
* the element and link it in.
*
* The image loading is done by an instance of We recommend you use a mirror to download our release
builds, but you must verify the integrity of
the downloaded files using signatures downloaded from our main
distribution directories. Recent releases (48 hours) may not yet be available from the mirrors. You are currently using http://mirror.deri.at/apache. If you
encounter a problem with this mirror, please select another
mirror. If all mirrors are failing, there are backup
mirrors (at the end of the mirrors list) that should be
available.
The For more information concerning Email, see the Email site. DataSourceResolver
* which has to be provided by the caller.
* entries in an HTML
// document.It needs to cater for various things, like more whitespaces
// including newlines on any place, HTML is not case sensitive and there
// can be arbitrary text between "IMG" and "SRC" like IDs and other things.
/** Regexp for extracting {@code
} tags */
public static final String REGEX_IMG_SRC =
"(<[Ii][Mm][Gg]\\s*[^>]*?\\s+[Ss][Rr][Cc]\\s*=\\s*[\"'])([^\"']+?)([\"'])";
/** regexp for extracting {@code
Email Downloads
KEYS
link links to the code signing keys used to sign the product. The PGP
link downloads the OpenPGP compatible signature from our main site.
The MD5
link downloads the checksum from the main site.