本文整理汇总了Java中javax.mail.Flags类的典型用法代码示例。如果您正苦于以下问题:Java Flags类的具体用法?Java Flags怎么用?Java Flags使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Flags类属于javax.mail包,在下文中一共展示了Flags类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteMails
import javax.mail.Flags; //导入依赖的package包/类
/**
* Connect to the mail server and delete all mails.
*/
public void deleteMails() throws MessagingException {
Folder folder = getStore().getFolder(MAIL_INBOX);
folder.open(Folder.READ_WRITE);
// Get folder's list of messages.
Message[] messages = folder.getMessages();
// Retrieve message headers for each message in folder.
FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
folder.fetch(messages, profile);
for (Message message : messages) {
message.setFlag(Flags.Flag.DELETED, true);
}
folder.close(true);
}
示例2: changeStatus
import javax.mail.Flags; //导入依赖的package包/类
public void changeStatus( String folderName, long mailIDs[], Flags.Flag newFlag, boolean value ){
try{
Folder folderToUse = mailStore.getFolder(folderName);
folderToUse.open( Folder.READ_WRITE );
Flags f = new Flags();
f.add( newFlag );
Message mlist[];
if ( folderToUse instanceof UIDFolder )
mlist = ((UIDFolder)folderToUse).getMessagesByUID( mailIDs );
else
mlist = folderToUse.getMessages( returnToInts(mailIDs) );
for ( int x=0; x < mlist.length; x++ )
mlist[x].setFlags( f, value );
folderToUse.close( true );
setData( "succeeded", cfBooleanData.TRUE );
} catch (Exception E ){
setData( "errortext", new cfStringData( E.getMessage() ) );
setData( "succeeded", cfBooleanData.FALSE );
}
}
示例3: createMimeMessageInFolder
import javax.mail.Flags; //导入依赖的package包/类
/**
* Creates the EML message in the specified folder.
*
* @param folderFileInfo The folder to create message in.
* @param message The original MimeMessage.
* @return ID of the new message created
* @throws FileNotFoundException
* @throws FileExistsException
* @throws MessagingException
* @throws IOException
*/
private long createMimeMessageInFolder(
FileInfo folderFileInfo,
MimeMessage message,
Flags flags)
throws FileExistsException, FileNotFoundException, IOException, MessagingException
{
String name = AlfrescoImapConst.MESSAGE_PREFIX + GUID.generate();
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
FileInfo messageFile = fileFolderService.create(folderFileInfo.getNodeRef(), name, ContentModel.TYPE_CONTENT);
final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID);
name = AlfrescoImapConst.MESSAGE_PREFIX + newMessageUid + AlfrescoImapConst.EML_EXTENSION;
fileFolderService.rename(messageFile.getNodeRef(), name);
Flags newFlags = new Flags(flags);
newFlags.add(Flag.RECENT);
imapService.setFlags(messageFile, newFlags, true);
if (extractAttachmentsEnabled)
{
imapService.extractAttachments(messageFile.getNodeRef(), message);
}
// Force persistence of the message to the repository
new IncomingImapMessage(messageFile, serviceRegistry, message);
return newMessageUid;
}
示例4: getFlags
import javax.mail.Flags; //导入依赖的package包/类
/**
* Return flags that belong to the specified imap folder.
*
* @param messageInfo imap folder info.
* @return flags.
*/
public Flags getFlags(FileInfo messageInfo)
{
Flags flags = new Flags();
Map<QName, Serializable> props = nodeService.getProperties(messageInfo.getNodeRef());
for (QName key : qNameToFlag.keySet())
{
Boolean value = (Boolean) props.get(key);
if (value != null && value)
{
flags.add(qNameToFlag.get(key));
}
}
return flags;
}
示例5: replaceFlagsInternal
import javax.mail.Flags; //导入依赖的package包/类
/**
* Replaces flags for the message with the given UID. If {@code addUid} is set to {@code true}
* {@link FolderListener} objects defined for this folder will be notified.
* {@code silentListener} can be provided - this listener wouldn't be notified.
*
* @param flags - new flags.
* @param uid - message UID.
* @param silentListener - listener that shouldn't be notified.
* @param addUid - defines whether or not listeners be notified.
* @throws FolderException
* @throws MessagingException
*/
@Override
protected void replaceFlagsInternal(
Flags flags,
long uid,
FolderListener silentListener,
boolean addUid)
throws FolderException, MessagingException
{
int msn = getMsn(uid);
FileInfo fileInfo = searchMails().get(uid);
imapService.setFlags(fileInfo, MessageFlags.ALL_FLAGS, false);
imapService.setFlags(fileInfo, flags, true);
Long uidNotification = addUid ? uid : null;
notifyFlagUpdate(msn, flags, uidNotification, silentListener);
}
示例6: execute
import javax.mail.Flags; //导入依赖的package包/类
public void execute(Pop3Connection conn, Pop3State state, String cmd) {
conn.println("+OK");
try {
MailFolder inbox = state.getFolder();
List msgList = inbox.getMessages();
int count = 0;
for(int i=0;i<msgList.size();i++) {
SimpleStoredMessage msg = (SimpleStoredMessage) msgList.get(i);
Flags flags = msg.getFlags();
if (flags.contains(Flags.Flag.DELETED)) {
count++;
flags.remove(Flags.Flag.DELETED);
}
}
conn.println("+OK maildrop has "+count+" messages undeleted.");
} catch (Exception e) {
conn.println("-ERR " + e);
}
}
示例7: appendMessage
import javax.mail.Flags; //导入依赖的package包/类
public long appendMessage(MimeMessage message,
Flags flags,
Date internalDate) {
long uid = nextUid;
nextUid++;
// flags.setRecent(true);
SimpleStoredMessage storedMessage = new SimpleStoredMessage(message, flags,
internalDate, uid);
storedMessage.getFlags().add(Flags.Flag.RECENT);
mailMessages.add(storedMessage);
int newMsn = mailMessages.size();
// Notify all the listeners of the new message
synchronized (_mailboxListeners) {
for (int j = 0; j < _mailboxListeners.size(); j++) {
FolderListener listener = (FolderListener) _mailboxListeners.get(j);
listener.added(newMsn);
}
}
return uid;
}
示例8: deleteAllEmails
import javax.mail.Flags; //导入依赖的package包/类
/**
* Delete all emails in the inbox.
*
* @param protocol protocol used to connect to the server
* @throws MessagingException if we're unable to connect to the store
*/
public static void deleteAllEmails(String protocol, GreenMailUser user) throws MessagingException {
Folder inbox = null;
Store store = getConnection(user, protocol);
try {
inbox = store.getFolder(EMAIL_INBOX);
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.getMessages();
for (Message message : messages) {
message.setFlag(Flags.Flag.DELETED, true);
log.info("Deleted email Subject : " + message.getSubject());
}
} finally {
if (inbox != null) {
inbox.close(true);
}
if (store != null) {
store.close();
}
}
}
示例9: testSendingAndReceiving
import javax.mail.Flags; //导入依赖的package包/类
@Test
public void testSendingAndReceiving() throws MessagingException {
Session session = EmailUtils.getGMailSession(EmailUtils.user, EmailUtils.pass);
String key = (new Long(System.currentTimeMillis())).toString();
EmailUtils.postMail(session, EmailUtils.user, "test" + key, "testmsg" + key);
Folder inbox = EmailUtils.openPop3InboxReadWrite(session);
Folder trash = EmailUtils.openPop3TrashReadWrite(session);
boolean emailReceived = false;
for (Message m : inbox.getMessages()) {
if (m.getSubject().startsWith("test" + key)) {
emailReceived = true;
Message[] m_array = inbox.getMessages(m.getMessageNumber(), m.getMessageNumber());
// delete test mail
inbox.copyMessages(m_array, trash);
m.setFlag(Flags.Flag.DELETED, true);
}
}
EmailUtils.closeFolder(inbox);
EmailUtils.closeFolder(trash);
assertTrue(emailReceived);
}
示例10: prepareMailbox
import javax.mail.Flags; //导入依赖的package包/类
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("imap");
store.connect("localhost", 25, "claus", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts two new messages
Message[] msg = new Message[2];
msg[0] = new MimeMessage(sender.getSession());
msg[0].setText("Message 1");
msg[0].setHeader("Message-ID", "0");
msg[0].setFlag(Flags.Flag.SEEN, false);
msg[1] = new MimeMessage(sender.getSession());
msg[1].setText("Message 2");
msg[0].setHeader("Message-ID", "1");
msg[1].setFlag(Flags.Flag.SEEN, true);
folder.appendMessages(msg);
folder.close(true);
}
示例11: prepareMailbox
import javax.mail.Flags; //导入依赖的package包/类
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("imap");
store.connect("localhost", 25, "claus", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts two messages with the SEEN flag
Message[] msg = new Message[2];
msg[0] = new MimeMessage(sender.getSession());
msg[0].setText("Message 1");
msg[0].setHeader("Message-ID", "0");
msg[0].setFlag(Flags.Flag.SEEN, true);
msg[1] = new MimeMessage(sender.getSession());
msg[1].setText("Message 2");
msg[0].setHeader("Message-ID", "1");
msg[1].setFlag(Flags.Flag.SEEN, true);
folder.appendMessages(msg);
folder.close(true);
}
示例12: clear
import javax.mail.Flags; //导入依赖的package包/类
private static void clear(Folder folder) throws MessagingException {
if(folder.exists() && (folder.getType() & Folder.HOLDS_MESSAGES) == Folder.HOLDS_MESSAGES) {
int totMessages = folder.getMessageCount();
System.out.println(totMessages + " messages from folder: " + folder.getFullName());
folder.open(Folder.READ_WRITE);
Message[] messages = folder.getMessages();
for (int i = 0; i < messages.length; i++) {
System.out.println("Deleting message: " + (i+1) + " of " + totMessages);
messages[i].setFlag(Flags.Flag.DELETED, true);
}
folder.close(true);
}
Folder[] childs = folder.list();
for (int i = 0; i < childs.length; i++) {
clear(childs[i]);
}
}
示例13: checkInbox
import javax.mail.Flags; //导入依赖的package包/类
public void checkInbox(int mode) throws MessagingException, IOException {
if (mode == 0) {
return;
}
boolean show = (mode & MailClient.SHOW_MESSAGES) > 0;
boolean clear = (mode & MailClient.CLEAR_MESSAGES) > 0;
String action = (show ? "Show" : "") + (show && clear ? " and " : "") + (clear ? "Clear" : "");
System.out.println(action + " INBOX for " + from);
Store store = session.getStore();
store.connect();
Folder root = store.getDefaultFolder();
Folder inbox = root.getFolder("inbox");
inbox.open(Folder.READ_WRITE);
Message[] msgs = inbox.getMessages();
if (msgs.length == 0 && show) {
System.out.println("No messages in inbox");
}
for (Message msg2 : msgs) {
MimeMessage msg = (MimeMessage) msg2;
if (show) {
System.out.println(" From: " + msg.getFrom()[0]);
System.out.println(" Subject: " + msg.getSubject());
System.out.println(" Content: " + msg.getContent());
}
if (clear) {
msg.setFlag(Flags.Flag.DELETED, true);
}
}
inbox.close(true);
store.close();
System.out.println();
}
示例14: deleteMails
import javax.mail.Flags; //导入依赖的package包/类
/**
* delete all message in ibox that match given criteria
* @param messageNumbers
* @param uIds
* @throws MessagingException
* @throws IOException
*/
public void deleteMails(String as[], String as1[]) throws MessagingException, IOException {
Folder folder;
Message amessage[];
folder = _fldelse.getFolder("INBOX");
folder.open(2);
Map<String, Message> map = getMessages(null,folder, as1, as, startrow, maxrows,false);
Iterator<String> iterator = map.keySet().iterator();
amessage = new Message[map.size()];
int i = 0;
while(iterator.hasNext()) {
amessage[i++] = map.get(iterator.next());
}
try {
folder.setFlags(amessage, new Flags(javax.mail.Flags.Flag.DELETED), true);
}
finally {
folder.close(true);
}
}
示例15: onRestoreNode
import javax.mail.Flags; //导入依赖的package包/类
@Override
public void onRestoreNode(final ChildAssociationRef childAssocRef)
{
doAsSystem(new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
NodeRef childNodeRef = childAssocRef.getChildRef();
if (serviceRegistry.getDictionaryService().isSubClass(nodeService.getType(childNodeRef), ContentModel.TYPE_CONTENT))
{
setFlag(childNodeRef, Flags.Flag.DELETED, false);
setFlag(childNodeRef, Flags.Flag.SEEN, false);
}
NodeRef folderRef = childAssocRef.getParentRef();
long newId = (Long) nodeService.getProperty(childNodeRef, ContentModel.PROP_NODE_DBID);
if (nodeService.hasAspect(folderRef, ImapModel.ASPECT_IMAP_FOLDER))
{
// Force generation of a new change token and updating the UIDVALIDITY
getUidValidityTransactionListener(folderRef).recordNewUid(newId);
}
return null;
}
});
}