annotate src/lib-imap/imap-util.c @ 9266:cd29b745c8dd HEAD

configure: clock_gettime()'s -lrt adding dropped everything else from $LIBS.
author Timo Sirainen <tss@iki.fi>
date Mon, 27 Jul 2009 06:32:42 -0400
parents 743cc6ff3d89
children 00cd9aacd03c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
7620
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
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
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
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
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
8 #include "imap-parser.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "imap-util.h"
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 {
2322
aae574ed7f4c Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
14 size_t size;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 }
7620
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
42
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
43 void imap_write_seq_range(string_t *dest, const ARRAY_TYPE(seq_range) *array)
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
44 {
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
45 const struct seq_range *range;
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
46 unsigned int i, count;
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
47
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
48 range = array_get(array, &count);
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
49 for (i = 0; i < count; i++) {
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
50 if (i > 0)
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
51 str_append_c(dest, ',');
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
52 str_printfa(dest, "%u", range[i].seq1);
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
53 if (range[i].seq1 != range[i].seq2)
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
54 str_printfa(dest, ":%u", range[i].seq2);
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
55 }
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
56 }
8729
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
57
8740
743cc6ff3d89 Renamed imap_args_to_str() to imap_write_args() and added a new imap_args_to_str().
Timo Sirainen <tss@iki.fi>
parents: 8729
diff changeset
58 void imap_write_args(string_t *dest, const struct imap_arg *args)
8729
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
59 {
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
60 const ARRAY_TYPE(imap_arg_list) *list;
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
61 bool first = TRUE;
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
62
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
63 for (; args->type != IMAP_ARG_EOL; args++) {
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
64 if (first)
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
65 first = FALSE;
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
66 else
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
67 str_append_c(dest, ' ');
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
68
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
69 switch (args->type) {
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
70 case IMAP_ARG_NIL:
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
71 str_append(dest, "NIL");
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
72 break;
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
73 case IMAP_ARG_ATOM:
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
74 str_append(dest, IMAP_ARG_STR(args));
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
75 break;
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
76 case IMAP_ARG_STRING:
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
77 str_append_c(dest, '"');
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
78 str_append(dest, str_escape(IMAP_ARG_STR(args)));
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
79 str_append_c(dest, '"');
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
80 break;
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
81 case IMAP_ARG_LITERAL: {
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
82 const char *strarg = IMAP_ARG_STR(args);
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
83 str_printfa(dest, "{%"PRIuSIZE_T"}\r\n",
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
84 strlen(strarg));
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
85 str_append(dest, strarg);
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
86 break;
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
87 }
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
88 case IMAP_ARG_LIST:
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
89 str_append_c(dest, '(');
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
90 list = IMAP_ARG_LIST(args);
8740
743cc6ff3d89 Renamed imap_args_to_str() to imap_write_args() and added a new imap_args_to_str().
Timo Sirainen <tss@iki.fi>
parents: 8729
diff changeset
91 imap_write_args(dest, array_idx(list, 0));
8729
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
92 str_append_c(dest, ')');
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
93 break;
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
94 case IMAP_ARG_LITERAL_SIZE:
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
95 case IMAP_ARG_LITERAL_SIZE_NONSYNC:
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
96 str_printfa(dest, "{%"PRIuUOFF_T"}\r\n",
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
97 IMAP_ARG_LITERAL_SIZE(args));
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
98 str_append(dest, "<too large>");
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
99 break;
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
100 case IMAP_ARG_EOL:
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
101 i_unreached();
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
102 }
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
103 }
b7ebdade6cbd Added imap_args_to_str()
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
104 }
8740
743cc6ff3d89 Renamed imap_args_to_str() to imap_write_args() and added a new imap_args_to_str().
Timo Sirainen <tss@iki.fi>
parents: 8729
diff changeset
105
743cc6ff3d89 Renamed imap_args_to_str() to imap_write_args() and added a new imap_args_to_str().
Timo Sirainen <tss@iki.fi>
parents: 8729
diff changeset
106 const char *imap_args_to_str(const struct imap_arg *args)
743cc6ff3d89 Renamed imap_args_to_str() to imap_write_args() and added a new imap_args_to_str().
Timo Sirainen <tss@iki.fi>
parents: 8729
diff changeset
107 {
743cc6ff3d89 Renamed imap_args_to_str() to imap_write_args() and added a new imap_args_to_str().
Timo Sirainen <tss@iki.fi>
parents: 8729
diff changeset
108 string_t *str;
743cc6ff3d89 Renamed imap_args_to_str() to imap_write_args() and added a new imap_args_to_str().
Timo Sirainen <tss@iki.fi>
parents: 8729
diff changeset
109
743cc6ff3d89 Renamed imap_args_to_str() to imap_write_args() and added a new imap_args_to_str().
Timo Sirainen <tss@iki.fi>
parents: 8729
diff changeset
110 str = t_str_new(128);
743cc6ff3d89 Renamed imap_args_to_str() to imap_write_args() and added a new imap_args_to_str().
Timo Sirainen <tss@iki.fi>
parents: 8729
diff changeset
111 imap_write_args(str, args);
743cc6ff3d89 Renamed imap_args_to_str() to imap_write_args() and added a new imap_args_to_str().
Timo Sirainen <tss@iki.fi>
parents: 8729
diff changeset
112 return str_c(str);
743cc6ff3d89 Renamed imap_args_to_str() to imap_write_args() and added a new imap_args_to_str().
Timo Sirainen <tss@iki.fi>
parents: 8729
diff changeset
113 }