Java Mail API中邮件事件

景子安
2023-12-01
Java Mail API中包括6种邮件事件,都位于javax.mail.event包中,它们都是MailEvent的子类:
public abstract class MailEvent extends EventObject

这6种具体的邮件事件,前4种涉及到文件夹,它们是:
ConnectionEvent
Folder(或Store或Transport)已经被打开,关闭或断开连接.

FolderEvent
Folder已经被创建,删除或重命名

MessageChangedEvent
消息的信封或标志被修改

MessageCountEvent
消息被添加到Folder或被删除

StoreEvent
来自Store的通知或警告

TransportEvent
来自Transport的通知,消息已经被发送,部分发送或发送失败

这6个事件相应的监听接口为:

public interface ConnectionListener extends EventListener
包含的抽象方法为:
public abstract void closed(javax.mail.event.ConnectionEvent arg1);
public abstract void opened(javax.mail.event.ConnectionEvent arg1);
public abstract void disconnected(javax.mail.event.ConnectionEvent arg1);


public interface FolderListener extends EventListener
包含的抽象方法为:
public abstract void folderCreated(javax.mail.event.FolderEvent arg1);
public abstract void folderDeleted(javax.mail.event.FolderEvent arg1);
public abstract void folderRenamed(javax.mail.event.FolderEvent arg1);


public interface MessageChangedListener extends EventListener
包含的抽象方法为:
public abstract void messageChanged(javax.mail.event.MessageChangedEvent arg1);

public interface MessageCountListener extends EventListener
包含的抽象方法为:

public abstract void messagesAdded(javax.mail.event.MessageCountEvent arg1);
public abstract void messagesRemoved(javax.mail.event.MessageCountEvent arg1);

public interface StoreListener extends EventListener
包含的抽象方法为:
public abstract void notification(javax.mail.event.StoreEvent arg1);

public interface TransportListener extends EventListener
包含的抽象方法为:
public abstract void messageDelivered(javax.mail.event.TransportEvent arg1);
public abstract void messageNotDelivered(javax.mail.event.TransportEvent arg1);
public abstract void messagePartiallyDelivered(javax.mail.event.TransportEvent arg1);

其中4个事件可以由Folder发出.因此Folder类有14个 addXXXListener()方法,removeXXXListener()和notifyXXXListener()方法.

public void addConnectionListener(ConnectionListener l);

public void removeConnectionListener(ConnectionListener l);

protected void notifyConnectionListeners(int type);

public void addFolderListener(FolderListener l);

public void removeFolderListener(FolderListener l);

protected void notifyFolderListeners(int type);

protected void notifyFolderRenamedListeners(Folder folder);

public void addMessageCountListener(MessageCountListener l);

public void removeMessageCountListener(MessageCountListener l);

protected void notifyMessageAddedListeners(Message[] messages);

protected void notifyMessageRemovedListeners(boolean removed,Message[] messages);

public void addMessageChangedListener(MessageChangedListener l);

public void removeMessageChangeListener(MessageChangedListener l);

protected void notifyMessageChangedListeners(int type,Message message);
 类似资料: