当前位置: 首页>>代码示例>>Java>>正文


Java IMAPFolder类代码示例

本文整理汇总了Java中com.sun.mail.imap.IMAPFolder的典型用法代码示例。如果您正苦于以下问题:Java IMAPFolder类的具体用法?Java IMAPFolder怎么用?Java IMAPFolder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IMAPFolder类属于com.sun.mail.imap包,在下文中一共展示了IMAPFolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRFC822Message

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
private static RFC822DATA getRFC822Message(final IMAPFolder folder, final long uid) throws MessagingException
{
    return (RFC822DATA) folder.doCommand(new IMAPFolder.ProtocolCommand()
    {
        public Object doCommand(IMAPProtocol p) throws ProtocolException
        {
            Response[] r = p.command("UID FETCH " + uid + " (RFC822)", null);
            logResponse(r);
            Response response = r[r.length - 1];
            if (!response.isOK())
            {
                throw new ProtocolException("Unable to retrieve message in RFC822 format");
            }

            FetchResponse fetchResponse = (FetchResponse) r[0];
            return fetchResponse.getItem(RFC822DATA.class);
        }
    });
   
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:21,代码来源:ImapMessageTest.java

示例2: getMessageBodyPart

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
/**
 * Returns BODY object containing desired message fragment
 * 
 * @param folder Folder containing the message
 * @param uid Message UID
 * @param from starting byte
 * @param count bytes to read
 * @return BODY containing desired message fragment
 * @throws MessagingException
 */
private static BODY getMessageBodyPart(IMAPFolder folder, final Long uid, final Integer from, final Integer count) throws MessagingException
{
    return (BODY) folder.doCommand(new IMAPFolder.ProtocolCommand()
    {
        public Object doCommand(IMAPProtocol p) throws ProtocolException
        {
            Response[] r = p.command("UID FETCH " + uid + " (FLAGS BODY.PEEK[]<" + from + "." + count + ">)", null);
            logResponse(r);
            Response response = r[r.length - 1];

            // Grab response
            if (!response.isOK())
            {
                throw new ProtocolException("Unable to retrieve message part <" + from + "." + count + ">");
            }

            FetchResponse fetchResponse = (FetchResponse) r[0];
            BODY body = (BODY) fetchResponse.getItem(com.sun.mail.imap.protocol.BODY.class);
            return body;
        }
    });

}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:34,代码来源:ImapMessageTest.java

示例3: getMessageBody

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
/**
 * Returns a full message body
 * 
 * @param folder Folder containing the message
 * @param uid Message UID
 * @return Returns size of the message
 * @throws MessagingException
 */
private static BODY getMessageBody(IMAPFolder folder, final Long uid) throws MessagingException
{
    return (BODY) folder.doCommand(new IMAPFolder.ProtocolCommand()
    {
        public Object doCommand(IMAPProtocol p) throws ProtocolException
        {
            Response[] r = p.command("UID FETCH " + uid + " (FLAGS BODY.PEEK[])", null);
            logResponse(r);
            Response response = r[r.length - 1];

            // Grab response
            if (!response.isOK())
            {
                throw new ProtocolException("Unable to retrieve message size");
            }
            FetchResponse fetchResponse = (FetchResponse) r[0];
            BODY body = (BODY) fetchResponse.getItem(BODY.class);
            return body;
        }
    });
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:ImapMessageTest.java

示例4: prepareFetching

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected void prepareFetching(String mailbox) throws MailboxConnectionException {
    try {
        this.folder = (IMAPFolder) getMessageStore().getFolder(mailbox);
        if (this.folder != null && this.folder.exists()) {
            if (this.folder.isOpen() && this.folder.getMode() != Folder.READ_WRITE) {
                this.folder.close(false);
                this.folder.open(Folder.READ_WRITE);
            } else if (!folder.isOpen()) {
                this.folder.open(Folder.READ_WRITE);
            }
        } else {
            String errMsg = "Folder " + mailbox + " not found";
            LOGGER.error(errMsg);
            throw new MailboxConnectionException(errMsg, false);
        }
    } catch (MessagingException e) {
        LOGGER.error("Opening IMAP folder failed.", e);
        throw new MailboxConnectionException("Opening IMAP folder failed.", e);
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:25,代码来源:ImapMailboxConnection.java

示例5: markMessagesAsRead

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
public void markMessagesAsRead(String[] ids, boolean seen) throws NoSuchProviderException, MessagingException, IOException {
  IMAPFolder folder = (IMAPFolder)getStore().getFolder("Inbox");
  folder.open(Folder.READ_WRITE);
  UIDFolder uidFolder = folder;
  
  Message[] msgs;
  

  long[] uids = new long[ids.length];
  int i = 0;
  for (String s : ids) {
    try {
      uids[i++] = Long.parseLong(s);
    } catch (Exception ex) {
      Log.d("rgai", "", ex);
    }
  }
  // TODO: if instance not support UID, then use simple id
  msgs = uidFolder.getMessagesByUID(uids);

  folder.setFlags(msgs, new Flags(Flags.Flag.SEEN), seen);

  folder.close(false);
}
 
开发者ID:k-kojak,项目名称:yako,代码行数:25,代码来源:SimpleEmailMessageProvider.java

示例6: testSearchNotFlags

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
@Test
public void testSearchNotFlags() throws MessagingException {
    store.connect("[email protected]", "pwd");
    try {
        IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
        folder.open(Folder.READ_WRITE);
        folder.setFlags(new int[]{2,3}, new Flags(Flags.Flag.ANSWERED), true);
        Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
            @Override
            public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
                return protocol.command("SEARCH NOT (ANSWERED) NOT (DELETED) NOT (SEEN) NOT (FLAGGED) ALL", null);
            }
        });
        IMAPResponse response = (IMAPResponse) ret[0];
        assertFalse(response.isBAD());
        assertEquals("1 4 5 6 7 8 9 10" /* 2 and 3 set to answered */, response.getRest());
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:21,代码来源:ImapProtocolTest.java

示例7: testGetMessageByUnknownUidInEmptyINBOX

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
@Test
public void testGetMessageByUnknownUidInEmptyINBOX() throws MessagingException, FolderException {
    greenMail.getManagers()
            .getImapHostManager()
            .getInbox(user)
            .deleteAllMessages();
    store.connect("[email protected]", "pwd");
    try {
        IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        Message message = folder.getMessageByUID(666);
        assertEquals(null, message);
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:17,代码来源:ImapProtocolTest.java

示例8: addHeaders

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
/**
     * Adds required headers to fetch profile
     *
     * @param fetchProfile
     * @return
     */
    public static final FetchProfile addHeaders(FetchProfile fetchProfile) {
        fetchProfile.add(FetchProfile.Item.ENVELOPE);
        //Some servers respond to get a header request with a partial response of the header
        //when hMailServer is fetched for To or From, it returns only the first entry,
        //so when compared with other server versions, e-mails appear to be different.
        fetchProfile.add(IMAPFolder.FetchProfileItem.HEADERS);
        //If using the header consructor add this for performance.
//        for (String header : new String[]{
//            MessageId.HEADER_MESSAGE_ID,
//            MessageId.HEADER_SUBJECT,
//            MessageId.HEADER_FROM,
//            MessageId.HEADER_TO}) {
//            fetchProfile.add(header.toUpperCase());
//        }
        return fetchProfile;
    }
 
开发者ID:manusa,项目名称:mnIMAPSync,代码行数:23,代码来源:MessageId.java

示例9: stop

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
@Override
public void stop() {
  runnning = false;

  // perform a NOOP to interrupt IDLE
  try {
    folder.doCommand(new IMAPFolder.ProtocolCommand() {
      public Object doCommand(IMAPProtocol p) throws ProtocolException {
            p.simpleCommand("NOOP", null);
            return null;
        }
    });
  } catch (MessagingException e) {
    // ignore
  }
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:17,代码来源:IdleNotificationWorker.java

示例10: start

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
public void start(String folderName) throws Exception {
	executorService = Executors.newSingleThreadExecutor();

	Folder folder = mailService.ensureOpenFolder(folderName);

	folder.addMessageCountListener(new MessageCountAdapter() {
		@Override
		public void messagesAdded(MessageCountEvent event) {
			List<Message> messages = Arrays.asList(event.getMessages());

			handlers.forEach(handler -> handler.accept(messages));
		}
	});

	if (supportsIdle(folder)) {
		notificationWorker = new IdleNotificationWorker(mailService, (IMAPFolder) folder);
	} else {
		notificationWorker = new PollNotificationWorker(mailService, folder,
				configuration.getNotificationLookupTime());
	}

	LOGGER.debug("start notification service: {}", notificationWorker);

	executorService.submit(notificationWorker);
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:26,代码来源:MailNotificationService.java

示例11: supportsIdle

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
protected boolean supportsIdle(Folder folder) throws MessagingException {
	Store store = folder.getStore();

	if (store instanceof IMAPStore) {
		IMAPStore imapStore = (IMAPStore) store;
		return imapStore.hasCapability("IDLE") && folder instanceof IMAPFolder;
	} else {
		return false;
	}
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:11,代码来源:MailNotificationService.java

示例12: openPop3InboxReadWrite

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
/**
 * opens inbox folder in read write modus returns inbox folder
 */
public static Folder openPop3InboxReadWrite(final Session session) throws MessagingException {
	final Store store = session.getStore("imaps");
	store.connect("imap.googlemail.com", EmailUtils.user, EmailUtils.pass);

	final IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
	if (!folder.isOpen()) {
		folder.open(Folder.READ_WRITE);
	}
	return folder;
}
 
开发者ID:bptlab,项目名称:Unicorn,代码行数:14,代码来源:EmailUtils.java

示例13: openPop3TrashReadWrite

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
/**
 * return trash folder in read write modus
 */
public static Folder openPop3TrashReadWrite(final Session session) throws MessagingException {
	final Store store = session.getStore("imaps");
	store.connect("imap.googlemail.com", EmailUtils.user, EmailUtils.pass);

	final IMAPFolder folder = (IMAPFolder) store.getFolder("[Gmail]/Papierkorb");
	if (!folder.isOpen()) {
		folder.open(Folder.READ_WRITE);
	}
	return folder;
}
 
开发者ID:bptlab,项目名称:Unicorn,代码行数:14,代码来源:EmailUtils.java

示例14: getTrashFolderLocalisedName

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
private String getTrashFolderLocalisedName(final IMAPFolder inbox) throws MessagingException {
	String trashFolderName = null;
	ListInfo[] li = null;
	li = (ListInfo[]) inbox.doCommand(new ProtocolCommand() {
	    public Object doCommand(IMAPProtocol p) throws ProtocolException {
		return p.list("", "*");
	    }
	});
	for (ListInfo info: li)
		if (info.attrs.length == 2 && TRASH_FOLDER_NAME.equals(info.attrs[1])) {
			trashFolderName = info.name;
			break;
		}
	return (trashFolderName == null ? TRASH_FOLDER_ENGLISH_NAME : trashFolderName);
}
 
开发者ID:danielebufarini,项目名称:Reminders,代码行数:16,代码来源:DeleteEmailViaImap.java

示例15: deleteEmail

import com.sun.mail.imap.IMAPFolder; //导入依赖的package包/类
private void deleteEmail(final IMAPStore store, long uid) throws Exception {
	IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
	inbox.open(Folder.READ_WRITE);
	javax.mail.Message message = inbox.getMessageByUID(uid);
	if (message != null) {
		Folder trash = store.getFolder(getTrashFolderLocalisedName(inbox));
		trash.open(Folder.READ_WRITE);
		inbox.copyMessages(new javax.mail.Message[] { message }, trash);
		trash.close(true);
	}
	inbox.close(true);
}
 
开发者ID:danielebufarini,项目名称:Reminders,代码行数:13,代码来源:DeleteEmailViaImap.java


注:本文中的com.sun.mail.imap.IMAPFolder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。