diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 946a87d8..99d60bec 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -1824,7 +1824,7 @@ public abstract class ExchangeSession { } if (keywords != null) { for (String keyword:keywords.split(",")) { - buffer.append(keyword).append(" "); + buffer.append(convertKeywordToFlag(keyword)).append(" "); } } return buffer.toString().trim(); @@ -1999,6 +1999,78 @@ public abstract class ExchangeSession { public int hashCode() { return (int) (imapUid ^ (imapUid >>> 32)); } + + protected String convertKeywordToFlag(String value) { + String result = value; + // convert flags to Thunderbird flags + ResourceBundle flagBundle = ResourceBundle.getBundle("imapflags"); + Enumeration 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 keywordSet = new HashSet(); + 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 keywordSet = new HashSet(); + 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 flags) { + HashSet keywordSet = new HashSet(); + for (String flag : flags) { + keywordSet.add(convertFlagToKeyword(flag)); + } + keywords = StringUtil.join(keywordSet, ","); + return keywords; + } + } /** diff --git a/src/java/davmail/imap/ImapConnection.java b/src/java/davmail/imap/ImapConnection.java index 726aeb23..40e3af1e 100644 --- a/src/java/davmail/imap/ImapConnection.java +++ b/src/java/davmail/imap/ImapConnection.java @@ -1411,15 +1411,7 @@ public class ImapConnection extends AbstractConnection { properties.put("answered", null); message.answered = false; } else if (message.keywords != null) { - String[] keywords = message.keywords.split(","); - HashSet keywordSet = new HashSet(); - for (String value : keywords) { - if (!value.equalsIgnoreCase(flag)) { - keywordSet.add(value); - } - } - message.keywords = StringUtil.join(keywordSet, ","); - properties.put("keywords", message.keywords); + properties.put("keywords", message.removeFlag(flag)); } } } else if ("+Flags".equalsIgnoreCase(action) || "+FLAGS.SILENT".equalsIgnoreCase(action)) { @@ -1445,22 +1437,7 @@ public class ImapConnection extends AbstractConnection { properties.put("junk", "1"); message.junk = true; } else { - HashSet keywordSet = new HashSet(); - 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); + properties.put("keywords", message.addFlag(flag)); } } } else if ("FLAGS".equalsIgnoreCase(action) || "FLAGS.SILENT".equalsIgnoreCase(action)) { @@ -1496,8 +1473,7 @@ public class ImapConnection extends AbstractConnection { } } if (keywords != null) { - message.keywords = StringUtil.join(keywords, ","); - properties.put("keywords", message.keywords); + properties.put("keywords", message.setFlags(keywords)); } if (read != message.read) { message.read = read; diff --git a/src/java/imapflags.properties b/src/java/imapflags.properties new file mode 100644 index 00000000..a3c0ef4c --- /dev/null +++ b/src/java/imapflags.properties @@ -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 diff --git a/src/java/imapflags_fr.properties b/src/java/imapflags_fr.properties new file mode 100644 index 00000000..057ba670 --- /dev/null +++ b/src/java/imapflags_fr.properties @@ -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