* some cleanup + beginnings of extract functionality

This commit is contained in:
Dirk-Jan C. Binnema 2010-08-20 21:38:54 +03:00
parent a4515de466
commit fc40900037
6 changed files with 126 additions and 23 deletions

View File

@ -52,6 +52,7 @@ libmu_la_SOURCES= \
mu-cmd-index.c \
mu-cmd-view.c \
mu-cmd-mkdir.c \
mu-cmd-extract.c \
mu-config.c \
mu-config.h \
mu-index.c \

62
src/mu-cmd-extract.c Normal file
View File

@ -0,0 +1,62 @@
/*
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** 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.
**
*/
#include "config.h"
#include "mu-msg-gmime.h"
#include "mu-msg-str.h"
#include "mu-cmd.h"
static gboolean
show_parts (const char* path)
{
MuMsgGMime* msg;
msg = mu_msg_gmime_new (path, NULL);
if (!msg)
return FALSE;
mu_msg_gmime_mime_part_foreach (msg, NULL, NULL);
return TRUE;
}
gboolean
mu_cmd_extract (MuConfigOptions *opts)
{
gboolean rv;
g_return_val_if_fail (opts, FALSE);
/* note: params[0] will be 'view' */
if (!opts->params[0] || !opts->params[1]) {
g_printerr ("Missing files to view\n");
return FALSE;
}
mu_msg_gmime_init();
rv = show_parts (opts->params[1]);
mu_msg_gmime_uninit();
return rv;
}

View File

@ -43,7 +43,9 @@ cmd_from_string (const char* cmd)
{ "cleanup", MU_CMD_CLEANUP },
{ "mkdir", MU_CMD_MKDIR },
{ "view", MU_CMD_VIEW },
{ "index", MU_CMD_INDEX }};
{ "index", MU_CMD_INDEX },
{ "extract", MU_CMD_EXTRACT }
};
for (i = 0; i != G_N_ELEMENTS(cmd_map); ++i)
if (strcmp (cmd, cmd_map[i]._name) == 0)
@ -57,7 +59,8 @@ show_usage (gboolean noerror)
{
const char* usage=
"usage: mu [options] command [parameters]\n"
"\twhere command is one of index, find, mkdir, cleanup or view\n\n"
"\twhere command is one of index, find, view, mkdir, cleanup "
"or extract\n\n"
"see mu(1) (the mu manpage) for more information, or try "
"mu --help\n";
@ -107,12 +110,13 @@ mu_cmd_execute (MuConfigOptions *opts)
switch (cmd) {
case MU_CMD_INDEX: return mu_cmd_index (opts);
case MU_CMD_FIND: return mu_cmd_find (opts);
case MU_CMD_MKDIR: return mu_cmd_mkdir (opts);
case MU_CMD_CLEANUP: return mu_cmd_cleanup (opts);
case MU_CMD_VIEW: return mu_cmd_view (opts);
case MU_CMD_CLEANUP: return mu_cmd_cleanup (opts);
case MU_CMD_EXTRACT: return mu_cmd_extract (opts);
case MU_CMD_FIND: return mu_cmd_find (opts);
case MU_CMD_INDEX: return mu_cmd_index (opts);
case MU_CMD_MKDIR: return mu_cmd_mkdir (opts);
case MU_CMD_VIEW: return mu_cmd_view (opts);
case MU_CMD_UNKNOWN:
return show_usage (FALSE);
default:

View File

@ -32,7 +32,7 @@ enum _MuCmd {
MU_CMD_CLEANUP,
MU_CMD_MKDIR,
MU_CMD_VIEW,
MU_CMD_HELP,
MU_CMD_EXTRACT,
MU_CMD_UNKNOWN
};
@ -99,6 +99,16 @@ gboolean mu_cmd_cleanup (MuConfigOptions *opts);
gboolean mu_cmd_find (MuConfigOptions *opts);
/**
* execute the 'extract' command
*
* @param opts configuration options
*
* @return TRUE if the command succeede, FALSE otherwise
*/
gboolean mu_cmd_extract (MuConfigOptions *opts);
G_END_DECLS
#endif /*__MU_CMD_H__*/

View File

@ -770,17 +770,44 @@ mu_msg_gmime_get_summary (MuMsgGMime *msg, size_t max_lines)
return msg->_fields[SUMMARY_FIELD] = summarize (body, max_lines);
}
void
mu_msg_gmime_attach_foreach (MuMsgGMime* msg, MuMsgGMimeAttachForeachFunc func,
gpointer user_data)
struct _PartForeachData {};
typedef struct _PartForeachData PartForeachData;
static void
part_foreach_cb (GMimeObject *parent, GMimeObject *part, PartForeachData *data)
{
/* FIXME */
GMimeContentType *ct;
ct = g_mime_object_get_content_type (part);
if (!GMIME_IS_CONTENT_TYPE(ct)) {
g_warning ("not a content type!");
return;
}
g_print ("%s\n", g_mime_content_type_to_string (ct));
}
void
mu_msg_gmime_mime_part_foreach (MuMsgGMime* msg, MuMsgMimePartForeachFunc func,
gpointer user_data)
{
g_return_if_fail (msg);
g_return_if_fail (GMIME_IS_OBJECT(msg->_mime_msg));
g_mime_message_foreach (msg->_mime_msg,
(GMimeObjectForeachFunc)part_foreach_cb,
NULL);
}
gboolean
mu_msg_gmime_save_attachment (MuMsgGMime *msg, unsigned num,
const char *targetdir)
mu_msg_gmime_mime_part_save (MuMsgGMime *msg, unsigned num,
const char *targetdir)
{
return TRUE; /* FIXME */
}

View File

@ -119,10 +119,9 @@ struct _MuMsgGMimeAttach {
size_t size; /* size in bytes, or 0 if not available */
const char* mime_type; /* the mime type */
};
typedef struct _MuMsgGMimeAttach MuMsgGMimeAttach;
typedef gboolean (*MuMsgGMimeAttachForeachFunc) (MuMsgGMimeAttach *att, gpointer data);
typedef struct _MuMsgMimePart MuMsgMimePart;
typedef gboolean (*MuMsgMimePartForeachFunc) (MuMsgMimePart *part, gpointer data);
/**
* call a user function for each attachment found in the message. the
* function will be calle d for each attachment and as long a the
@ -134,9 +133,9 @@ typedef gboolean (*MuMsgGMimeAttachForeachFunc) (MuMsgGMimeAttach *att, gpointer
*
* @return a list of attachment
*/
void mu_msg_gmime_attach_foreach (MuMsgGMime* msg,
MuMsgGMimeAttachForeachFunc func,
gpointer user_data);
void mu_msg_gmime_mime_part_foreach (MuMsgGMime* msg,
MuMsgMimePartForeachFunc func,
gpointer user_data);
/**
* save a specific attachment to some targetdir
@ -147,8 +146,8 @@ void mu_msg_gmime_attach_foreach (MuMsgGMime* msg,
*
* @return TRUE if saving succeeded, FALSE otherwise
*/
gboolean mu_msg_gmime_save_attachment (MuMsgGMime *msg, unsigned num,
const char *targetdir);
gboolean mu_msg_gmime_mime_part_save (MuMsgGMime *msg, unsigned num,
const char *targetdir);
/**
* get the sender (From:) of this message