1
14
15 package com.liferay.util.mail;
16
17 import com.liferay.portal.kernel.util.FileUtil;
18 import com.liferay.portal.kernel.util.StringBundler;
19 import com.liferay.portal.kernel.util.StringPool;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23
24 import javax.mail.Address;
25 import javax.mail.MessagingException;
26 import javax.mail.Part;
27 import javax.mail.internet.InternetAddress;
28
29
34 public class JavaMailUtil {
35
36 public static byte[] getBytes(Part part)
37 throws IOException, MessagingException {
38
39 InputStream is = part.getInputStream();
40
41 try {
42 return FileUtil.getBytes(is);
43 }
44 finally {
45 is.close();
46 }
47 }
48
49 public static String toUnicodeString(Address[] addresses) {
50 return toUnicodeString((InternetAddress[])addresses);
51 }
52
53 public static String toUnicodeString(InternetAddress[] addresses) {
54 if ((addresses == null) || (addresses.length == 0)) {
55 return StringPool.BLANK;
56 }
57
58 StringBundler sb = new StringBundler(addresses.length * 2 - 1);
59
60 for (int i = 0; i < addresses.length; i++) {
61 if (addresses[i] != null) {
62 sb.append(addresses[i].toUnicodeString());
63 }
64
65 if ((i + 1) != addresses.length) {
66 sb.append(", ");
67 }
68 }
69
70 return sb.toString();
71 }
72
73 }