svutil.c
2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/** utility wrappers around mailutils functionality **/
#include <errno.h>
#include "sv.h"
int
sv_mu_errno_to_rc (int eno)
{
switch (eno)
{
case ENOMEM:
return SIEVE_NOMEM;
case ENOENT:
return SIEVE_FAIL;
case EOK:
return SIEVE_OK;
}
return SIEVE_INTERNAL_ERROR;
}
/* we hook mailutils debug output into our diagnostics using this */
int
sv_mu_debug_print (mu_debug_t d, const char *fmt, va_list ap)
{
sv_printv(mu_debug_get_owner(d), SV_PRN_MU, fmt, ap);
return 0;
}
int
sv_mu_copy_debug_level (const mailbox_t from, mailbox_t to)
{
mu_debug_t d = 0;
size_t level;
int rc;
if (!from || !to)
return EINVAL;
rc = mailbox_get_debug (from, &d);
if (!rc)
mu_debug_get_level (d, &level);
if (!rc)
rc = mailbox_get_debug (to, &d);
if (!rc)
mu_debug_set_level (d, level);
return 0;
}
int
sv_mu_save_to (const char *toname, message_t mesg,
ticket_t ticket, const char **errmsg)
{
int res = 0;
mailbox_t to = 0;
mailbox_t from = 0;
res = mailbox_create_default (&to, toname);
if (res == ENOENT)
*errmsg = "no handler for this type of mailbox";
if (!res && ticket)
{
folder_t folder = NULL;
authority_t auth = NULL;
if (!res)
{
*errmsg = "mailbox_get_folder";
res = mailbox_get_folder (to, &folder);
}
if (!res)
{
*errmsg = "folder_get_authority";
res = folder_get_authority (folder, &auth);
}
if (!res)
{
*errmsg = "authority_set_ticket";
res = authority_set_ticket (auth, ticket);
}
}
if (!res)
{
if (message_get_mailbox (mesg, &from) == 0)
sv_mu_copy_debug_level (from, to);
}
if (!res)
{
*errmsg = "mailbox_open";
res = mailbox_open (to, MU_STREAM_WRITE | MU_STREAM_CREAT);
}
if (!res)
{
*errmsg = "mailbox_append_message";
res = mailbox_append_message (to, mesg);
if (!res)
{
*errmsg = "mailbox_close";
res = mailbox_close (to);
}
else
{
mailbox_close (to);
}
}
mailbox_destroy (&to);
if(res == 0)
*errmsg = 0;
return res;
}
int
sv_mu_mark_deleted (message_t msg)
{
attribute_t attr = 0;
int res;
res = message_get_attribute (msg, &attr);
if (!res)
attribute_set_deleted (attr);
return res;
}