IMAP: improve keyword support, map $label1 to 5 from Thunderbird to Outlook categories
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2025 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
e33fafb8b2
commit
e1002affac
|
@ -1824,7 +1824,7 @@ public abstract class ExchangeSession {
|
||||||
}
|
}
|
||||||
if (keywords != null) {
|
if (keywords != null) {
|
||||||
for (String keyword:keywords.split(",")) {
|
for (String keyword:keywords.split(",")) {
|
||||||
buffer.append(keyword).append(" ");
|
buffer.append(convertKeywordToFlag(keyword)).append(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buffer.toString().trim();
|
return buffer.toString().trim();
|
||||||
|
@ -1999,6 +1999,78 @@ public abstract class ExchangeSession {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (int) (imapUid ^ (imapUid >>> 32));
|
return (int) (imapUid ^ (imapUid >>> 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String convertKeywordToFlag(String value) {
|
||||||
|
String result = value;
|
||||||
|
// convert flags to Thunderbird flags
|
||||||
|
ResourceBundle flagBundle = ResourceBundle.getBundle("imapflags");
|
||||||
|
Enumeration<String> flagEnumeration = flagBundle.getKeys();
|
||||||
|
while (flagEnumeration.hasMoreElements()) {
|
||||||
|
String key = flagEnumeration.nextElement();
|
||||||
|
if (value.equalsIgnoreCase(flagBundle.getString(key))) {
|
||||||
|
result = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String convertFlagToKeyword(String value) {
|
||||||
|
String result = value;
|
||||||
|
// convert flags to Thunderbird flags
|
||||||
|
ResourceBundle flagBundle = ResourceBundle.getBundle("imapflags");
|
||||||
|
try {
|
||||||
|
result = flagBundle.getString(value);
|
||||||
|
} catch (MissingResourceException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String removeFlag(String flag) {
|
||||||
|
if (keywords != null) {
|
||||||
|
final String exchangeFlag = convertFlagToKeyword(flag);
|
||||||
|
Set<String> keywordSet = new HashSet<String>();
|
||||||
|
String[] keywordArray = keywords.split(",");
|
||||||
|
for (String value : keywordArray) {
|
||||||
|
if (!value.equalsIgnoreCase(exchangeFlag)) {
|
||||||
|
keywordSet.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
keywords = StringUtil.join(keywordSet, ",");
|
||||||
|
}
|
||||||
|
return keywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String addFlag(String flag) {
|
||||||
|
final String exchangeFlag = convertFlagToKeyword(flag);
|
||||||
|
HashSet<String> keywordSet = new HashSet<String>();
|
||||||
|
boolean hasFlag = false;
|
||||||
|
if (keywords != null) {
|
||||||
|
String[] keywordArray = keywords.split(",");
|
||||||
|
for (String value : keywordArray) {
|
||||||
|
keywordSet.add(value);
|
||||||
|
if (value.equalsIgnoreCase(exchangeFlag)) {
|
||||||
|
hasFlag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasFlag) {
|
||||||
|
keywordSet.add(exchangeFlag);
|
||||||
|
}
|
||||||
|
keywords = StringUtil.join(keywordSet, ",");
|
||||||
|
return keywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setFlags(HashSet<String> flags) {
|
||||||
|
HashSet<String> keywordSet = new HashSet<String>();
|
||||||
|
for (String flag : flags) {
|
||||||
|
keywordSet.add(convertFlagToKeyword(flag));
|
||||||
|
}
|
||||||
|
keywords = StringUtil.join(keywordSet, ",");
|
||||||
|
return keywords;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1411,15 +1411,7 @@ public class ImapConnection extends AbstractConnection {
|
||||||
properties.put("answered", null);
|
properties.put("answered", null);
|
||||||
message.answered = false;
|
message.answered = false;
|
||||||
} else if (message.keywords != null) {
|
} else if (message.keywords != null) {
|
||||||
String[] keywords = message.keywords.split(",");
|
properties.put("keywords", message.removeFlag(flag));
|
||||||
HashSet<String> keywordSet = new HashSet<String>();
|
|
||||||
for (String value : keywords) {
|
|
||||||
if (!value.equalsIgnoreCase(flag)) {
|
|
||||||
keywordSet.add(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
message.keywords = StringUtil.join(keywordSet, ",");
|
|
||||||
properties.put("keywords", message.keywords);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ("+Flags".equalsIgnoreCase(action) || "+FLAGS.SILENT".equalsIgnoreCase(action)) {
|
} else if ("+Flags".equalsIgnoreCase(action) || "+FLAGS.SILENT".equalsIgnoreCase(action)) {
|
||||||
|
@ -1445,22 +1437,7 @@ public class ImapConnection extends AbstractConnection {
|
||||||
properties.put("junk", "1");
|
properties.put("junk", "1");
|
||||||
message.junk = true;
|
message.junk = true;
|
||||||
} else {
|
} else {
|
||||||
HashSet<String> keywordSet = new HashSet<String>();
|
properties.put("keywords", message.addFlag(flag));
|
||||||
boolean hasFlag = false;
|
|
||||||
if (message.keywords != null) {
|
|
||||||
String[] keywords = message.keywords.split(",");
|
|
||||||
for (String value : keywords) {
|
|
||||||
keywordSet.add(value);
|
|
||||||
if (value.equalsIgnoreCase(flag)) {
|
|
||||||
hasFlag = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!hasFlag) {
|
|
||||||
keywordSet.add(flag);
|
|
||||||
}
|
|
||||||
message.keywords = StringUtil.join(keywordSet, ",");
|
|
||||||
properties.put("keywords", message.keywords);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ("FLAGS".equalsIgnoreCase(action) || "FLAGS.SILENT".equalsIgnoreCase(action)) {
|
} else if ("FLAGS".equalsIgnoreCase(action) || "FLAGS.SILENT".equalsIgnoreCase(action)) {
|
||||||
|
@ -1496,8 +1473,7 @@ public class ImapConnection extends AbstractConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (keywords != null) {
|
if (keywords != null) {
|
||||||
message.keywords = StringUtil.join(keywords, ",");
|
properties.put("keywords", message.setFlags(keywords));
|
||||||
properties.put("keywords", message.keywords);
|
|
||||||
}
|
}
|
||||||
if (read != message.read) {
|
if (read != message.read) {
|
||||||
message.read = read;
|
message.read = read;
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
#
|
||||||
|
# DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
||||||
|
# Copyright (C) 2012 Mickael Guessant
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
$label1=Important
|
||||||
|
$label2=Work
|
||||||
|
$label3=Personal
|
||||||
|
$label4=To Do
|
||||||
|
$label5=Later
|
|
@ -0,0 +1,23 @@
|
||||||
|
#
|
||||||
|
# DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
||||||
|
# Copyright (C) 2012 Mickael Guessant
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
$label1=Important
|
||||||
|
$label2=Travail
|
||||||
|
$label3=Personnel
|
||||||
|
$label4=À faire
|
||||||
|
$label5=En attente
|
Loading…
Reference in New Issue