本文整理汇总了Java中com.sun.mail.iap.ProtocolException类的典型用法代码示例。如果您正苦于以下问题:Java ProtocolException类的具体用法?Java ProtocolException怎么用?Java ProtocolException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProtocolException类属于com.sun.mail.iap包,在下文中一共展示了ProtocolException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getRFC822Message
import com.sun.mail.iap.ProtocolException; //导入依赖的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.iap.ProtocolException; //导入依赖的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.iap.ProtocolException; //导入依赖的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: testSearchNotFlags
import com.sun.mail.iap.ProtocolException; //导入依赖的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
示例5: stop
import com.sun.mail.iap.ProtocolException; //导入依赖的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
示例6: getTrashFolderLocalisedName
import com.sun.mail.iap.ProtocolException; //导入依赖的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
示例7: doCommand
import com.sun.mail.iap.ProtocolException; //导入依赖的package包/类
@Override
public Object doCommand(IMAPProtocol imapp) throws ProtocolException {
//shared folders containing /, which are forbidden for "normal" folders
if(this.folderName.startsWith("Other Users") || this.folderName.startsWith("Shared Folders")){
Argument command = new Argument();
setFolderName(command);
command.writeNString("/vendor/kolab/folder-type");
command.writeString("*");
Response[] response = imapp.command("GETANNOTATION", command);
for (int i = 0; i < response.length; i++) {
String rest = response[i].getRest();
if (rest.contains("note")) {
isNotesFolder = true;
break;
}
}
}
return null;
}
开发者ID:konradrenner,项目名称:kolabnotes-java,代码行数:24,代码来源:GetSharedFolderCommand.java
示例8: doCommand
import com.sun.mail.iap.ProtocolException; //导入依赖的package包/类
@Override
public Object doCommand(IMAPProtocol imapp) throws ProtocolException {
Argument command = new Argument();
command.writeString(folderName);
command.writeNString("/vendor/kolab/folder-type");
command.writeString("*");
Response[] response = imapp.command("GETANNOTATION", command);
for (int i = 0; i < response.length; i++) {
String rest = response[i].getRest();
if (rest.contains("configuration")) {
isConfigurationFolder = true;
break;
}
}
return null;
}
开发者ID:konradrenner,项目名称:kolabnotes-java,代码行数:22,代码来源:GetConfigurationCommand.java
示例9: doCommand
import com.sun.mail.iap.ProtocolException; //导入依赖的package包/类
@Override
public Object doCommand(IMAPProtocol imapp) throws ProtocolException {
Argument command = new Argument();
setFolderName(command);
command.writeNString("/vendor/kolab/folder-type");
command.writeString("*");
Response[] response = imapp.command("GETANNOTATION", command);
for (int i = 0; i < response.length; i++) {
String rest = response[i].getRest();
if (rest.contains("note")) {
isNotesFolder = true;
break;
}
}
return null;
}
开发者ID:konradrenner,项目名称:kolabnotes-java,代码行数:22,代码来源:GetMetadataCommand.java
示例10: testFetchUidsAndSize
import com.sun.mail.iap.ProtocolException; //导入依赖的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();
}
}
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:28,代码来源:ImapProtocolTest.java
示例11: testRenameFolder
import com.sun.mail.iap.ProtocolException; //导入依赖的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();
}
}
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:34,代码来源:ImapProtocolTest.java
示例12: getMessageUid
import com.sun.mail.iap.ProtocolException; //导入依赖的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());
}
});
}
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:61,代码来源:ImapMessageTest.java
示例13: testSearchSequenceSet
import com.sun.mail.iap.ProtocolException; //导入依赖的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();
}
}
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:53,代码来源:ImapProtocolTest.java
示例14: testUidSearchSequenceSet
import com.sun.mail.iap.ProtocolException; //导入依赖的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();
}
}
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:60,代码来源:ImapProtocolTest.java
示例15: testUidSearchText
import com.sun.mail.iap.ProtocolException; //导入依赖的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();
}
}
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:42,代码来源:ImapProtocolTest.java
示例16: testUidSearchTextWithCharset
import com.sun.mail.iap.ProtocolException; //导入依赖的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();
}
}
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:45,代码来源:ImapProtocolTest.java
示例17: authenticate
import com.sun.mail.iap.ProtocolException; //导入依赖的package包/类
public boolean authenticate(String[] mechs, String realm, String authzid,
String u, String p) throws ProtocolException;
开发者ID:konradrenner,项目名称:kore-javamail,代码行数:3,代码来源:SaslAuthenticator.java
示例18: getProtocol
import com.sun.mail.iap.ProtocolException; //导入依赖的package包/类
protected IMAPProtocol getProtocol()
throws ProtocolException, FolderClosedException {
return msg.getProtocol();
}
开发者ID:konradrenner,项目名称:kore-javamail,代码行数:5,代码来源:IMAPNestedMessage.java
示例19: doCommand
import com.sun.mail.iap.ProtocolException; //导入依赖的package包/类
@Override
public Object doCommand(IMAPProtocol imapp) throws ProtocolException {
Argument command = new Argument();
Argument listArguments = new Argument();
command.writeString(folderName);
command.writeNString("/vendor/kolab/folder-type");
listArguments.writeNString("value.shared");
listArguments.writeNString("note");
command.writeArgument(listArguments);
Response[] response = imapp.command("SETANNOTATION", command);
if (response.length == 1 && response[0].isOK()) {
return null;
}
throw new ProtocolException("Unable to set folder-type." + Arrays.toString(response));
}
开发者ID:konradrenner,项目名称:kolabnotes-java,代码行数:23,代码来源:SetMetadataCommand.java
示例20: doCommand
import com.sun.mail.iap.ProtocolException; //导入依赖的package包/类
@Override
public Object doCommand(IMAPProtocol imapp) throws ProtocolException {
//shared folders containing /, which are forbidden for "normal" folders
Argument command = new Argument();
setFolderName(command);
Response[] response = imapp.command("MYRIGHTS", command);
for (int i = 0; i < response.length; i++) {
String rest = response[i].getRest();
//there is a whitespace if the result is in this string (in the one loop run there will be e.g. the string "Completed" if everything is ok)
String[] splitted = rest.split(" ");
if (splitted.length > 1) {
//Details look https://tools.ietf.org/html/rfc4314#page-10
//The rights are always the last part
String imapPermissions = splitted[splitted.length - 1];
boolean creationPossible = true;
for (String creationRight : CREATION_RIGHTS) {
if (!imapPermissions.contains(creationRight)) {
creationPossible = false;
}
}
if (creationPossible) {
this.isNoteCreationAllowed = true;
boolean modificationPossible = true;
for (String modificationRight : MODIFICATION_RIGHTS) {
if (!imapPermissions.contains(modificationRight)) {
modificationPossible = false;
}
}
this.isNoteModificationAllowed = modificationPossible;
}
break;
}
}
return null;
}
开发者ID:konradrenner,项目名称:kolabnotes-java,代码行数:44,代码来源:GetFolderPermissionsCommand.java
注:本文中的com.sun.mail.iap.ProtocolException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论