Skip to content
Newer
Older
100644 640 lines (512 sloc) 14.1 KB
3468315 @djcb * minor updates / cleanups
authored May 22, 2011
1 /* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
fc40900 @djcb * some cleanup + beginnings of extract functionality
authored Aug 20, 2010
2 /*
b563128 * make colorized output the default
djcb authored Jan 21, 2012
3 ** Copyright (C) 2010-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
fc40900 @djcb * some cleanup + beginnings of extract functionality
authored Aug 20, 2010
4 **
5 ** This program is free software; you can redistribute it and/or modify it
6 ** under the terms of the GNU General Public License as published by the
7 ** Free Software Foundation; either version 3, or (at your option) any
8 ** later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software Foundation,
17 ** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 **
19 */
20
2b393ed @djcb * make error messages more consistent
authored Nov 30, 2010
21 #if HAVE_CONFIG_H
fc40900 @djcb * some cleanup + beginnings of extract functionality
authored Aug 20, 2010
22 #include "config.h"
9a51016 @djcb * many: renaming/refactoring
authored Aug 25, 2010
23 #endif /*HAVE_CONFIG_H*/
fc40900 @djcb * some cleanup + beginnings of extract functionality
authored Aug 20, 2010
24
43b1c0f @djcb * WIP: rough implementation of attachment extraction
authored Aug 22, 2010
25 #include <stdlib.h>
f1ad2eb @djcb * update 'mu view' and 'mu cfind' to use colors in some cases
authored May 25, 2011
26 #include <stdio.h>
2c1f3da @djcb * mu-cmd, mu-config: add --flags parameter to 'mu move', to change th…
authored Aug 2, 2011
27 #include <string.h>
28 #include <unistd.h>
29 #include <errno.h>
43b1c0f @djcb * WIP: rough implementation of attachment extraction
authored Aug 22, 2010
30
9a51016 @djcb * many: renaming/refactoring
authored Aug 24, 2010
31 #include "mu-msg.h"
32 #include "mu-msg-part.h"
fc40900 @djcb * some cleanup + beginnings of extract functionality
authored Aug 20, 2010
33 #include "mu-cmd.h"
c3dafe2 @djcb * mu-cmd-extract.c: check targetdir for writability
authored Oct 17, 2010
34 #include "mu-util.h"
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
35 #include "mu-str.h"
eb62f52 @djcb * mu-cmd/-cfind/-find: use the split-off date funcs
authored Jul 21, 2011
36 #include "mu-date.h"
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
37 #include "mu-maildir.h"
b9be7f2 @djcb * WIP: rudimentary implementation of the 'cfind' command, to find con…
authored Mar 2, 2011
38 #include "mu-contacts.h"
39 #include "mu-runtime.h"
a571a3f @djcb * MuMsgFlags => MuFlags
authored Aug 11, 2011
40 #include "mu-flags.h"
bdf1237 @djcb * mu-mv: optionally, let it update the database (--updatedb) and prin…
authored Aug 2, 2011
41 #include "mu-store.h"
beb1972 @djcb * mu/: improved logging, using the new logging functions
authored Sep 15, 2012
42 #include "mu-log.h"
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
43
de150bd @djcb * rename the --separate option into --terminator (mu view)
authored Jul 7, 2011
44 #define VIEW_TERMINATOR '\f' /* form-feed */
57ebeda @djcb * add optional separator (\f, form-feed) between multiple messages in…
authored Jun 14, 2011
45
dabbfc3 @djcb * use the sexp export that moved to mu-msg-sexp
authored Jul 31, 2011
46 static gboolean
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
47 view_msg_sexp (MuMsg *msg, MuConfig *opts)
dabbfc3 @djcb * use the sexp export that moved to mu-msg-sexp
authored Jul 31, 2011
48 {
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
49 char *sexp;
50
acfabfd @djcb * refactor: MU_MSG_PART_OPTION -> MU_MSG_OPTION and related changes
authored Jul 18, 2012
51 sexp = mu_msg_to_sexp (msg, 0, NULL, MU_MSG_OPTION_NONE);
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
52 fputs (sexp, stdout);
53 g_free (sexp);
54
dabbfc3 @djcb * use the sexp export that moved to mu-msg-sexp
authored Jul 31, 2011
55 return TRUE;
56 }
57
58
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
59 static void
60 each_part (MuMsg *msg, MuMsgPart *part, gchar **attach)
61 {
a65af12 @djcb * mu-cmd.c: update for mu-msg-part changes
authored Aug 1, 2012
62 char *fname, *tmp;
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
63
b376074 @djcb * update for attachment checking changes
authored Aug 9, 2012
64 if (!mu_msg_part_maybe_attachment (part))
a65af12 @djcb * mu-cmd.c: update for mu-msg-part changes
authored Aug 1, 2012
65 return;
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
66
a65af12 @djcb * mu-cmd.c: update for mu-msg-part changes
authored Aug 1, 2012
67 fname = mu_msg_part_get_filename (part, FALSE);
68 if (!fname)
69 return;
70
71 tmp = *attach;
72 *attach = g_strdup_printf ("%s%s'%s'",
73 *attach ? *attach : "",
74 *attach ? ", " : "",
75 fname);
76 g_free (tmp);
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
77 }
78
79 /* return comma-sep'd list of attachments */
3468315 @djcb * minor updates / cleanups
authored May 22, 2011
80 static gchar *
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
81 get_attach_str (MuMsg *msg)
82 {
83 gchar *attach;
84
85 attach = NULL;
a65af12 @djcb * mu-cmd.c: update for mu-msg-part changes
authored Aug 1, 2012
86 mu_msg_part_foreach (msg, MU_MSG_OPTION_NONE,
87 (MuMsgPartForeachFunc)each_part, &attach);
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
88 return attach;
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
89 }
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
90
ac1d1b2 @djcb * cosmetics
authored Sep 13, 2012
91 #define color_maybe(C) do { if(color) fputs ((C),stdout);} while(0)
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
92
f1ad2eb @djcb * update 'mu view' and 'mu cfind' to use colors in some cases
authored May 25, 2011
93 static void
94 print_field (const char* field, const char *val, gboolean color)
95 {
96 if (!val)
97 return;
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
98
ccbf76b @djcb * make the output of mu cfind/extract/view locale-encoded except for …
authored Jun 2, 2011
99 color_maybe (MU_COLOR_MAGENTA);
100 mu_util_fputs_encoded (field, stdout);
101 color_maybe (MU_COLOR_DEFAULT);
102 fputs (": ", stdout);
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
103
ccbf76b @djcb * make the output of mu cfind/extract/view locale-encoded except for …
authored Jun 2, 2011
104 if (val) {
105 color_maybe (MU_COLOR_GREEN);
106 mu_util_fputs_encoded (val, stdout);
107 }
f1ad2eb @djcb * update 'mu view' and 'mu cfind' to use colors in some cases
authored May 25, 2011
108
ccbf76b @djcb * make the output of mu cfind/extract/view locale-encoded except for …
authored Jun 2, 2011
109 color_maybe (MU_COLOR_DEFAULT);
110 fputs ("\n", stdout);
f1ad2eb @djcb * update 'mu view' and 'mu cfind' to use colors in some cases
authored May 25, 2011
111 }
112
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
113
5013f4c @djcb * add --summary-len option for mu find and mu view, and document it
authored Apr 28, 2012
114 /* a summary_len of 0 mean 'don't show summary, show body */
707a1ea @djcb * mu-cmd-find.c, mu-cmd.c: make sure we pass 'make line33'
authored Jun 19, 2011
115 static void
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
116 body_or_summary (MuMsg *msg, MuConfig *opts)
707a1ea @djcb * mu-cmd-find.c, mu-cmd.c: make sure we pass 'make line33'
authored Jun 19, 2011
117 {
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
118 const char *body;
119 gboolean color;
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
120
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
121 color = !opts->nocolor;
abfcc4a @djcb * updates for mu_msg_get_body_(text|html) api change
authored Aug 9, 2012
122 body = mu_msg_get_body_text (msg,
404d32e @djcb * mu-cmd: support asking for password when decrypting
authored Sep 13, 2012
123 mu_config_get_msg_options(opts) |
124 MU_MSG_OPTION_CONSOLE_PASSWORD);
b8639f6 @djcb * mu/mu-cmd.c: enable --decrypt in 'mu view'
authored Sep 12, 2012
125 if (!body) {
126 if (mu_msg_get_flags (msg) & MU_FLAG_ENCRYPTED) {
127 color_maybe (MU_COLOR_CYAN);
128 g_print ("[No body found; "
129 "message has encrypted parts]\n");
130 } else {
131 color_maybe (MU_COLOR_MAGENTA);
132 g_print ("[No body found]\n");
133 }
134 color_maybe (MU_COLOR_DEFAULT);
f1a2e94 @djcb * crypto: update for crypto api changes
authored Jul 27, 2012
135 return;
b8639f6 @djcb * mu/mu-cmd.c: enable --decrypt in 'mu view'
authored Sep 12, 2012
136 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
137
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
138 if (opts->summary_len != 0) {
707a1ea @djcb * mu-cmd-find.c, mu-cmd.c: make sure we pass 'make line33'
authored Jun 19, 2011
139 gchar *summ;
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
140 summ = mu_str_summarize (body, opts->summary_len);
707a1ea @djcb * mu-cmd-find.c, mu-cmd.c: make sure we pass 'make line33'
authored Jun 19, 2011
141 print_field ("Summary", summ, color);
142 g_free (summ);
143 } else {
b8639f6 @djcb * mu/mu-cmd.c: enable --decrypt in 'mu view'
authored Sep 12, 2012
144 mu_util_print_encoded ("%s", body);
145 if (!g_str_has_suffix (body, "\n"))
146 g_print ("\n");
707a1ea @djcb * mu-cmd-find.c, mu-cmd.c: make sure we pass 'make line33'
authored Jun 19, 2011
147 }
148 }
149
150
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
151 /* we ignore fields for now */
5013f4c @djcb * add --summary-len option for mu find and mu view, and document it
authored Apr 28, 2012
152 /* summary_len == 0 means "no summary */
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
153 static gboolean
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
154 view_msg_plain (MuMsg *msg, MuConfig *opts)
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
155 {
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
156 gchar *attachs;
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
157 time_t date;
52b7ac7 @djcb * add tags output to 'mu view'
authored Jun 16, 2011
158 const GSList *lst;
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
159 gboolean color;
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
160
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
161 color = !opts->nocolor;
ac1d1b2 @djcb * cosmetics
authored Sep 13, 2012
162
2a23762 @djcb * cosmetics
authored Apr 11, 2012
163 print_field ("From", mu_msg_get_from (msg), color);
164 print_field ("To", mu_msg_get_to (msg), color);
165 print_field ("Cc", mu_msg_get_cc (msg), color);
166 print_field ("Bcc", mu_msg_get_bcc (msg), color);
167 print_field ("Subject", mu_msg_get_subject (msg), color);
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
168
169 if ((date = mu_msg_get_date (msg)))
eb62f52 @djcb * mu-cmd/-cfind/-find: use the split-off date funcs
authored Jul 20, 2011
170 print_field ("Date", mu_date_str_s ("%c", date),
f1ad2eb @djcb * update 'mu view' and 'mu cfind' to use colors in some cases
authored May 25, 2011
171 color);
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
172
52b7ac7 @djcb * add tags output to 'mu view'
authored Jun 16, 2011
173 if ((lst = mu_msg_get_tags (msg))) {
174 gchar *tags;
175 tags = mu_str_from_list (lst,',');
176 print_field ("Tags", tags, color);
177 g_free (tags);
178 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
179
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
180 if ((attachs = get_attach_str (msg))) {
ff8f5db @djcb * improved color impl for mu view
authored May 26, 2011
181 print_field ("Attachments", attachs, color);
e780431 @djcb * mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
authored May 21, 2011
182 g_free (attachs);
183 }
707a1ea @djcb * mu-cmd-find.c, mu-cmd.c: make sure we pass 'make line33'
authored Jun 19, 2011
184
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
185 body_or_summary (msg, opts);
707a1ea @djcb * mu-cmd-find.c, mu-cmd.c: make sure we pass 'make line33'
authored Jun 19, 2011
186
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
187 return TRUE;
188 }
189
57ebeda @djcb * add optional separator (\f, form-feed) between multiple messages in…
authored Jun 13, 2011
190
a3b627f @djcb * mu-cmd: fix gboolean vs MuExitCode confusion
authored Aug 9, 2011
191 static gboolean
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
192 handle_msg (const char *fname, MuConfig *opts, GError **err)
57ebeda @djcb * add optional separator (\f, form-feed) between multiple messages in…
authored Jun 13, 2011
193 {
194 MuMsg *msg;
a3b627f @djcb * mu-cmd: fix gboolean vs MuExitCode confusion
authored Aug 9, 2011
195 gboolean rv;
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
196
57ebeda @djcb * add optional separator (\f, form-feed) between multiple messages in…
authored Jun 13, 2011
197 err = NULL;
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
198 msg = mu_msg_new_from_file (fname, NULL, err);
199 if (!msg)
a3b627f @djcb * mu-cmd: fix gboolean vs MuExitCode confusion
authored Aug 9, 2011
200 return FALSE;
dabbfc3 @djcb * use the sexp export that moved to mu-msg-sexp
authored Jul 31, 2011
201
202 switch (opts->format) {
203 case MU_CONFIG_FORMAT_PLAIN:
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
204 rv = view_msg_plain (msg, opts);
dabbfc3 @djcb * use the sexp export that moved to mu-msg-sexp
authored Jul 31, 2011
205 break;
206 case MU_CONFIG_FORMAT_SEXP:
8e6376a @djcb * crypto: support --decrypt in mu view
authored Jul 22, 2012
207 rv = view_msg_sexp (msg, opts);
dabbfc3 @djcb * use the sexp export that moved to mu-msg-sexp
authored Jul 31, 2011
208 break;
209 default:
210 g_critical ("bug: should not be reached");
a3b627f @djcb * mu-cmd: fix gboolean vs MuExitCode confusion
authored Aug 9, 2011
211 rv = FALSE;
dabbfc3 @djcb * use the sexp export that moved to mu-msg-sexp
authored Jul 31, 2011
212 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
213
57ebeda @djcb * add optional separator (\f, form-feed) between multiple messages in…
authored Jun 13, 2011
214 mu_msg_unref (msg);
215
216 return rv;
217 }
218
0a6161a @djcb * centralize formatstr parsing, cleanup
authored Jul 27, 2011
219 static gboolean
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
220 view_params_valid (MuConfig *opts, GError **err)
0a6161a @djcb * centralize formatstr parsing, cleanup
authored Jul 27, 2011
221 {
222 /* note: params[0] will be 'view' */
223 if (!opts->params[0] || !opts->params[1]) {
5013f4c @djcb * add --summary-len option for mu find and mu view, and document it
authored Apr 28, 2012
224 mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
225 "error in parameters");
0a6161a @djcb * centralize formatstr parsing, cleanup
authored Jul 27, 2011
226 return FALSE;
227 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
228
0a6161a @djcb * centralize formatstr parsing, cleanup
authored Jul 27, 2011
229 switch (opts->format) {
230 case MU_CONFIG_FORMAT_PLAIN:
231 case MU_CONFIG_FORMAT_SEXP:
232 break;
233 default:
5013f4c @djcb * add --summary-len option for mu find and mu view, and document it
authored Apr 28, 2012
234 mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
235 "invalid output format");
0a6161a @djcb * centralize formatstr parsing, cleanup
authored Jul 27, 2011
236 return FALSE;
237 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
238
0a6161a @djcb * centralize formatstr parsing, cleanup
authored Jul 27, 2011
239 return TRUE;
240 }
241
57ebeda @djcb * add optional separator (\f, form-feed) between multiple messages in…
authored Jun 13, 2011
242
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
243 MuError
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
244 mu_cmd_view (MuConfig *opts, GError **err)
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
245 {
a3b627f @djcb * mu-cmd: fix gboolean vs MuExitCode confusion
authored Aug 9, 2011
246 int i;
247 gboolean rv;
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
248
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
249 g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
250 g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_VIEW,
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
251 MU_ERROR_INTERNAL);
0a6161a @djcb * centralize formatstr parsing, cleanup
authored Jul 27, 2011
252
b8639f6 @djcb * mu/mu-cmd.c: enable --decrypt in 'mu view'
authored Sep 12, 2012
253 rv = view_params_valid (opts, err);
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
254 if (!rv)
255 goto leave;
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
256
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
257 for (i = 1; opts->params[i]; ++i) {
57ebeda @djcb * add optional separator (\f, form-feed) between multiple messages in…
authored Jun 13, 2011
258
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
259 rv = handle_msg (opts->params[i], opts, err);
a3b627f @djcb * mu-cmd: fix gboolean vs MuExitCode confusion
authored Aug 9, 2011
260 if (!rv)
57ebeda @djcb * add optional separator (\f, form-feed) between multiple messages in…
authored Jun 13, 2011
261 break;
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
262
57ebeda @djcb * add optional separator (\f, form-feed) between multiple messages in…
authored Jun 13, 2011
263 /* add a separator between two messages? */
de150bd @djcb * rename the --separate option into --terminator (mu view)
authored Jul 7, 2011
264 if (opts->terminator)
265 g_print ("%c", VIEW_TERMINATOR);
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
266 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
267
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
268 leave:
269 if (!rv)
270 return err && *err ? (*err)->code : MU_ERROR;
271
272 return MU_OK;
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
273 }
274
275
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
276 MuError
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
277 mu_cmd_mkdir (MuConfig *opts, GError **err)
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
278 {
279 int i;
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
280
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
281 g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
282 g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_MKDIR,
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
283 MU_ERROR_INTERNAL);
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
284
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
285 if (!opts->params[1]) {
3132b8d @djcb * mu: improve help output
authored Sep 9, 2012
286 mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
287 "missing directory parameter");
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
288 return MU_ERROR_IN_PARAMETERS;
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
289 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
290
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
291 for (i = 1; opts->params[i]; ++i)
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
292 if (!mu_maildir_mkdir (opts->params[i], opts->dirmode,
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
293 FALSE, err))
294 return err && *err ? (*err)->code :
295 MU_ERROR_FILE_CANNOT_MKDIR;
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
296 return MU_OK;
aa22e5e @djcb * some further cleanups
authored Jan 5, 2011
297 }
b9be7f2 @djcb * WIP: rudimentary implementation of the 'cfind' command, to find con…
authored Mar 2, 2011
298
4707300 @djcb * added the mu mv command for moving, removing messages (WIP)
authored Aug 1, 2011
299
bdf1237 @djcb * mu-mv: optionally, let it update the database (--updatedb) and prin…
authored Aug 2, 2011
300 static gboolean
82be497 @djcb * add 'mu add' and 'mu remove' commands for adding, removing messages…
authored Aug 3, 2011
301 check_file_okay (const char *path, gboolean cmd_add)
302 {
303 if (!g_path_is_absolute (path)) {
304 g_warning ("path is not absolute: %s", path);
305 return FALSE;
306 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
307
b1d0de2 @djcb * minor
authored Aug 11, 2011
308 if (cmd_add && access(path, R_OK) != 0) {
82be497 @djcb * add 'mu add' and 'mu remove' commands for adding, removing messages…
authored Aug 3, 2011
309 g_warning ("path is not readable: %s: %s",
310 path, strerror (errno));
311 return FALSE;
312 }
313
314 return TRUE;
315 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
316
82be497 @djcb * add 'mu add' and 'mu remove' commands for adding, removing messages…
authored Aug 3, 2011
317
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
318 MuError
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
319 mu_cmd_add (MuStore *store, MuConfig *opts, GError **err)
bdf1237 @djcb * mu-mv: optionally, let it update the database (--updatedb) and prin…
authored Aug 2, 2011
320 {
48cf82f @djcb * mu-cmd.c, mu-config.c: enable 'mu add' and 'mu remove' and fix line…
authored Aug 10, 2011
321 gboolean allok;
322 int i;
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
323
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
324 g_return_val_if_fail (store, MU_ERROR_INTERNAL);
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
325 g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
82be497 @djcb * add 'mu add' and 'mu remove' commands for adding, removing messages…
authored Aug 3, 2011
326 g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_ADD,
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
327 MU_ERROR_INTERNAL);
82be497 @djcb * add 'mu add' and 'mu remove' commands for adding, removing messages…
authored Aug 3, 2011
328
329 /* note: params[0] will be 'add' */
330 if (!opts->params[0] || !opts->params[1]) {
46a6b44 @djcb * mu: use g_print, no g_message (the latter is hidden) for output
authored Jun 12, 2012
331 g_print ("usage: mu add <file> [<files>]\n");
3132b8d @djcb * mu: improve help output
authored Sep 9, 2012
332 mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
333 "missing source and/or target");
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
334 return MU_ERROR_IN_PARAMETERS;
bdf1237 @djcb * mu-mv: optionally, let it update the database (--updatedb) and prin…
authored Aug 2, 2011
335 }
336
48cf82f @djcb * mu-cmd.c, mu-config.c: enable 'mu add' and 'mu remove' and fix line…
authored Aug 10, 2011
337 for (i = 1, allok = TRUE; opts->params[i]; ++i) {
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
338
48cf82f @djcb * mu-cmd.c, mu-config.c: enable 'mu add' and 'mu remove' and fix line…
authored Aug 10, 2011
339 const char* src;
340 src = opts->params[i];
341
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
342 if (!check_file_okay (src, TRUE) ||
d1e843c @djcb * mu-cmd.c: cosmetic
authored Sep 20, 2011
343 mu_store_add_path (store, src, NULL, err) ==
344 MU_STORE_INVALID_DOCID) {
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
345 MU_WRITE_LOG ("failed to add %s", src);
48cf82f @djcb * mu-cmd.c, mu-config.c: enable 'mu add' and 'mu remove' and fix line…
authored Aug 10, 2011
346 allok = FALSE;
347 }
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
348 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
349
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
350 if (!allok) {
3132b8d @djcb * mu: improve help output
authored Sep 9, 2012
351 mu_util_g_set_error (err, MU_ERROR_XAPIAN_STORE_FAILED,
352 "store failed for some message(s)");
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
353 return MU_ERROR_XAPIAN_STORE_FAILED;
48cf82f @djcb * mu-cmd.c, mu-config.c: enable 'mu add' and 'mu remove' and fix line…
authored Aug 10, 2011
354 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
355
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
356 return MU_OK;
bdf1237 @djcb * mu-mv: optionally, let it update the database (--updatedb) and prin…
authored Aug 2, 2011
357 }
358
4707300 @djcb * added the mu mv command for moving, removing messages (WIP)
authored Aug 1, 2011
359
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
360 MuError
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
361 mu_cmd_remove (MuStore *store, MuConfig *opts, GError **err)
48cf82f @djcb * mu-cmd.c, mu-config.c: enable 'mu add' and 'mu remove' and fix line…
authored Aug 10, 2011
362 {
363 gboolean allok;
364 int i;
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
365
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
366 g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
82be497 @djcb * add 'mu add' and 'mu remove' commands for adding, removing messages…
authored Aug 3, 2011
367 g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_REMOVE,
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
368 MU_ERROR_INTERNAL);
bdf1237 @djcb * mu-mv: optionally, let it update the database (--updatedb) and prin…
authored Aug 2, 2011
369
82be497 @djcb * add 'mu add' and 'mu remove' commands for adding, removing messages…
authored Aug 3, 2011
370 /* note: params[0] will be 'add' */
371 if (!opts->params[0] || !opts->params[1]) {
372 g_warning ("usage: mu remove <file> [<files>]");
3132b8d @djcb * mu: improve help output
authored Sep 9, 2012
373 mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
374 "missing source and/or target");
e55eb4e @djcb * MuResult/MuExitCode => MuError
authored Aug 11, 2011
375 return MU_ERROR_IN_PARAMETERS;
82be497 @djcb * add 'mu add' and 'mu remove' commands for adding, removing messages…
authored Aug 3, 2011
376 }
bdf1237 @djcb * mu-mv: optionally, let it update the database (--updatedb) and prin…
authored Aug 2, 2011
377
48cf82f @djcb * mu-cmd.c, mu-config.c: enable 'mu add' and 'mu remove' and fix line…
authored Aug 10, 2011
378 for (i = 1, allok = TRUE; opts->params[i]; ++i) {
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
379
48cf82f @djcb * mu-cmd.c, mu-config.c: enable 'mu add' and 'mu remove' and fix line…
authored Aug 10, 2011
380 const char* src;
381 src = opts->params[i];
382
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
383 if (!check_file_okay (src, FALSE) ||
384 !mu_store_remove_path (store, src)) {
48cf82f @djcb * mu-cmd.c, mu-config.c: enable 'mu add' and 'mu remove' and fix line…
authored Aug 10, 2011
385 allok = FALSE;
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
386 MU_WRITE_LOG ("failed to remove %s", src);
48cf82f @djcb * mu-cmd.c, mu-config.c: enable 'mu add' and 'mu remove' and fix line…
authored Aug 10, 2011
387 }
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
388 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
389
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
390 if (!allok) {
bc6f9eb @djcb * fix glib warnings (compile time, runtime): add error gquark, don't …
authored Apr 1, 2012
391 g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_XAPIAN_STORE_FAILED,
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
392 "remove failed for some message(s)");
393 return MU_ERROR_XAPIAN_REMOVE_FAILED;
48cf82f @djcb * mu-cmd.c, mu-config.c: enable 'mu add' and 'mu remove' and fix line…
authored Aug 10, 2011
394 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
395
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
396 return MU_OK;
4707300 @djcb * added the mu mv command for moving, removing messages (WIP)
authored Aug 1, 2011
397 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
398
399
bf2585b @djcb * crypto: implement 'mu verify' command -- WIP
authored Jul 17, 2012
400
401 #ifdef BUILD_CRYPTO
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
402
403 struct _VData {
404 MuMsgPartSigStatus combined_status;
405 char *report;
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
406 gboolean oneline;
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
407 };
408 typedef struct _VData VData;
409
410 static void
411 each_sig (MuMsg *msg, MuMsgPart *part, VData *vdata)
bf2585b @djcb * crypto: implement 'mu verify' command -- WIP
authored Jul 17, 2012
412 {
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
413 MuMsgPartSigStatusReport *report;
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
414
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
415 report = part->sig_status_report;
416 if (!report)
417 return;
418
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
419 if (vdata->oneline)
420 vdata->report = g_strdup_printf
421 ("%s%s%s",
422 vdata->report ? vdata->report : "",
423 vdata->report ? "; " : "",
424 report->report);
425 else
426 vdata->report = g_strdup_printf
427 ("%s%s\t%s",
428 vdata->report ? vdata->report : "",
429 vdata->report ? "\n" : "",
430 report->report);
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
431
432 if (vdata->combined_status == MU_MSG_PART_SIG_STATUS_BAD ||
433 vdata->combined_status == MU_MSG_PART_SIG_STATUS_ERROR)
bf2585b @djcb * crypto: implement 'mu verify' command -- WIP
authored Jul 17, 2012
434 return;
435
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
436 vdata->combined_status = report->verdict;
bf2585b @djcb * crypto: implement 'mu verify' command -- WIP
authored Jul 17, 2012
437 }
438
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
439
440 static void
441 print_verdict (VData *vdata, gboolean color)
442 {
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
443 g_print ("verdict: ");
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
444
445 switch (vdata->combined_status) {
446 case MU_MSG_PART_SIG_STATUS_UNSIGNED:
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
447 g_print ("%s", "no signature found");
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
448 break;
449 case MU_MSG_PART_SIG_STATUS_GOOD:
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
450 color_maybe (MU_COLOR_GREEN);
451 g_print ("%s", "signature(s) verified");
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
452 break;
453 case MU_MSG_PART_SIG_STATUS_BAD:
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
454 color_maybe (MU_COLOR_RED);
455 g_print ("%s", "bad signature");
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
456 break;
457 case MU_MSG_PART_SIG_STATUS_ERROR:
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
458 color_maybe (MU_COLOR_RED);
459 g_print ("%s", "verification failed");
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
460 break;
461 case MU_MSG_PART_SIG_STATUS_FAIL:
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
462 color_maybe(MU_COLOR_RED);
463 g_print ("%s", "error in verification process");
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
464 break;
465 default: g_return_if_reached ();
466 }
467
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
468 color_maybe (MU_COLOR_DEFAULT);
469 if (vdata->report)
470 g_print ("%s%s\n",
471 (vdata->oneline) ? ";" : "\n",
472 vdata->report);
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
473 }
474
475
bf2585b @djcb * crypto: implement 'mu verify' command -- WIP
authored Jul 17, 2012
476 MuError
477 mu_cmd_verify (MuConfig *opts, GError **err)
478 {
479 MuMsg *msg;
acfabfd @djcb * refactor: MU_MSG_PART_OPTION -> MU_MSG_OPTION and related changes
authored Jul 18, 2012
480 MuMsgOptions msgopts;
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
481 VData vdata;
bf2585b @djcb * crypto: implement 'mu verify' command -- WIP
authored Jul 17, 2012
482
483 g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
484 g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_VERIFY,
485 MU_ERROR_INTERNAL);
486
3132b8d @djcb * mu: improve help output
authored Sep 9, 2012
487 if (!opts->params[1]) {
488 mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
489 "missing message-file parameter");
490 return MU_ERROR_IN_PARAMETERS;
491 }
492
bf2585b @djcb * crypto: implement 'mu verify' command -- WIP
authored Jul 17, 2012
493 msg = mu_msg_new_from_file (opts->params[1], NULL, err);
494 if (!msg)
495 return MU_ERROR;
496
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
497 msgopts = mu_config_get_msg_options (opts) | MU_MSG_OPTION_VERIFY;
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
498
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
499 vdata.report = NULL;
500 vdata.combined_status = MU_MSG_PART_SIG_STATUS_UNSIGNED;
1ef9dae @djcb * crypto: improved signature / verify output
authored Sep 19, 2012
501 vdata.oneline = FALSE;
502
adc2361 @djcb * enable signature verification (WIP)
authored Aug 30, 2012
503 mu_msg_part_foreach (msg, msgopts,
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
504 (MuMsgPartForeachFunc)each_sig, &vdata);
adc2361 @djcb * enable signature verification (WIP)
authored Aug 30, 2012
505
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
506 if (!opts->quiet)
507 print_verdict (&vdata, !opts->nocolor);
807c9de @djcb * crypto: better handling of crypto errors
authored Jul 18, 2012
508
bf2585b @djcb * crypto: implement 'mu verify' command -- WIP
authored Jul 17, 2012
509 mu_msg_unref (msg);
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
510 g_free (vdata.report);
bf2585b @djcb * crypto: implement 'mu verify' command -- WIP
authored Jul 17, 2012
511
14661a6 @djcb * restore mu-verify (WIP)
authored Aug 30, 2012
512 return vdata.combined_status == MU_MSG_PART_SIG_STATUS_GOOD ?
513 MU_OK : MU_ERROR;
bf2585b @djcb * crypto: implement 'mu verify' command -- WIP
authored Jul 17, 2012
514 }
515 #else
516 MuError
517 mu_cmd_verify (MuConfig *opts, GError **err)
518 {
adc2361 @djcb * enable signature verification (WIP)
authored Aug 30, 2012
519 g_warning ("this version of mu does not support the 'verify' command");
3c8bc3e @djcb * crypto: some small updates
authored Jul 18, 2012
520 return MU_ERROR_IN_PARAMETERS;
bf2585b @djcb * crypto: implement 'mu verify' command -- WIP
authored Jul 17, 2012
521 }
522
523 #endif /*!BUILD_CRYPTO*/
524
525
526
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
527 static void
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
528 show_usage (void)
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
529 {
46a6b44 @djcb * mu: use g_print, no g_message (the latter is hidden) for output
authored Jun 11, 2012
530 g_print ("usage: mu command [options] [parameters]\n");
531 g_print ("where command is one of index, find, cfind, view, mkdir, "
3132b8d @djcb * mu: improve help output
authored Sep 9, 2012
532 "extract, add, remove, verify or server\n");
46a6b44 @djcb * mu: use g_print, no g_message (the latter is hidden) for output
authored Jun 11, 2012
533 g_print ("see the mu, mu-<command> or mu-easy manpages for "
534 "more information\n");
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
535 }
fbc786f @djcb * minor changes, trailing whitespace fixes
authored Aug 29, 2011
536
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
537 typedef MuError (*store_func) (MuStore *, MuConfig *, GError **err);
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
538
6a4b094 @djcb * some refactoring for line35
authored Sep 14, 2012
539 static MuError
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
540 with_store (store_func func, MuConfig *opts, gboolean read_only,
541 GError **err)
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
542 {
543 MuStore *store;
dea2647 @djcb * fix _MuStore initialization; proliferate API change
authored Jun 20, 2012
544 MuError merr;
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
545
546 if (read_only)
547 store = mu_store_new_read_only
548 (mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB),
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
549 err);
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
550 else
551 store = mu_store_new_writable
552 (mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB),
553 mu_runtime_path(MU_RUNTIME_PATH_CONTACTS),
ef17c2f @djcb * mu cfind: some fixes
authored Jun 20, 2012
554 opts->rebuild, err);
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
555 if (!store)
556 return MU_G_ERROR_CODE(err);
dea2647 @djcb * fix _MuStore initialization; proliferate API change
authored Jun 20, 2012
557
558 mu_store_set_my_addresses (store, (const char**)opts->my_addresses);
559 merr = func (store, opts, err);
560 mu_store_unref (store);
561 return merr;
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
562 }
563
564
ac1d1b2 @djcb * cosmetics
authored Sep 13, 2012
565 static gboolean
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
566 check_params (MuConfig *opts, GError **err)
567 {
568 if (!opts->params||!opts->params[0]) {/* no command? */
569 show_usage ();
5013f4c @djcb * add --summary-len option for mu find and mu view, and document it
authored Apr 28, 2012
570 mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
571 "error in parameters");
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
572 return FALSE;
573 }
574
575 return TRUE;
576 }
577
beb1972 @djcb * mu/: improved logging, using the new logging functions
authored Sep 15, 2012
578
579 static void
580 set_log_options (MuConfig *opts)
581 {
582 MuLogOptions logopts;
583
584 logopts = MU_LOG_OPTIONS_NONE;
585
586 if (opts->quiet)
587 logopts |= MU_LOG_OPTIONS_QUIET;
588 if (!opts->nocolor)
589 logopts |= MU_LOG_OPTIONS_COLOR;
590 if (opts->log_stderr)
591 logopts |= MU_LOG_OPTIONS_STDERR;
592 if (opts->debug)
593 logopts |= MU_LOG_OPTIONS_DEBUG;
594 }
595
596
597
598
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
599 MuError
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
600 mu_cmd_execute (MuConfig *opts, GError **err)
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
601 {
3132b8d @djcb * mu: improve help output
authored Sep 9, 2012
602 MuError merr;
6a4b094 @djcb * some refactoring for line35
authored Sep 14, 2012
603
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
604 g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
605
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
606 if (!check_params(opts, err))
607 return MU_G_ERROR_CODE(err);
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
608
beb1972 @djcb * mu/: improved logging, using the new logging functions
authored Sep 15, 2012
609 set_log_options (opts);
610
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
611 switch (opts->cmd) {
2f7f3a0 @djcb * add mu help command (WIP)
authored Jul 19, 2012
612 /* already handled in mu-config.c */
613 case MU_CONFIG_CMD_HELP: return MU_OK;
614
ac1d1b2 @djcb * cosmetics
authored Sep 13, 2012
615 case MU_CONFIG_CMD_CFIND: merr = mu_cmd_cfind (opts, err); break;
616 case MU_CONFIG_CMD_MKDIR: merr = mu_cmd_mkdir (opts, err); break;
617 case MU_CONFIG_CMD_VIEW: merr = mu_cmd_view (opts, err); break;
618 case MU_CONFIG_CMD_VERIFY: merr = mu_cmd_verify (opts, err); break;
619 case MU_CONFIG_CMD_EXTRACT: merr = mu_cmd_extract (opts, err); break;
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
620
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
621 case MU_CONFIG_CMD_FIND:
6a4b094 @djcb * some refactoring for line35
authored Sep 14, 2012
622 merr = with_store (mu_cmd_find, opts, TRUE, err); break;
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
623 case MU_CONFIG_CMD_INDEX:
6a4b094 @djcb * some refactoring for line35
authored Sep 14, 2012
624 merr = with_store (mu_cmd_index, opts, FALSE, err); break;
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
625 case MU_CONFIG_CMD_ADD:
6a4b094 @djcb * some refactoring for line35
authored Sep 14, 2012
626 merr = with_store (mu_cmd_add, opts, FALSE, err); break;
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
627 case MU_CONFIG_CMD_REMOVE:
6a4b094 @djcb * some refactoring for line35
authored Sep 14, 2012
628 merr = with_store (mu_cmd_remove, opts, FALSE, err); break;
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
629 case MU_CONFIG_CMD_SERVER:
6a4b094 @djcb * some refactoring for line35
authored Sep 14, 2012
630 merr = with_store (mu_cmd_server, opts, FALSE, err); break;
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
631 default:
0ad110d @djcb * mu-cmd.c: use GError + cleanups
authored Sep 3, 2011
632 show_usage ();
3132b8d @djcb * mu: improve help output
authored Sep 9, 2012
633 mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
634 "unknown command '%s'", opts->cmdstr);
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
635 return MU_ERROR_IN_PARAMETERS;
636 }
3132b8d @djcb * mu: improve help output
authored Sep 9, 2012
637
638 return merr;
0861319 @djcb * mu-cmd*: cleanup command handling
authored Aug 30, 2011
639 }
Something went wrong with that request. Please try again.