1 25 26 package net.killingar.actions.email; 27 28 import javax.mail.Address ; 29 import javax.mail.Flags ; 30 import java.util.Date ; 31 32 public class Mail 33 { 34 String from, to, subject, body, flags, xmailer, mime; 35 boolean unread; 36 Date sendDate; 37 Object content; 38 39 javax.mail.Message m; 40 41 public Mail(javax.mail.Message inMail) throws Exception 42 { 43 m = inMail; 44 45 { 46 StringBuffer s = new StringBuffer (); 47 boolean first = true; 48 Address [] a; 49 50 if ((a = m.getFrom()) != null) 51 { 52 for (int j = 0; j < a.length; j++) 53 { 54 if (first) 55 first = false; 56 else 57 s.append(", "); 58 s.append(a[j].toString()); 59 } 60 } 61 62 from = s.toString(); 63 } 64 65 { 66 StringBuffer s = new StringBuffer (); 67 Address [] a; 68 69 boolean first = true; 70 if ((a = m.getRecipients(javax.mail.Message.RecipientType.TO)) != null) 71 { 72 for (int j = 0; j < a.length; j++) 73 { 74 if (first) 75 first = false; 76 else 77 s.append(", "); 78 s.append(a[j].toString()); 79 } 80 } 81 82 to = s.toString(); 83 } 84 85 subject = m.getSubject(); 86 sendDate = m.getSentDate(); 87 body = m.getContent().toString(); mime = m.getDataHandler().getContentType(); 89 content = m.getContent(); 90 91 117 118 { 119 StringBuffer s = new StringBuffer (); 120 Flags flags = m.getFlags(); 121 Flags.Flag [] sf = flags.getSystemFlags(); 123 boolean first = true; 124 for (int i = 0; i < sf.length; i++) 125 { 126 Flags.Flag f = sf[i]; 127 if (f == Flags.Flag.ANSWERED) 128 s.append("\\Answered"); 129 else if (f == Flags.Flag.DELETED) 130 s.append("\\Deleted"); 131 else if (f == Flags.Flag.DRAFT) 132 s.append("\\Draft"); 133 else if (f == Flags.Flag.FLAGGED) 134 s.append("\\Flagged"); 135 else if (f == Flags.Flag.RECENT) 136 s.append("\\Recent"); 137 else if (f == Flags.Flag.SEEN) 138 s.append("\\Seen"); 139 else 140 continue; if (first) 142 first = false; 143 else 144 s.append(", "); 145 } 146 147 String [] uf = flags.getUserFlags(); for (int i = 0; i < uf.length; i++) 149 { 150 if (first) 151 first = false; 152 else 153 s.append(", "); 154 s.append(uf[i]); 155 } 156 157 this.flags = s.toString(); 158 } 159 160 { 161 String [] hdrs = m.getHeader("X-Mailer"); 162 if (hdrs != null) 163 xmailer = hdrs[0]; 164 else 165 xmailer = "n/a"; 166 } 167 168 unread = isNew(m); 169 } 170 171 public static boolean isNew(javax.mail.Message m) throws Exception 172 { 173 Flags flags = m.getFlags(); 174 Flags.Flag [] sf = flags.getSystemFlags(); 176 for (int i = 0; i < sf.length; i++) 177 { 178 Flags.Flag f = sf[i]; 179 if (f == Flags.Flag.RECENT) 180 return true; 181 } 182 return false; 183 } 184 185 public String getFrom() { return from; } 186 public String getTo() { return to; } 187 public String getSubject() { return subject; } 188 public String getBody() { return body; } 189 public String getFlags() { return flags; } 190 public String getXmailer() { return xmailer; } 191 public String getMime() { return mime; } 192 193 public Object getContent() { return content; } 194 195 public boolean getUnread() { return unread; } 196 public Date getSendDate() { return sendDate; } 197 public int getMessageNumber() { return m.getMessageNumber(); } 198 public String getFolder() { return m.getFolder().getName(); } 199 200 public javax.mail.Message getMessage() { return m; } 201 } | Popular Tags |