mu/src/mu-cmd-view.c

101 lines
2.5 KiB
C
Raw Normal View History

2010-08-20 20:07:36 +02:00
/*
2011-01-04 22:19:03 +01:00
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
2010-08-20 20:07:36 +02:00
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation,
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
*/
2011-01-04 22:19:03 +01:00
#if HAVE_CONFIG_H
2010-08-20 20:07:36 +02:00
#include "config.h"
2011-01-04 22:19:03 +01:00
#endif /*HAVE_CONFIG_H*/
2010-08-20 20:07:36 +02:00
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include "mu-msg.h"
2010-11-22 23:44:18 +01:00
#include "mu-str.h"
2010-08-20 20:07:36 +02:00
#include "mu-cmd.h"
#include "mu-util.h"
/* we ignore fields for now */
static gboolean
view_msg (MuMsg *msg, const gchar *fields, size_t summary_len)
2010-08-20 20:07:36 +02:00
{
const char *field;
time_t date;
2010-11-25 20:49:25 +01:00
if ((field = mu_msg_get_from (msg)))
2010-08-20 20:07:36 +02:00
g_print ("From: %s\n", field);
if ((field = mu_msg_get_to (msg)))
2010-08-20 20:07:36 +02:00
g_print ("To: %s\n", field);
if ((field = mu_msg_get_cc (msg)))
2010-08-20 20:07:36 +02:00
g_print ("Cc: %s\n", field);
if ((field = mu_msg_get_subject (msg)))
2010-08-20 20:07:36 +02:00
g_print ("Subject: %s\n", field);
if ((date = mu_msg_get_date (msg)))
2010-11-22 23:44:18 +01:00
g_print ("Date: %s\n", mu_str_date_s ("%c", date));
2010-08-20 20:07:36 +02:00
if (summary_len > 0) {
field = mu_msg_get_summary (msg, summary_len);
2010-08-20 20:07:36 +02:00
g_print ("Summary: %s\n", field ? field : "<none>");
2010-09-10 19:37:58 +02:00
} else if ((field = mu_msg_get_body_text (msg)))
g_print ("\n%s\n", field);
2010-08-20 20:07:36 +02:00
return TRUE;
}
2011-01-04 22:19:03 +01:00
MuExitCode
mu_cmd_view (MuConfig *opts)
2010-08-20 20:07:36 +02:00
{
2011-01-04 22:19:03 +01:00
int rv, i;
g_return_val_if_fail (opts, MU_EXITCODE_ERROR);
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_VIEW,
MU_EXITCODE_ERROR);
2010-08-20 20:07:36 +02:00
/* note: params[0] will be 'view' */
if (!opts->params[0] || !opts->params[1]) {
2010-11-30 08:02:29 +01:00
g_warning ("usage: mu view [options] <file> [<files>]");
2011-01-04 22:19:03 +01:00
return MU_EXITCODE_ERROR;
2010-08-20 20:07:36 +02:00
}
2011-01-04 22:19:03 +01:00
rv = MU_EXITCODE_OK;
for (i = 1; opts->params[i] && rv; ++i) {
GError *err = NULL;
MuMsg *msg = mu_msg_new (opts->params[i], NULL, &err);
if (!msg) {
g_warning ("error: %s", err->message);
g_error_free (err);
2011-01-04 22:19:03 +01:00
return MU_EXITCODE_ERROR;
}
2011-01-04 22:19:03 +01:00
if (!view_msg (msg, NULL, opts->summary_len))
rv = MU_EXITCODE_ERROR;
mu_msg_destroy (msg);
}
2010-08-20 20:07:36 +02:00
return rv;
}