1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.mail.event;
  6. import java.util.*;
  7. import javax.mail.*;
  8. /**
  9. * This class models Transport events.
  10. *
  11. * @author John Mani
  12. * @author Max Spivak
  13. *
  14. * @see javax.mail.Transport
  15. * @see javax.mail.event.TransportListener
  16. */
  17. public class TransportEvent extends MailEvent {
  18. /**
  19. * Message has been successfully delivered to all recipients by the
  20. * transport firing this event. validSent[] contains all the addresses
  21. * this transport sent to successfully. validUnsent[] and invalid[]
  22. * should be null,
  23. */
  24. public static final int MESSAGE_DELIVERED = 1;
  25. /**
  26. * Message was not sent for some reason. validSent[] should be null.
  27. * validUnsent[] may have addresses that are valid (but the message
  28. * wasn't sent to them). invalid[] should likely contain invalid addresses.
  29. */
  30. public static final int MESSAGE_NOT_DELIVERED = 2;
  31. /**
  32. * Message was successfully sent to some recipients but not to all.
  33. * validSent[] holds addresses of recipients to whom the message was sent.
  34. * validUnsent[] holds valid addresses to which the message was not sent.
  35. * invalid[] holds invalid addresses, if any.
  36. */
  37. public static final int MESSAGE_PARTIALLY_DELIVERED = 3;
  38. /**
  39. * The event type.
  40. *
  41. * @serial
  42. */
  43. protected int type;
  44. transient protected Address[] validSent;
  45. transient protected Address[] validUnsent;
  46. transient protected Address[] invalid;
  47. transient protected Message msg;
  48. /**
  49. * Constructor.
  50. * @param source The Transport object
  51. */
  52. public TransportEvent(Transport transport, int type, Address[] validSent,
  53. Address[] validUnsent, Address[] invalid,
  54. Message msg) {
  55. super(transport);
  56. this.type = type;
  57. this.validSent = validSent;
  58. this.validUnsent = validUnsent;
  59. this.invalid = invalid;
  60. this.msg = msg;
  61. }
  62. /**
  63. * Return the type of this event.
  64. * @return type
  65. */
  66. public int getType() {
  67. return type;
  68. }
  69. /**
  70. * Return the addresses to which this message was sent succesfully.
  71. * @return Addresses to which the message was sent successfully or null
  72. */
  73. public Address[] getValidSentAddresses() {
  74. return validSent;
  75. }
  76. /**
  77. * Return the addresses that are valid but to which this message
  78. * was not sent.
  79. * @return Addresses that are valid but to which the message was
  80. * not sent successfully or null
  81. */
  82. public Address[] getValidUnsentAddresses() {
  83. return validUnsent;
  84. }
  85. /**
  86. * Return the addresses to which this message could not be sent.
  87. * @return Addresses to which the message sending failed or null
  88. */
  89. public Address[] getInvalidAddresses() {
  90. return invalid;
  91. }
  92. /**
  93. * Get the Message object associated with this Transport Event.
  94. *
  95. * @return the Message object
  96. * @since JavaMail 1.2
  97. */
  98. public Message getMessage() {
  99. return msg;
  100. }
  101. /**
  102. * Invokes the appropriate TransportListener method.
  103. */
  104. public void dispatch(Object listener) {
  105. if (type == MESSAGE_DELIVERED)
  106. ((TransportListener)listener).messageDelivered(this);
  107. else if (type == MESSAGE_NOT_DELIVERED)
  108. ((TransportListener)listener).messageNotDelivered(this);
  109. else // MESSAGE_PARTIALLY_DELIVERED
  110. ((TransportListener)listener).messagePartiallyDelivered(this);
  111. }
  112. }