2
** Copyright (C) 2008 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
4
** This program is free software; you can redistribute it and/or modify
5
** it under the terms of the GNU General Public License as published by
6
** the Free Software Foundation; either version 3 of the License, or
7
** (at your option) any later version.
9
** This program is distributed in the hope that it will be useful,
10
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
** GNU General Public License for more details.
14
** You should have received a copy of the GNU General Public License
15
** along with this program; if not, write to the Free Software Foundation,
16
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
#include "mu/mu-msg-str.h"
29
#include "mu/mu-msg-flags.h"
30
#include "app/mu-app.h"
31
#include "msg/mu-msg-gmime.h"
47
struct _MsgInfoOptions {
48
gboolean _field[OPTION_NUM];
50
typedef struct _MsgInfoOptions MsgInfoOptions;
52
static MsgInfoOptions OPTIONS;
53
static GOptionEntry OPTION_ENTRIES [] = {
54
{"subject", 's', 0, G_OPTION_ARG_NONE, &OPTIONS._field[OPTION_SUBJECT],
55
"get the message subject"},
56
{"sender", 'f', 0, G_OPTION_ARG_NONE, &OPTIONS._field[OPTION_FROM],
57
"get the message sender (From:)"},
58
{"to", 't', 0, G_OPTION_ARG_NONE, &OPTIONS._field[OPTION_TO],
59
"get the message recipients (To:)"},
60
{"cc", 'c', 0, G_OPTION_ARG_NONE, &OPTIONS._field[OPTION_CC],
61
"get the carbon-copy recipients (Cc:)"},
62
{"date", 'd', 0, G_OPTION_ARG_NONE,&OPTIONS._field[OPTION_DATE],
63
"get the message date"},
64
{"body", 'b', 0, G_OPTION_ARG_NONE, &OPTIONS._field[OPTION_BODY],
65
"get the message body (default)"},
66
{"user-agent", 'u', 0, G_OPTION_ARG_NONE, &OPTIONS._field[OPTION_USER_AGENT],
67
"get the message user agent"},
68
{"message-id", 'i', 0, G_OPTION_ARG_NONE,&OPTIONS._field[OPTION_MESSAGE_ID],
69
"get the message-id"},
70
{"priority", 'p', 0, G_OPTION_ARG_NONE, &OPTIONS._field[OPTION_PRIORITY],
71
"get the message priority"},
76
display_info_field (MuMsgGMime *msg, MsgInfoOptions *opts)
79
for (i = 0; i != OPTION_NUM; ++i) {
81
const char *str = NULL;
89
str = mu_msg_gmime_get_from (msg); break;
91
str = mu_msg_gmime_get_to (msg); break;
93
str = mu_msg_gmime_get_cc (msg); break;
95
str = mu_msg_gmime_get_subject (msg); break;
97
str = mu_msg_gmime_get_body_text (msg);
99
str = mu_msg_gmime_get_body_html (msg);
101
case OPTION_USER_AGENT:
102
str = mu_msg_gmime_get_user_agent (msg); break;
103
case OPTION_MESSAGE_ID:
104
str = mu_msg_gmime_get_msgid (msg); break;
105
case OPTION_PRIORITY:
106
str = mu_msg_str_prio(
107
mu_msg_gmime_get_priority (msg)); break;
109
time_t t = mu_msg_gmime_get_date (msg);
111
str = mu_msg_str_date_s(t);
115
g_warning ("%s: invalid field %d", __FUNCTION__, i);
120
g_print ("%s\n", str);
127
display_info (const char* file, MsgInfoOptions *opts)
130
g_return_val_if_fail (file, FALSE);
132
if (access (file, R_OK) != 0) {
133
g_printerr ("error opening %s: %s\n", file, strerror(errno));
137
msg = mu_msg_gmime_new (file);
139
g_printerr ("error: failed to analyze message %s\n", file);
143
display_info_field (msg, opts);
145
mu_msg_gmime_destroy (msg);
151
get_options (int *argcp, char ***argvp)
157
memset (&OPTIONS, 0, sizeof(MsgInfoOptions));
159
if (!mu_conf_handle_options (mu_app_conf(),OPTION_ENTRIES,
160
argcp, argvp, &err)) {
161
g_printerr ("option parsing failed: %s\n", err ? err->message : "");
167
/* default to body, if no options are set... */
169
for (i = 0; i != OPTION_NUM; ++i) {
170
if (OPTIONS._field[i]) {
177
OPTIONS._field[OPTION_BODY] = TRUE;
180
g_printerr ("error: expected: some mailfile(s)\n");
190
main (int argc, char *argv[])
195
if (!mu_app_init (&argc, &argv, "mu-msginfo")) {
196
g_printerr ("failed to init mu\n");
200
if (!get_options (&argc, &argv)) {
201
g_printerr ("error: failed to handle options\n");
209
for (i = 1; i != argc; ++i) {
210
if (!display_info (argv[i], &OPTIONS)) {
216
mu_msg_gmime_uninit ();