Added workaround for Migadu

master
M66B 2 months ago
parent 538523dded
commit cb821dc04f

@ -56,7 +56,7 @@ import com.sun.mail.imap.Utility;
*/ */
public class IMAPProtocol extends Protocol { public class IMAPProtocol extends Protocol {
private boolean connected = false; // did constructor succeed? private boolean connected = false; // did constructor succeed?
private boolean rev1 = false; // REV1 server ? private boolean rev1 = false; // REV1 server ?
private boolean referralException; // throw exception for IMAP REFERRAL? private boolean referralException; // throw exception for IMAP REFERRAL?
@ -102,7 +102,7 @@ public class IMAPProtocol extends Protocol {
* @exception IOException for I/O errors * @exception IOException for I/O errors
* @exception ProtocolException for protocol failures * @exception ProtocolException for protocol failures
*/ */
public IMAPProtocol(String name, String host, int port, public IMAPProtocol(String name, String host, int port,
Properties props, boolean isSSL, MailLogger logger) Properties props, boolean isSSL, MailLogger logger)
throws IOException, ProtocolException { throws IOException, ProtocolException {
super(host, port, props, "mail." + name, isSSL, logger); super(host, port, props, "mail." + name, isSSL, logger);
@ -481,7 +481,7 @@ public class IMAPProtocol extends Protocol {
/** /**
* LOGIN Command. * LOGIN Command.
* *
* @param u the username * @param u the username
* @param p the password * @param p the password
* @throws ProtocolException as thrown by {@link Protocol#handleResult}. * @throws ProtocolException as thrown by {@link Protocol#handleResult}.
@ -557,7 +557,7 @@ public class IMAPProtocol extends Protocol {
* Note that the encoded bytes should be sent "as-is" to the * Note that the encoded bytes should be sent "as-is" to the
* server, *not* as literals or quoted-strings. * server, *not* as literals or quoted-strings.
* *
* Also note that unlike the B64 definition in MIME, CRLFs * Also note that unlike the B64 definition in MIME, CRLFs
* should *not* be inserted during the encoding process. So, I * should *not* be inserted during the encoding process. So, I
* use Integer.MAX_VALUE (0x7fffffff (> 1G)) as the bytesPerLine, * use Integer.MAX_VALUE (0x7fffffff (> 1G)) as the bytesPerLine,
* which should be sufficiently large ! * which should be sufficiently large !
@ -582,7 +582,7 @@ public class IMAPProtocol extends Protocol {
first = false; first = false;
} else // Send encoded password } else // Send encoded password
s = p; s = p;
// obtain b64 encoded bytes // obtain b64 encoded bytes
b64os.write(s.getBytes(StandardCharsets.UTF_8)); b64os.write(s.getBytes(StandardCharsets.UTF_8));
b64os.flush(); // complete the encoding b64os.flush(); // complete the encoding
@ -617,7 +617,7 @@ public class IMAPProtocol extends Protocol {
/* /*
* Dispatch untagged responses. * Dispatch untagged responses.
* NOTE: in our current upper level IMAP classes, we add the * NOTE: in our current upper level IMAP classes, we add the
* responseHandler to the Protocol object only *after* the * responseHandler to the Protocol object only *after* the
* connection has been authenticated. So, for now, the below * connection has been authenticated. So, for now, the below
* code really ends up being just a no-op. * code really ends up being just a no-op.
*/ */
@ -806,7 +806,7 @@ public class IMAPProtocol extends Protocol {
} else { } else {
s = ntlm.generateType3Msg(r.getRest()); s = ntlm.generateType3Msg(r.getRest());
} }
os.write(s.getBytes(StandardCharsets.UTF_8)); os.write(s.getBytes(StandardCharsets.UTF_8));
os.write(CRLF); // CRLF termination os.write(CRLF); // CRLF termination
os.flush(); // flush the stream os.flush(); // flush the stream
@ -1051,7 +1051,7 @@ public class IMAPProtocol extends Protocol {
/** /**
* PROXYAUTH Command. * PROXYAUTH Command.
* *
* @param u the PROXYAUTH user name * @param u the PROXYAUTH user name
* @exception ProtocolException for protocol failures * @exception ProtocolException for protocol failures
* @see "Netscape/iPlanet/SunONE Messaging Server extension" * @see "Netscape/iPlanet/SunONE Messaging Server extension"
@ -1077,7 +1077,7 @@ public class IMAPProtocol extends Protocol {
/** /**
* UNAUTHENTICATE Command. * UNAUTHENTICATE Command.
* *
* @exception ProtocolException for protocol failures * @exception ProtocolException for protocol failures
* @see "Netscape/iPlanet/SunONE Messaging Server extension" * @see "Netscape/iPlanet/SunONE Messaging Server extension"
* @since JavaMail 1.5.1 * @since JavaMail 1.5.1
@ -1108,7 +1108,7 @@ public class IMAPProtocol extends Protocol {
/** /**
* STARTTLS Command. * STARTTLS Command.
* *
* @exception ProtocolException for protocol failures * @exception ProtocolException for protocol failures
* @see "RFC3501, section 6.2.1" * @see "RFC3501, section 6.2.1"
*/ */
@ -1134,7 +1134,7 @@ public class IMAPProtocol extends Protocol {
/** /**
* COMPRESS Command. Only supports DEFLATE. * COMPRESS Command. Only supports DEFLATE.
* *
* @exception ProtocolException for protocol failures * @exception ProtocolException for protocol failures
* @see "RFC 4978" * @see "RFC 4978"
*/ */
@ -1200,7 +1200,7 @@ public class IMAPProtocol extends Protocol {
*/ */
public MailboxInfo select(String mbox, ResyncData rd) public MailboxInfo select(String mbox, ResyncData rd)
throws ProtocolException { throws ProtocolException {
Argument args = new Argument(); Argument args = new Argument();
writeMailboxName(args, mbox); writeMailboxName(args, mbox);
if (rd != null) { if (rd != null) {
@ -1209,7 +1209,7 @@ public class IMAPProtocol extends Protocol {
throw new BadCommandException("CONDSTORE not supported"); throw new BadCommandException("CONDSTORE not supported");
args.writeArgument(new Argument().writeAtom("CONDSTORE")); args.writeArgument(new Argument().writeAtom("CONDSTORE"));
} else { } else {
if (!hasCapability("QRESYNC")) if (!hasCapability("QRESYNC"))
throw new BadCommandException("QRESYNC not supported"); throw new BadCommandException("QRESYNC not supported");
args.writeArgument(resyncArgs(rd)); args.writeArgument(resyncArgs(rd));
} }
@ -1217,22 +1217,22 @@ public class IMAPProtocol extends Protocol {
Response[] r = command("SELECT", args); Response[] r = command("SELECT", args);
// Note that MailboxInfo also removes those responses // Note that MailboxInfo also removes those responses
// it knows about // it knows about
MailboxInfo minfo = new MailboxInfo(r); MailboxInfo minfo = new MailboxInfo(r);
// dispatch any remaining untagged responses // dispatch any remaining untagged responses
notifyResponseHandlers(r); notifyResponseHandlers(r);
Response response = r[r.length-1]; Response response = r[r.length-1];
if (response.isOK()) { // command succesful if (response.isOK()) { // command succesful
if (response.toString().indexOf("READ-ONLY") != -1) if (response.toString().indexOf("READ-ONLY") != -1)
minfo.mode = Folder.READ_ONLY; minfo.mode = Folder.READ_ONLY;
else else
minfo.mode = Folder.READ_WRITE; minfo.mode = Folder.READ_WRITE;
} }
handleResult(response); handleResult(response);
return minfo; return minfo;
} }
@ -1262,7 +1262,7 @@ public class IMAPProtocol extends Protocol {
*/ */
public MailboxInfo examine(String mbox, ResyncData rd) public MailboxInfo examine(String mbox, ResyncData rd)
throws ProtocolException { throws ProtocolException {
Argument args = new Argument(); Argument args = new Argument();
writeMailboxName(args, mbox); writeMailboxName(args, mbox);
if (rd != null) { if (rd != null) {
@ -1271,7 +1271,7 @@ public class IMAPProtocol extends Protocol {
throw new BadCommandException("CONDSTORE not supported"); throw new BadCommandException("CONDSTORE not supported");
args.writeArgument(new Argument().writeAtom("CONDSTORE")); args.writeArgument(new Argument().writeAtom("CONDSTORE"));
} else { } else {
if (!hasCapability("QRESYNC")) if (!hasCapability("QRESYNC"))
throw new BadCommandException("QRESYNC not supported"); throw new BadCommandException("QRESYNC not supported");
args.writeArgument(resyncArgs(rd)); args.writeArgument(resyncArgs(rd));
} }
@ -1316,7 +1316,7 @@ public class IMAPProtocol extends Protocol {
* @since JavaMail 1.5.1 * @since JavaMail 1.5.1
*/ */
public void enable(String cap) throws ProtocolException { public void enable(String cap) throws ProtocolException {
if (!hasCapability("ENABLE")) if (!hasCapability("ENABLE"))
throw new BadCommandException("ENABLE not supported"); throw new BadCommandException("ENABLE not supported");
Argument args = new Argument(); Argument args = new Argument();
args.writeAtom(cap); args.writeAtom(cap);
@ -1352,7 +1352,7 @@ public class IMAPProtocol extends Protocol {
* @since JavaMail 1.4.4 * @since JavaMail 1.4.4
*/ */
public void unselect() throws ProtocolException { public void unselect() throws ProtocolException {
if (!hasCapability("UNSELECT")) if (!hasCapability("UNSELECT"))
throw new BadCommandException("UNSELECT not supported"); throw new BadCommandException("UNSELECT not supported");
simpleCommand("UNSELECT", null); simpleCommand("UNSELECT", null);
} }
@ -1366,14 +1366,14 @@ public class IMAPProtocol extends Protocol {
* @exception ProtocolException for protocol failures * @exception ProtocolException for protocol failures
* @see "RFC2060, section 6.3.10" * @see "RFC2060, section 6.3.10"
*/ */
public Status status(String mbox, String[] items) public Status status(String mbox, String[] items)
throws ProtocolException { throws ProtocolException {
if (!isREV1() && !hasCapability("IMAP4SUNVERSION")) if (!isREV1() && !hasCapability("IMAP4SUNVERSION"))
// STATUS is rev1 only, however the non-rev1 SIMS2.0 // STATUS is rev1 only, however the non-rev1 SIMS2.0
// does support this. // does support this.
throw new BadCommandException("STATUS not supported"); throw new BadCommandException("STATUS not supported");
Argument args = new Argument(); Argument args = new Argument();
writeMailboxName(args, mbox); writeMailboxName(args, mbox);
Argument itemArgs = new Argument(); Argument itemArgs = new Argument();
@ -1390,7 +1390,7 @@ public class IMAPProtocol extends Protocol {
Response response = r[r.length-1]; Response response = r[r.length-1];
// Grab all STATUS responses // Grab all STATUS responses
if (response.isOK()) { // command succesful if (response.isOK()) { // command succesful
for (int i = 0, len = r.length; i < len; i++) { for (int i = 0, len = r.length; i < len; i++) {
if (!(r[i] instanceof IMAPResponse)) if (!(r[i] instanceof IMAPResponse))
continue; continue;
@ -1420,7 +1420,7 @@ public class IMAPProtocol extends Protocol {
* @see "RFC2060, section 6.3.3" * @see "RFC2060, section 6.3.3"
*/ */
public void create(String mbox) throws ProtocolException { public void create(String mbox) throws ProtocolException {
Argument args = new Argument(); Argument args = new Argument();
writeMailboxName(args, mbox); writeMailboxName(args, mbox);
simpleCommand("CREATE", args); simpleCommand("CREATE", args);
@ -1434,7 +1434,7 @@ public class IMAPProtocol extends Protocol {
* @see "RFC2060, section 6.3.4" * @see "RFC2060, section 6.3.4"
*/ */
public void delete(String mbox) throws ProtocolException { public void delete(String mbox) throws ProtocolException {
Argument args = new Argument(); Argument args = new Argument();
writeMailboxName(args, mbox); writeMailboxName(args, mbox);
simpleCommand("DELETE", args); simpleCommand("DELETE", args);
@ -1449,7 +1449,7 @@ public class IMAPProtocol extends Protocol {
* @see "RFC2060, section 6.3.5" * @see "RFC2060, section 6.3.5"
*/ */
public void rename(String o, String n) throws ProtocolException { public void rename(String o, String n) throws ProtocolException {
Argument args = new Argument(); Argument args = new Argument();
writeMailboxName(args, o); writeMailboxName(args, o);
writeMailboxName(args, n); writeMailboxName(args, n);
@ -1464,7 +1464,7 @@ public class IMAPProtocol extends Protocol {
* @see "RFC2060, section 6.3.6" * @see "RFC2060, section 6.3.6"
*/ */
public void subscribe(String mbox) throws ProtocolException { public void subscribe(String mbox) throws ProtocolException {
Argument args = new Argument(); Argument args = new Argument();
writeMailboxName(args, mbox); writeMailboxName(args, mbox);
simpleCommand("SUBSCRIBE", args); simpleCommand("SUBSCRIBE", args);
@ -1478,7 +1478,7 @@ public class IMAPProtocol extends Protocol {
* @see "RFC2060, section 6.3.7" * @see "RFC2060, section 6.3.7"
*/ */
public void unsubscribe(String mbox) throws ProtocolException { public void unsubscribe(String mbox) throws ProtocolException {
Argument args = new Argument(); Argument args = new Argument();
writeMailboxName(args, mbox); writeMailboxName(args, mbox);
simpleCommand("UNSUBSCRIBE", args); simpleCommand("UNSUBSCRIBE", args);
@ -1493,7 +1493,7 @@ public class IMAPProtocol extends Protocol {
* @exception ProtocolException for protocol failures * @exception ProtocolException for protocol failures
* @see "RFC2060, section 6.3.8" * @see "RFC2060, section 6.3.8"
*/ */
public ListInfo[] list(String ref, String pattern) public ListInfo[] list(String ref, String pattern)
throws ProtocolException { throws ProtocolException {
return doList("LIST", ref, pattern); return doList("LIST", ref, pattern);
} }
@ -1507,7 +1507,7 @@ public class IMAPProtocol extends Protocol {
* @exception ProtocolException for protocol failures * @exception ProtocolException for protocol failures
* @see "RFC2060, section 6.3.9" * @see "RFC2060, section 6.3.9"
*/ */
public ListInfo[] lsub(String ref, String pattern) public ListInfo[] lsub(String ref, String pattern)
throws ProtocolException { throws ProtocolException {
return doList("LSUB", ref, pattern); return doList("LSUB", ref, pattern);
} }
@ -1525,7 +1525,7 @@ public class IMAPProtocol extends Protocol {
*/ */
protected ListInfo[] doList(String cmd, String ref, String pat) protected ListInfo[] doList(String cmd, String ref, String pat)
throws ProtocolException { throws ProtocolException {
Argument args = new Argument(); Argument args = new Argument();
writeMailboxName(args, ref); writeMailboxName(args, ref);
writeMailboxName(args, pat); writeMailboxName(args, pat);
@ -1534,7 +1534,7 @@ public class IMAPProtocol extends Protocol {
ListInfo[] linfo = null; ListInfo[] linfo = null;
Response response = r[r.length-1]; Response response = r[r.length-1];
if (response.isOK()) { // command succesful if (response.isOK()) { // command succesful
List<ListInfo> v = new ArrayList<>(1); List<ListInfo> v = new ArrayList<>(1);
for (int i = 0, len = r.length; i < len; i++) { for (int i = 0, len = r.length; i < len; i++) {
if (!(r[i] instanceof IMAPResponse)) if (!(r[i] instanceof IMAPResponse))
@ -1550,13 +1550,13 @@ public class IMAPProtocol extends Protocol {
linfo = v.toArray(new ListInfo[v.size()]); linfo = v.toArray(new ListInfo[v.size()]);
} }
} }
// Dispatch remaining untagged responses // Dispatch remaining untagged responses
notifyResponseHandlers(r); notifyResponseHandlers(r);
handleResult(response); handleResult(response);
return linfo; return linfo;
} }
/** /**
* APPEND Command. * APPEND Command.
* *
@ -1590,7 +1590,7 @@ public class IMAPProtocol extends Protocol {
public AppendUID appenduid(String mbox, Flags f, Date d, public AppendUID appenduid(String mbox, Flags f, Date d,
Literal data, boolean uid) throws ProtocolException { Literal data, boolean uid) throws ProtocolException {
Argument args = new Argument(); Argument args = new Argument();
writeMailboxName(args, mbox); writeMailboxName(args, mbox);
if (f != null) { // set Flags in appended message if (f != null) { // set Flags in appended message
@ -1670,8 +1670,13 @@ public class IMAPProtocol extends Protocol {
* @see "RFC2060, section 6.4.2" * @see "RFC2060, section 6.4.2"
*/ */
public void close() throws ProtocolException { public void close() throws ProtocolException {
simpleCommand("CLOSE", null); try {
} simpleCommand("CLOSE", null);
} catch (CommandFailedException ex) {
if (ex.getMessage() == null || !ex.getMessage().contains("Mailbox is read-only (opened with EXAMINE)")) // Migadu
throw ex;
}
}
/** /**
* EXPUNGE Command. * EXPUNGE Command.

Loading…
Cancel
Save