本文整理汇总了Java中com.sun.mail.imap.IMAPFolder.doCommand方法的典型用法代码示例。如果您正苦于以下问题:Java IMAPFolder.doCommand方法的具体用法?Java IMAPFolder.doCommand怎么用?Java IMAPFolder.doCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.mail.imap.IMAPFolder
的用法示例。
在下文中一共展示了IMAPFolder.doCommand方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
});
}
示例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;
}
});
}
示例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;
}
});
}
示例4: 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();
}
}
示例5: 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);
}
示例6: testFetchUidsAndSize
import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testFetchUidsAndSize() throws MessagingException {
store.connect("[email protected]", "pwd");
try {
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("UID FETCH 1:* RFC822.SIZE", null);
}
});
FetchResponse fetchResponse = (FetchResponse) ret[0];
assertFalse(fetchResponse.isBAD());
assertEquals(2, fetchResponse.getItemCount()); // UID and SIZE
RFC822SIZE size = fetchResponse.getItem(RFC822SIZE.class);
assertNotNull(size);
assertTrue(size.size > 0);
UID uid = fetchResponse.getItem(UID.class);
assertEquals(folder.getUID(folder.getMessage(1)), uid.uid);
} finally {
store.close();
}
}
示例7: testRenameFolder
import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testRenameFolder() throws MessagingException {
store.connect("[email protected]", "pwd");
try {
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("CREATE foo", null);
}
});
IMAPResponse response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("RENAME foo bar", null);
}
});
Response response2 = ret[0];
assertTrue(response2.isOK());
final Folder bar = store.getFolder("bar");
bar.open(Folder.READ_ONLY);
assertTrue(bar.exists());
} finally {
store.close();
}
}
示例8: getMessageUid
import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
/**
* Returns the UID of the first message in folder
*
* @param folder Folder containing the message
* @param msn message sequence number
* @return UID of the first message
* @throws MessagingException
*/
private static Long getMessageUid(IMAPFolder folder, final int msn) throws MessagingException
{
return (Long) folder.doCommand(new IMAPFolder.ProtocolCommand()
{
public Object doCommand(IMAPProtocol p) throws ProtocolException
{
String command = "FETCH " + msn + " (UID)";
Response[] r = p.command(command, null);
logResponse(r);
Response response = r[r.length - 1];
// Grab response
if (!response.isOK())
{
throw new ProtocolException("Unable to retrieve message UID");
}
for(int i = 0 ; i < r.length; i++)
{
if(r[i] instanceof FetchResponse)
{
FetchResponse fetchResponse = (FetchResponse) r[0];
UID uid = (UID) fetchResponse.getItem(UID.class);
logger.debug("SECNUM=" + uid.seqnum + ", UID="+uid.uid);
return uid.uid;
}
}
/**
* Uh-oh - this is where we would intermittently fall over with a class cast exception.
* The following code probes why we don't have a FetchResponse
*/
StringBuffer sb = new StringBuffer();
sb.append("command="+command);
sb.append('\n');
sb.append("resp length=" + r.length);
sb.append('\n');
for(int i = 0 ; i < r.length; i++)
{
logger.error(r[i]);
sb.append("class=" + r[i].getClass().getName());
IMAPResponse unexpected = (IMAPResponse)r[i];
sb.append("key=" + unexpected.getKey());
sb.append("number=" + unexpected.getNumber());
sb.append("rest=" + unexpected.getRest());
sb.append("r[" + i + "]=" + r[i] + '\n');
}
throw new ProtocolException("getMessageUid: "+ sb.toString());
}
});
}
示例9: testSearchSequenceSet
import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testSearchSequenceSet() throws MessagingException {
store.connect("[email protected]", "pwd");
try {
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("SEARCH 1", null);
}
});
IMAPResponse response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
assertEquals("1", response.getRest());
ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("SEARCH 2:2", null);
}
});
response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
assertTrue(ret[1].isOK());
assertEquals("2", response.getRest());
ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("SEARCH 2:4", null);
}
});
response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
assertEquals("2 3 4", response.getRest());
assertTrue(ret[1].isOK());
ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("SEARCH 1 2:4 8", null);
}
});
response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
assertEquals("1 2 3 4 8", response.getRest());
assertTrue(ret[1].isOK());
} finally {
store.close();
}
}
示例10: testUidSearchSequenceSet
import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testUidSearchSequenceSet() throws MessagingException {
store.connect("[email protected]", "pwd");
try {
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
final Message[] messages = folder.getMessages();
Map<Integer, Long> uids = new HashMap<>();
for (Message msg : messages) {
uids.put(msg.getMessageNumber(), folder.getUID(msg));
}
Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("UID SEARCH 1", null);
}
});
IMAPResponse response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
assertEquals(uids.get(1).toString(), response.getRest());
ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("UID SEARCH 2:2", null);
}
});
response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
assertTrue(ret[1].isOK());
assertEquals(uids.get(2).toString(), response.getRest());
ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("UID SEARCH 2:4", null);
}
});
response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
assertEquals(msnListToUidString(uids, 2, 3, 4), response.getRest());
assertTrue(ret[1].isOK());
ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("UID SEARCH 1 2:4 8", null);
}
});
response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
assertEquals(msnListToUidString(uids, 1, 2, 3, 4, 8), response.getRest());
assertTrue(ret[1].isOK());
} finally {
store.close();
}
}
示例11: testUidSearchText
import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testUidSearchText() throws MessagingException, IOException {
store.connect("[email protected]", "pwd");
try {
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
final Message[] messages = folder.getMessages();
Map<Integer, String> uids = new HashMap<>();
for (Message msg : messages) {
uids.put(msg.getMessageNumber(), Long.toString(folder.getUID(msg)));
}
// messages[2] contains content with search text, match must be case insensitive
final String searchText1 = "conTEnt2";
Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("UID SEARCH TEXT " + searchText1, null);
}
});
IMAPResponse response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
assertEquals(uids.get(messages[2].getMessageNumber()), response.getRest());
// messages[2] contains search text in CC, with different upper case
final String searchText2 = "[email protected]";
ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("UID SEARCH TEXT " + searchText2, null);
}
});
response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
// Match all
assertArrayEquals(uids.values().toArray(), response.getRest().split(" "));
} finally {
store.close();
}
}
示例12: testUidSearchTextWithCharset
import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testUidSearchTextWithCharset() throws MessagingException, IOException {
greenMail.setUser("[email protected]", "pwd");
store.connect("[email protected]", "pwd");
try {
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
final MimeMessage email = GreenMailUtil.createTextEmail("[email protected]", "[email protected]",
"some subject", "some content",
greenMail.getSmtp().getServerSetup());
String[][] s = {
{"US-ASCII", "ABC", "1"},
{"ISO-8859-15", "\u00c4\u00e4\u20AC", "2"},
{"UTF-8", "\u00c4\u00e4\u03A0", "3"}
};
for (String[] charsetAndQuery : s) {
final String charset = charsetAndQuery[0];
final String search = charsetAndQuery[1];
email.setSubject("subject " + search, charset);
GreenMailUtil.sendMimeMessage(email);
// messages[2] contains content with search text, match must be case insensitive
final byte[] searchBytes = search.getBytes(charset);
final Argument arg = new Argument();
arg.writeBytes(searchBytes);
Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
return protocol.command("UID SEARCH CHARSET " + charset + " TEXT", arg);
}
});
IMAPResponse response = (IMAPResponse) ret[0];
assertFalse(response.isBAD());
String number = response.getRest();
assertEquals(charsetAndQuery[2], number);
}
} finally {
store.close();
}
}