001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 package javax.mail.event; 021 022 import javax.mail.Address; 023 import javax.mail.Message; 024 import javax.mail.Transport; 025 026 /** 027 * @version $Rev: 467553 $ $Date: 2006-10-25 00:01:51 -0400 (Wed, 25 Oct 2006) $ 028 */ 029 public class TransportEvent extends MailEvent { 030 /** 031 * Indicates that the message has successfully been delivered to all 032 * recipients. 033 */ 034 public static final int MESSAGE_DELIVERED = 1; 035 036 /** 037 * Indicates that no messages could be delivered. 038 */ 039 public static final int MESSAGE_NOT_DELIVERED = 2; 040 041 /** 042 * Indicates that some of the messages were successfully delivered 043 * but that some failed. 044 */ 045 public static final int MESSAGE_PARTIALLY_DELIVERED = 3; 046 047 /** 048 * The event type. 049 */ 050 protected int type; 051 052 /** 053 * Addresses to which the message was successfully delivered. 054 */ 055 protected transient Address[] validSent; 056 057 /** 058 * Addresses which are valid but to which the message was not sent. 059 */ 060 protected transient Address[] validUnsent; 061 062 /** 063 * Addresses that are invalid. 064 */ 065 protected transient Address[] invalid; 066 067 /** 068 * The message associated with this event. 069 */ 070 protected transient Message msg; 071 072 /** 073 * Construct a new event, 074 * 075 * @param transport the transport attempting to deliver the message 076 * @param type the event type 077 * @param validSent addresses to which the message was successfully delivered 078 * @param validUnsent addresses which are valid but to which the message was not sent 079 * @param invalid invalid addresses 080 * @param message the associated message 081 */ 082 public TransportEvent(Transport transport, int type, Address[] validSent, Address[] validUnsent, Address[] invalid, Message message) { 083 super(transport); 084 this.type = type; 085 this.validSent = validSent; 086 this.validUnsent = validUnsent; 087 this.invalid = invalid; 088 this.msg = message; 089 } 090 091 public Address[] getValidSentAddresses() { 092 return validSent; 093 } 094 095 public Address[] getValidUnsentAddresses() { 096 return validUnsent; 097 } 098 099 public Address[] getInvalidAddresses() { 100 return invalid; 101 } 102 103 public Message getMessage() { 104 return msg; 105 } 106 107 public int getType() { 108 return type; 109 } 110 111 public void dispatch(Object listener) { 112 TransportListener l = (TransportListener) listener; 113 switch (type) { 114 case MESSAGE_DELIVERED: 115 l.messageDelivered(this); 116 break; 117 case MESSAGE_NOT_DELIVERED: 118 l.messageNotDelivered(this); 119 break; 120 case MESSAGE_PARTIALLY_DELIVERED: 121 l.messagePartiallyDelivered(this); 122 break; 123 default: 124 throw new IllegalArgumentException("Invalid type " + type); 125 } 126 } 127 }