X-UIDONLY, really?

pull/194/merge
M66B 3 years ago
parent c4c8c2bf1f
commit 1e10eb8fdf

@ -1412,6 +1412,22 @@ public class IMAPFolder extends Folder implements UIDFolder, ResponseHandler {
synchronized(messageCacheLock) { synchronized(messageCacheLock) {
try { try {
IMAPProtocol p = getProtocol(); IMAPProtocol p = getProtocol();
if (p.hasCapability("X-UIDONLY") ||
(eu.faircode.email.BuildConfig.DEBUG && p.hasCapability("UIDPLUS"))) {
// Verizon
FetchProfile fp = new FetchProfile();
fp.add(UIDFolder.FetchProfileItem.UID);
fetch(msgs, fp);
UIDSet[] uids = Utility.toUIDSet(msgs);
if (uids == null)
return;
Response[] r = p.command("UID STORE " + UIDSet.toString(uids) +
" " + (value ? '+' : '-') + "FLAGS " + p.createFlagList(new Flags(flag)), null);
p.notifyResponseHandlers(r);
p.handleResult(r[r.length - 1]);
return;
}
MessageSet[] ms = Utility.toMessageSetSorted(msgs, null); MessageSet[] ms = Utility.toMessageSetSorted(msgs, null);
if (ms == null) if (ms == null)
throw new MessageRemovedException( throw new MessageRemovedException(
@ -2090,6 +2106,24 @@ public class IMAPFolder extends Folder implements UIDFolder, ResponseHandler {
synchronized(messageCacheLock) { synchronized(messageCacheLock) {
try { try {
IMAPProtocol p = getProtocol(); IMAPProtocol p = getProtocol();
if (p.hasCapability("X-UIDONLY") ||
(eu.faircode.email.BuildConfig.DEBUG && p.hasCapability("UIDPLUS"))) {
// Verizon
FetchProfile fp = new FetchProfile();
fp.add(UIDFolder.FetchProfileItem.UID);
fetch(msgs, fp);
UIDSet[] uids = Utility.toUIDSet(msgs);
if (uids == null)
return;
Argument args = new Argument();
args.writeAtom(UIDSet.toString(uids));
p.writeMailboxName(args, folder.getFullName());
Response[] r = p.command(move ? "UID MOVE" : "UID COPY", args);
p.notifyResponseHandlers(r);
p.handleResult(r[r.length - 1]);
return;
}
MessageSet[] ms = Utility.toMessageSet(msgs, null); MessageSet[] ms = Utility.toMessageSet(msgs, null);
if (ms == null) if (ms == null)
throw new MessageRemovedException( throw new MessageRemovedException(

@ -1111,16 +1111,21 @@ public class IMAPMessage extends MimeMessage implements ReadableMime {
try { try {
IMAPProtocol p = getProtocol(); IMAPProtocol p = getProtocol();
checkExpunged(); // Insure that this message is not expunged checkExpunged(); // Insure that this message is not expunged
if (flag.contains(javax.mail.Flags.Flag.DELETED) && if (p.hasCapability("X-UIDONLY") ||
"imap.mail.yahoo.co.jp".equals(p.getInetAddress().getHostName())) { "imap.mail.yahoo.co.jp".equals(p.getInetAddress().getHostName()) ||
// NO [CANNOT] STORE It's not possible to perform specified operation (eu.faircode.email.BuildConfig.DEBUG && p.hasCapability("UIDPLUS"))) {
long uid = ((IMAPFolder) getFolder()).getUID(this); // Verizon
// Yahoo: NO [CANNOT] STORE It's not possible to perform specified operation
long uid = getUID();
if (uid < 0) {
UID u = p.fetchUID(getSequenceNumber());
if (u != null)
uid = u.uid;
}
Response[] r = p.command("UID STORE " + uid + Response[] r = p.command("UID STORE " + uid +
" " + (set ? '+' : '-') + "FLAGS (\\Deleted)", null); " " + (set ? '+' : '-') + "FLAGS " + p.createFlagList(new Flags(flag)), null);
p.notifyResponseHandlers(r); p.notifyResponseHandlers(r);
p.handleResult(r[r.length - 1]); p.handleResult(r[r.length - 1]);
flag.remove(javax.mail.Flags.Flag.DELETED);
if (flag.getSystemFlags().length == 0)
return; return;
} }
p.storeFlags(getSequenceNumber(), flag, set); p.storeFlags(getSequenceNumber(), flag, set);

@ -1167,7 +1167,7 @@ public class IMAPProtocol extends Protocol {
* @param name the name to encode * @param name the name to encode
* @since JavaMail 1.6.0 * @since JavaMail 1.6.0
*/ */
protected void writeMailboxName(Argument args, String name) { public void writeMailboxName(Argument args, String name) {
if (utf8) if (utf8)
args.writeString(name, StandardCharsets.UTF_8); args.writeString(name, StandardCharsets.UTF_8);
else else
@ -2397,7 +2397,7 @@ public class IMAPProtocol extends Protocol {
* @return the IMAP flag_list * @return the IMAP flag_list
* @since JavaMail 1.5.4 * @since JavaMail 1.5.4
*/ */
protected String createFlagList(Flags flags) { public String createFlagList(Flags flags) {
StringBuilder sb = new StringBuilder("("); // start of flag_list StringBuilder sb = new StringBuilder("("); // start of flag_list
Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags

@ -866,9 +866,6 @@ class Core {
// Mark message (un)seen // Mark message (un)seen
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean uid_command = prefs.getBoolean("uid_command", false);
if (flag != Flags.Flag.SEEN && if (flag != Flags.Flag.SEEN &&
flag != Flags.Flag.ANSWERED && flag != Flags.Flag.ANSWERED &&
flag != Flags.Flag.FLAGGED && flag != Flags.Flag.FLAGGED &&
@ -917,32 +914,6 @@ class Core {
if (uids.size() == 0) if (uids.size() == 0)
return; return;
if (uid_command) {
String flags;
if (flag == Flags.Flag.SEEN)
flags = "\\Seen";
else if (flag == Flags.Flag.ANSWERED)
flags = "\\Answered";
else if (flag == Flags.Flag.FLAGGED)
flags = "\\Flagged";
else if (flag == Flags.Flag.DELETED)
flags = "\\Deleted";
else
throw new IllegalArgumentException("Unknown flag=" + flag);
ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
for (long uid : uids) {
Response[] r = protocol.command(
"UID STORE " + uid + (set ? " +" : " -") + "FLAGS " + flags, null);
protocol.notifyResponseHandlers(r);
protocol.handleResult(r[r.length - 1]);
}
return null;
}
});
} else {
Message[] imessages = ifolder.getMessagesByUID(Helper.toLongArray(uids)); Message[] imessages = ifolder.getMessagesByUID(Helper.toLongArray(uids));
for (Message imessage : imessages) for (Message imessage : imessages)
if (imessage == null) if (imessage == null)
@ -952,7 +923,6 @@ class Core {
throw new MessagingException("Set flag: message missing"); throw new MessagingException("Set flag: message missing");
ifolder.setFlags(imessages, new Flags(flag), set); ifolder.setFlags(imessages, new Flags(flag), set);
}
for (EntityMessage message : messages) for (EntityMessage message : messages)
if (flag == Flags.Flag.SEEN && !message.seen.equals(set)) if (flag == Flags.Flag.SEEN && !message.seen.equals(set))
@ -4403,6 +4373,8 @@ class Core {
try { try {
if (uid_expunge) if (uid_expunge)
uid_expunge = MessageHelper.hasCapability(ifolder, "UIDPLUS"); uid_expunge = MessageHelper.hasCapability(ifolder, "UIDPLUS");
if (MessageHelper.hasCapability(ifolder, "X-UIDONLY"))
uid_expunge = true;
if (uid_expunge) { if (uid_expunge) {
FetchProfile fp = new FetchProfile(); FetchProfile fp = new FetchProfile();

Loading…
Cancel
Save