本文整理汇总了Java中javax.mail.Flags.Flag类的典型用法代码示例。如果您正苦于以下问题:Java Flag类的具体用法?Java Flag怎么用?Java Flag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Flag类属于javax.mail.Flags包,在下文中一共展示了Flag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteMails
import javax.mail.Flags.Flag; //导入依赖的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: createMimeMessageInFolder
import javax.mail.Flags.Flag; //导入依赖的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;
}
示例3: onRestoreNode
import javax.mail.Flags.Flag; //导入依赖的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;
}
});
}
示例4: deleteMailsFromUserMailbox
import javax.mail.Flags.Flag; //导入依赖的package包/类
protected void deleteMailsFromUserMailbox(final Properties props, final String folderName, final int start, final int deleteCount,
final String user, final String password) throws MessagingException {
final Store store = Session.getInstance(props).getStore();
store.connect(user, password);
checkStoreForTestConnection(store);
final Folder f = store.getFolder(folderName);
f.open(Folder.READ_WRITE);
final int msgCount = f.getMessageCount();
final Message[] m = deleteCount == -1 ? f.getMessages() : f.getMessages(start, Math.min(msgCount, deleteCount + start - 1));
int d = 0;
for (final Message message : m) {
message.setFlag(Flag.DELETED, true);
logger.info("Delete msgnum: {} with sid {}", message.getMessageNumber(), message.getSubject());
d++;
}
f.close(true);
logger.info("Deleted " + d + " messages");
store.close();
}
示例5: changeMailStatus
import javax.mail.Flags.Flag; //导入依赖的package包/类
public void changeMailStatus(int mailId, Flag flag, MailCredentials credentials) throws MessagingException {
Properties properties = getServerProperties(credentials.getProtocol(), credentials.getHost(),
"" + credentials.getPort());
Session session = Session.getDefaultInstance(properties);
// connects to the message store
Store store = session.getStore(credentials.getProtocol());
store.connect(credentials.getUsername(), credentials.getPassword());
// opens the inbox folder
Folder folderInbox = store.getFolder("INBOX");
folderInbox.open(Folder.READ_WRITE);
logger.debug("unread:" + folderInbox.getUnreadMessageCount() + ", new:" + folderInbox.getNewMessageCount());
// fetches new messages from server
int msgnum[] = new int[] { mailId };
Message[] messages = folderInbox.getMessages(msgnum);
if (messages.length == 1 && messages[0] != null) {
messages[0].setFlag(flag, true);
}
folderInbox.close(false);
store.close();
}
示例6: expungeMessage
import javax.mail.Flags.Flag; //导入依赖的package包/类
public void expungeMessage(FileInfo fileInfo)
{
Flags flags = getFlags(fileInfo);
if (flags.contains(Flags.Flag.DELETED))
{
// See MNT-12259
//fileFolderService.delete(fileInfo.getNodeRef());
hideAndDelete(fileInfo.getNodeRef());
messageCache.remove(fileInfo.getNodeRef());
}
}
示例7: setFlags
import javax.mail.Flags.Flag; //导入依赖的package包/类
/**
* Set flags to the specified imapFolder.
*
* @param messageInfo FileInfo of imap Folder.
* @param flags flags to set.
* @param value value to set.
*/
public void setFlags(FileInfo messageInfo, Flags flags, boolean value)
{
checkForFlaggableAspect(messageInfo.getNodeRef());
for (Flags.Flag flag : flags.getSystemFlags())
{
setFlag(messageInfo, flag, value);
}
}
示例8: copyOrMoveNode
import javax.mail.Flags.Flag; //导入依赖的package包/类
/**
* Moves the node <code>sourceNodeRef</code> extracted from the message id.
* A part of a complex move operation.
*
* @param folderInfo FileInfo
* @param message MimeMessage
* @param flags Flags
* @param sourceNodeRef NodeRef
* @return UUID of the moved node
* @throws FileExistsException
* @throws FileNotFoundException
*/
@SuppressWarnings("deprecation")
private long copyOrMoveNode(FileInfo folderInfo, MimeMessage message, Flags flags, NodeRef sourceNodeRef, boolean move)
throws FileExistsException, FileNotFoundException
{
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
FileFilterMode.setClient(FileFilterMode.Client.imap);
FileInfo messageFile = null;
if (move)
{
fileFolderService.setHidden(sourceNodeRef, false);
messageFile = fileFolderService.move(sourceNodeRef, folderInfo.getNodeRef(), null);
}
else
{
NodeRef newNodeRef = serviceRegistry.getCopyService().copyAndRename(sourceNodeRef, folderInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, null, false);
fileFolderService.setHidden(newNodeRef, false);
messageFile = fileFolderService.getFileInfo(newNodeRef);
}
final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID);
imapService.persistMessageHeaders(messageFile.getNodeRef(), message);
Flags newFlags = new Flags(flags);
newFlags.add(Flag.RECENT);
imapService.setFlags(messageFile, newFlags, true);
imapService.setFlag(messageFile, Flag.DELETED, false);
return newMessageUid;
}
示例9: deleteAllMessagesInternal
import javax.mail.Flags.Flag; //导入依赖的package包/类
/**
* Marks all messages in the folder as deleted using {@link javax.mail.Flags.Flag#DELETED} flag.
*/
@Override
public void deleteAllMessagesInternal() throws FolderException
{
if (isReadOnly())
{
throw new FolderException("Can't delete all - Permission denied");
}
for (Map.Entry<Long, FileInfo> entry : searchMails().entrySet())
{
imapService.setFlag(entry.getValue(), Flags.Flag.DELETED, true);
// comment out to physically remove content.
// fileFolderService.delete(fileInfo.getNodeRef());
}
}
示例10: getNonDeletedMessagesInternal
import javax.mail.Flags.Flag; //导入依赖的package包/类
/**
* Returns the list of messages that have no {@link javax.mail.Flags.Flag#DELETED} flag set for current user.
*
* @return the list of non-deleted messages.
*/
@Override
protected List<SimpleStoredMessage> getNonDeletedMessagesInternal()
{
if (logger.isDebugEnabled())
{
logger.debug("[getNonDeletedMessagesInternal] " + this);
}
List<SimpleStoredMessage> result = new ArrayList<SimpleStoredMessage>();
Collection<SimpleStoredMessage> values = getMessagesInternal();
for (SimpleStoredMessage message : values)
{
if (!getFlags(message).contains(Flags.Flag.DELETED))
{
result.add(message);
}
}
if (logger.isDebugEnabled() && folderInfo != null)
{
logger.debug(folderInfo.getName() + " - Non deleted messages count:" + result.size());
}
return result;
}
示例11: getRecentCount
import javax.mail.Flags.Flag; //导入依赖的package包/类
/**
* Returns count of messages with {@link javax.mail.Flags.Flag#RECENT} flag.
* If {@code reset} parameter is {@code true} - removes {@link javax.mail.Flags.Flag#RECENT} flag from
* the message for current user.
*
* @param reset - if true the {@link javax.mail.Flags.Flag#RECENT} will be deleted for current user if exists.
* @return returns count of recent messages.
*/
@Override
public int getRecentCount(boolean reset)
{
int recent = getFolderStatus().recentCount;
if (reset && recent > 0)
{
CommandCallback<Void> command = new CommandCallback<Void>()
{
public Void command() throws Throwable
{
for (FileInfo fileInfo : folderStatus.search.values())
{
Flags flags = imapService.getFlags(fileInfo);
if (flags.contains(Flags.Flag.RECENT))
{
imapService.setFlag(fileInfo, Flags.Flag.RECENT, false);
}
}
return null;
}
};
try
{
command.run();
}
catch (AccessDeniedException ade)
{
if (logger.isDebugEnabled())
{
logger.debug("Access denied to reset RECENT FLAG");
}
}
}
return recent;
}
示例12: deleteMailById
import javax.mail.Flags.Flag; //导入依赖的package包/类
@Test
public void deleteMailById() throws MessagingException {
MimeMessage[] mails = greenMail.getReceivedMessages();
String messageId = mails[0].getMessageID();
MailConnectors.deleteMails()
.createRequest()
.folder("INBOX")
.messageIds(messageId)
.execute();
mails = greenMail.getReceivedMessages();
assertThat(mails).hasSize(2);
assertThat(mails[0].isSet(Flag.DELETED)).isTrue();
assertThat(mails[1].isSet(Flag.DELETED)).isFalse();
}
示例13: folderFromConfiguration
import javax.mail.Flags.Flag; //导入依赖的package包/类
@Test
public void folderFromConfiguration() throws MessagingException {
MailConnectors.deleteMails()
.createRequest()
.messageNumbers(1)
.execute();
MimeMessage[] mails = greenMail.getReceivedMessages();
assertThat(mails).hasSize(2);
assertThat(mails[0].isSet(Flag.DELETED)).isTrue();
assertThat(mails[1].isSet(Flag.DELETED)).isFalse();
}
示例14: verifyMail
import javax.mail.Flags.Flag; //导入依赖的package包/类
private boolean verifyMail(final String sender, final String subject) {
LOG.info("Waiting for notification to be sent...");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
boolean found = false;
try {
Session session = Session.getDefaultInstance(
System.getProperties());
Store store = session.getStore("pop3");
store.connect(pop3Host, mailAddress, mailPassword);
Folder inbox = store.getFolder("INBOX");
assertNotNull(inbox);
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.getMessages();
for (int i = 0; i < messages.length; i++) {
if (sender.equals(messages[i].getFrom()[0].toString())
&& subject.equals(messages[i].getSubject())) {
found = true;
messages[i].setFlag(Flag.DELETED, true);
}
}
inbox.close(true);
store.close();
} catch (Throwable t) {
LOG.error("Unexpected exception", t);
fail("Unexpected exception while fetching e-mail");
}
return found;
}
示例15: markMessageRead
import javax.mail.Flags.Flag; //导入依赖的package包/类
private void markMessageRead(List<EwsMessage> messagesRead) throws MessagingException, Exception,
ServiceResponseException {
if (messagesRead == null || messagesRead.isEmpty())
return;
for (EwsMessage aMessage : messagesRead) {
EmailMessage aRawMessage = aMessage.getEmailMessage();
if (aMessage.getFlags().contains(Flag.SEEN)) {
aRawMessage.setIsRead(Boolean.TRUE);
} else {
aRawMessage.setIsRead(Boolean.FALSE);
}
aRawMessage.update(CONFLICT_RESOLUTION_MODE);
}
}