2013-04-12 12:31:58 -07:00
|
|
|
/* Copyright 2011-2013 Yorba Foundation
|
2013-02-25 15:01:37 -08:00
|
|
|
*
|
|
|
|
|
* This software is licensed under the GNU Lesser General Public License
|
|
|
|
|
* (version 2.1 or later). See the COPYING file in this distribution.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-29 22:24:47 -07:00
|
|
|
* A {@link StringParameter} that holds a mailbox reference (can be wildcarded).
|
|
|
|
|
*
|
|
|
|
|
* Used to juggle between our internal UTF-8 representation of mailboxes and IMAP's
|
2013-02-25 15:01:37 -08:00
|
|
|
* odd "modified UTF-7" representation. The value is stored in IMAP's encoded
|
|
|
|
|
* format since that's how it comes across the wire.
|
|
|
|
|
*/
|
2013-05-29 22:24:47 -07:00
|
|
|
|
2013-02-25 15:01:37 -08:00
|
|
|
public class Geary.Imap.MailboxParameter : StringParameter {
|
2013-05-29 22:24:47 -07:00
|
|
|
public MailboxParameter(string mailbox) {
|
|
|
|
|
base (utf8_to_imap_utf7(mailbox));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MailboxParameter.from_string_parameter(StringParameter string_parameter) {
|
|
|
|
|
base (string_parameter.value);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-25 15:01:37 -08:00
|
|
|
private static string utf8_to_imap_utf7(string utf8) {
|
|
|
|
|
try {
|
|
|
|
|
return Geary.ImapUtf7.utf8_to_imap_utf7(utf8);
|
|
|
|
|
} catch (ConvertError e) {
|
|
|
|
|
debug("Error encoding mailbox name '%s': %s", utf8, e.message);
|
|
|
|
|
return utf8;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string imap_utf7_to_utf8(string imap_utf7) {
|
|
|
|
|
try {
|
|
|
|
|
return Geary.ImapUtf7.imap_utf7_to_utf8(imap_utf7);
|
|
|
|
|
} catch (ConvertError e) {
|
|
|
|
|
debug("Invalid mailbox name '%s': %s", imap_utf7, e.message);
|
|
|
|
|
return imap_utf7;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string decode() {
|
|
|
|
|
return imap_utf7_to_utf8(value);
|
|
|
|
|
}
|
2013-06-05 18:24:42 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
*/
|
2013-06-24 16:46:37 -07:00
|
|
|
public override void serialize(Serializer ser, Tag tag) throws Error {
|
2013-06-05 18:24:42 -07:00
|
|
|
serialize_string(ser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
*/
|
|
|
|
|
public override string to_string() {
|
|
|
|
|
return value;
|
|
|
|
|
}
|
2013-02-25 15:01:37 -08:00
|
|
|
}
|
2013-05-29 22:24:47 -07:00
|
|
|
|