001
014
015 package com.liferay.util.mail;
016
017 import com.liferay.portal.kernel.util.FileUtil;
018 import com.liferay.portal.kernel.util.StringBundler;
019 import com.liferay.portal.kernel.util.StringPool;
020
021 import java.io.IOException;
022 import java.io.InputStream;
023
024 import javax.mail.Address;
025 import javax.mail.MessagingException;
026 import javax.mail.Part;
027 import javax.mail.internet.InternetAddress;
028
029
032 public class JavaMailUtil {
033
034 public static byte[] getBytes(Part part)
035 throws IOException, MessagingException {
036
037 InputStream is = part.getInputStream();
038
039 return FileUtil.getBytes(is);
040 }
041
042 public static String toUnicodeString(Address[] addresses) {
043 return toUnicodeString((InternetAddress[])addresses);
044 }
045
046 public static String toUnicodeString(InternetAddress[] addresses) {
047 if ((addresses == null) || (addresses.length == 0)) {
048 return StringPool.BLANK;
049 }
050
051 StringBundler sb = new StringBundler(addresses.length * 2 - 1);
052
053 for (int i = 0; i < addresses.length; i++) {
054 if (addresses[i] != null) {
055 sb.append(addresses[i].toUnicodeString());
056 }
057
058 if ((i + 1) != addresses.length) {
059 sb.append(", ");
060 }
061 }
062
063 return sb.toString();
064 }
065
066 }