1 17 18 package org.apache.james.transport.mailets; 19 20 import java.io.PrintWriter ; 21 import java.io.StringWriter ; 22 23 import java.util.Collection ; 24 import java.util.Date ; 25 import java.util.Enumeration ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.Locale ; 29 import java.util.ArrayList ; 30 31 32 import javax.mail.Message ; 33 import javax.mail.MessagingException ; 34 import javax.mail.Session ; 35 import javax.mail.internet.InternetAddress ; 36 import javax.mail.internet.MimeBodyPart ; 37 import javax.mail.internet.MimeMessage ; 38 import javax.mail.internet.MimeMultipart ; 39 40 import org.apache.james.core.MailImpl; 41 42 import org.apache.mailet.GenericMailet; 43 import org.apache.mailet.Mail; 44 import org.apache.mailet.MailAddress; 45 46 47 282 283 public class Redirect extends AbstractRedirect { 284 285 290 public String getMailetInfo() { 291 return "Redirect Mailet"; 292 } 293 294 295 protected String [] getAllowedInitParameters() { 296 String [] allowedArray = { 297 "static", 298 "debug", 299 "passThrough", 300 "fakeDomainCheck", 301 "inline", 302 "attachment", 303 "message", 304 "recipients", 305 "to", 306 "replyTo", 307 "replyto", 308 "reversePath", 309 "sender", 310 "subject", 311 "prefix", 312 "attachError", 313 "isReply" 314 }; 315 return allowedArray; 316 } 317 318 319 320 321 322 325 protected boolean isStatic() { 326 return isStatic; 327 } 328 329 332 protected int getInLineType() throws MessagingException { 333 if(getInitParameter("inline") == null) { 334 return BODY; 335 } else { 336 return getTypeCode(getInitParameter("inline")); 337 } 338 } 339 340 349 protected Collection getRecipients() throws MessagingException { 350 Collection newRecipients = new HashSet (); 351 String addressList = (getInitParameter("recipients") == null) 352 ? getInitParameter("to") 353 : getInitParameter("recipients"); 354 355 if (addressList == null) { 357 return null; 358 } 359 360 try { 361 InternetAddress [] iaarray = InternetAddress.parse(addressList, false); 362 for (int i = 0; i < iaarray.length; i++) { 363 String addressString = iaarray[i].getAddress(); 364 MailAddress specialAddress = getSpecialAddress(addressString, 365 new String [] {"postmaster", "sender", "from", "replyTo", "reversePath", "unaltered", "recipients", "to", "null"}); 366 if (specialAddress != null) { 367 newRecipients.add(specialAddress); 368 } else { 369 newRecipients.add(new MailAddress(iaarray[i])); 370 } 371 } 372 } catch (Exception e) { 373 throw new MessagingException ("Exception thrown in getRecipients() parsing: " + addressList, e); 374 } 375 if (newRecipients.size() == 0) { 376 throw new MessagingException ("Failed to initialize \"recipients\" list; empty <recipients> init parameter found."); 377 } 378 379 return newRecipients; 380 } 381 382 391 protected InternetAddress [] getTo() throws MessagingException { 392 InternetAddress [] iaarray = null; 393 String addressList = (getInitParameter("to") == null) 394 ? getInitParameter("recipients") 395 : getInitParameter("to"); 396 397 if (addressList == null) { 399 return null; 400 } 401 402 try { 403 iaarray = InternetAddress.parse(addressList, false); 404 for(int i = 0; i < iaarray.length; ++i) { 405 String addressString = iaarray[i].getAddress(); 406 MailAddress specialAddress = getSpecialAddress(addressString, 407 new String [] {"postmaster", "sender", "from", "replyTo", "reversePath", "unaltered", "recipients", "to", "null"}); 408 if (specialAddress != null) { 409 iaarray[i] = specialAddress.toInternetAddress(); 410 } 411 } 412 } catch (Exception e) { 413 throw new MessagingException ("Exception thrown in getTo() parsing: " + addressList, e); 414 } 415 if (iaarray.length == 0) { 416 throw new MessagingException ("Failed to initialize \"to\" list; empty <to> init parameter found."); 417 } 418 419 return iaarray; 420 } 421 422 429 protected MailAddress getReversePath() throws MessagingException { 430 String addressString = getInitParameter("reversePath"); 431 if(addressString != null) { 432 MailAddress specialAddress = getSpecialAddress(addressString, 433 new String [] {"postmaster", "sender", "null"}); 434 if (specialAddress != null) { 435 return specialAddress; 436 } 437 438 try { 439 return new MailAddress(addressString); 440 } catch(Exception e) { 441 throw new MessagingException ("Exception thrown in getReversePath() parsing: " + addressString, e); 442 } 443 } 444 445 return null; 446 } 447 448 453 protected MailAddress getReversePath(Mail originalMail) throws MessagingException { 454 MailAddress reversePath = super.getReversePath(originalMail); 455 if (reversePath == null) { 456 reversePath = getSender(originalMail); 457 } 458 return reversePath; 459 } 460 461 462 463 464 465 } 466 | Popular Tags |