~ubuntu-branches/ubuntu/saucy/geary/saucy-updates

« back to all changes in this revision

Viewing changes to src/engine/imap/message/imap-mailbox-parameter.vala

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2013-03-14 13:48:23 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130314134823-gyk5av1g508zyj8a
Tags: 0.3.0~pr1-0ubuntu1
New upstream version (FFE lp: #1154316), supports multiple account as
well as full conversation views with inline replies

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2011-2012 Yorba Foundation
 
2
 *
 
3
 * This software is licensed under the GNU Lesser General Public License
 
4
 * (version 2.1 or later).  See the COPYING file in this distribution.
 
5
 */
 
6
 
 
7
/**
 
8
 * A StringParameter that holds a mailbox reference (can be wildcarded).  Used
 
9
 * to juggle between our internal UTF-8 representation of mailboxes and IMAP's
 
10
 * odd "modified UTF-7" representation.  The value is stored in IMAP's encoded
 
11
 * format since that's how it comes across the wire.
 
12
 */
 
13
public class Geary.Imap.MailboxParameter : StringParameter {
 
14
    private static string utf8_to_imap_utf7(string utf8) {
 
15
        try {
 
16
            return Geary.ImapUtf7.utf8_to_imap_utf7(utf8);
 
17
        } catch (ConvertError e) {
 
18
            debug("Error encoding mailbox name '%s': %s", utf8, e.message);
 
19
            return utf8;
 
20
        }
 
21
    }
 
22
    
 
23
    private static string imap_utf7_to_utf8(string imap_utf7) {
 
24
        try {
 
25
            return Geary.ImapUtf7.imap_utf7_to_utf8(imap_utf7);
 
26
        } catch (ConvertError e) {
 
27
            debug("Invalid mailbox name '%s': %s", imap_utf7, e.message);
 
28
            return imap_utf7;
 
29
        }
 
30
    }
 
31
    
 
32
    public MailboxParameter(string mailbox) {
 
33
        base (utf8_to_imap_utf7(mailbox));
 
34
    }
 
35
    
 
36
    public MailboxParameter.from_string_parameter(StringParameter string_parameter) {
 
37
        base (string_parameter.value);
 
38
    }
 
39
    
 
40
    public string decode() {
 
41
        return imap_utf7_to_utf8(value);
 
42
    }
 
43
}