Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-imap/imap-util.c @ 8729:b7ebdade6cbd HEAD
Added imap_args_to_str()
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 06 Feb 2009 13:38:54 -0500 |
parents | b9faf4db2a9f |
children | 743cc6ff3d89 |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */ |
0 | 2 |
3 #include "lib.h" | |
7620 | 4 #include "array.h" |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
5 #include "str.h" |
8729 | 6 #include "strescape.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
7 #include "mail-types.h" |
8729 | 8 #include "imap-parser.h" |
0 | 9 #include "imap-util.h" |
10 | |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
11 void imap_write_flags(string_t *dest, enum mail_flags flags, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
12 const char *const *keywords) |
0 | 13 { |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
14 size_t size; |
0 | 15 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
16 size = str_len(dest); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
17 if ((flags & MAIL_ANSWERED) != 0) |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
18 str_append(dest, "\\Answered "); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
19 if ((flags & MAIL_FLAGGED) != 0) |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
20 str_append(dest, "\\Flagged "); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
21 if ((flags & MAIL_DELETED) != 0) |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
22 str_append(dest, "\\Deleted "); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
23 if ((flags & MAIL_SEEN) != 0) |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
24 str_append(dest, "\\Seen "); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
25 if ((flags & MAIL_DRAFT) != 0) |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
26 str_append(dest, "\\Draft "); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
27 if ((flags & MAIL_RECENT) != 0) |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
28 str_append(dest, "\\Recent "); |
0 | 29 |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
30 if (keywords != NULL) { |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
31 /* we have keywords too */ |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
32 while (*keywords != NULL) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
33 str_append(dest, *keywords); |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
34 str_append_c(dest, ' '); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
35 keywords++; |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
36 } |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
37 } |
0 | 38 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
39 if (str_len(dest) != size) |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
40 str_truncate(dest, str_len(dest)-1); |
0 | 41 } |
7620 | 42 |
43 void imap_write_seq_range(string_t *dest, const ARRAY_TYPE(seq_range) *array) | |
44 { | |
45 const struct seq_range *range; | |
46 unsigned int i, count; | |
47 | |
48 range = array_get(array, &count); | |
49 for (i = 0; i < count; i++) { | |
50 if (i > 0) | |
51 str_append_c(dest, ','); | |
52 str_printfa(dest, "%u", range[i].seq1); | |
53 if (range[i].seq1 != range[i].seq2) | |
54 str_printfa(dest, ":%u", range[i].seq2); | |
55 } | |
56 } | |
8729 | 57 |
58 void imap_args_to_str(string_t *dest, const struct imap_arg *args) | |
59 { | |
60 const ARRAY_TYPE(imap_arg_list) *list; | |
61 bool first = TRUE; | |
62 | |
63 for (; args->type != IMAP_ARG_EOL; args++) { | |
64 if (first) | |
65 first = FALSE; | |
66 else | |
67 str_append_c(dest, ' '); | |
68 | |
69 switch (args->type) { | |
70 case IMAP_ARG_NIL: | |
71 str_append(dest, "NIL"); | |
72 break; | |
73 case IMAP_ARG_ATOM: | |
74 str_append(dest, IMAP_ARG_STR(args)); | |
75 break; | |
76 case IMAP_ARG_STRING: | |
77 str_append_c(dest, '"'); | |
78 str_append(dest, str_escape(IMAP_ARG_STR(args))); | |
79 str_append_c(dest, '"'); | |
80 break; | |
81 case IMAP_ARG_LITERAL: { | |
82 const char *strarg = IMAP_ARG_STR(args); | |
83 str_printfa(dest, "{%"PRIuSIZE_T"}\r\n", | |
84 strlen(strarg)); | |
85 str_append(dest, strarg); | |
86 break; | |
87 } | |
88 case IMAP_ARG_LIST: | |
89 str_append_c(dest, '('); | |
90 list = IMAP_ARG_LIST(args); | |
91 imap_args_to_str(dest, array_idx(list, 0)); | |
92 str_append_c(dest, ')'); | |
93 break; | |
94 case IMAP_ARG_LITERAL_SIZE: | |
95 case IMAP_ARG_LITERAL_SIZE_NONSYNC: | |
96 str_printfa(dest, "{%"PRIuUOFF_T"}\r\n", | |
97 IMAP_ARG_LITERAL_SIZE(args)); | |
98 str_append(dest, "<too large>"); | |
99 break; | |
100 case IMAP_ARG_EOL: | |
101 i_unreached(); | |
102 } | |
103 } | |
104 } |