mirror of
https://github.com/djcb/mu.git
synced 2024-06-29 07:51:04 +02:00
* some cleanup + beginnings of extract functionality
This commit is contained in:
parent
a4515de466
commit
fc40900037
|
@ -52,6 +52,7 @@ libmu_la_SOURCES= \
|
||||||
mu-cmd-index.c \
|
mu-cmd-index.c \
|
||||||
mu-cmd-view.c \
|
mu-cmd-view.c \
|
||||||
mu-cmd-mkdir.c \
|
mu-cmd-mkdir.c \
|
||||||
|
mu-cmd-extract.c \
|
||||||
mu-config.c \
|
mu-config.c \
|
||||||
mu-config.h \
|
mu-config.h \
|
||||||
mu-index.c \
|
mu-index.c \
|
||||||
|
|
62
src/mu-cmd-extract.c
Normal file
62
src/mu-cmd-extract.c
Normal 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;
|
||||||
|
}
|
14
src/mu-cmd.c
14
src/mu-cmd.c
|
@ -43,7 +43,9 @@ cmd_from_string (const char* cmd)
|
||||||
{ "cleanup", MU_CMD_CLEANUP },
|
{ "cleanup", MU_CMD_CLEANUP },
|
||||||
{ "mkdir", MU_CMD_MKDIR },
|
{ "mkdir", MU_CMD_MKDIR },
|
||||||
{ "view", MU_CMD_VIEW },
|
{ "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)
|
for (i = 0; i != G_N_ELEMENTS(cmd_map); ++i)
|
||||||
if (strcmp (cmd, cmd_map[i]._name) == 0)
|
if (strcmp (cmd, cmd_map[i]._name) == 0)
|
||||||
|
@ -57,7 +59,8 @@ show_usage (gboolean noerror)
|
||||||
{
|
{
|
||||||
const char* usage=
|
const char* usage=
|
||||||
"usage: mu [options] command [parameters]\n"
|
"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 "
|
"see mu(1) (the mu manpage) for more information, or try "
|
||||||
"mu --help\n";
|
"mu --help\n";
|
||||||
|
|
||||||
|
@ -107,10 +110,11 @@ mu_cmd_execute (MuConfigOptions *opts)
|
||||||
|
|
||||||
switch (cmd) {
|
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_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_VIEW: return mu_cmd_view (opts);
|
||||||
|
|
||||||
case MU_CMD_UNKNOWN:
|
case MU_CMD_UNKNOWN:
|
||||||
|
|
12
src/mu-cmd.h
12
src/mu-cmd.h
|
@ -32,7 +32,7 @@ enum _MuCmd {
|
||||||
MU_CMD_CLEANUP,
|
MU_CMD_CLEANUP,
|
||||||
MU_CMD_MKDIR,
|
MU_CMD_MKDIR,
|
||||||
MU_CMD_VIEW,
|
MU_CMD_VIEW,
|
||||||
MU_CMD_HELP,
|
MU_CMD_EXTRACT,
|
||||||
|
|
||||||
MU_CMD_UNKNOWN
|
MU_CMD_UNKNOWN
|
||||||
};
|
};
|
||||||
|
@ -99,6 +99,16 @@ gboolean mu_cmd_cleanup (MuConfigOptions *opts);
|
||||||
gboolean mu_cmd_find (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
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /*__MU_CMD_H__*/
|
#endif /*__MU_CMD_H__*/
|
||||||
|
|
|
@ -770,16 +770,43 @@ mu_msg_gmime_get_summary (MuMsgGMime *msg, size_t max_lines)
|
||||||
return msg->_fields[SUMMARY_FIELD] = summarize (body, max_lines);
|
return msg->_fields[SUMMARY_FIELD] = summarize (body, max_lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct _PartForeachData {};
|
||||||
|
typedef struct _PartForeachData PartForeachData;
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
part_foreach_cb (GMimeObject *parent, GMimeObject *part, PartForeachData *data)
|
||||||
|
{
|
||||||
|
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
|
void
|
||||||
mu_msg_gmime_attach_foreach (MuMsgGMime* msg, MuMsgGMimeAttachForeachFunc func,
|
mu_msg_gmime_mime_part_foreach (MuMsgGMime* msg, MuMsgMimePartForeachFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
/* FIXME */
|
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
|
gboolean
|
||||||
mu_msg_gmime_save_attachment (MuMsgGMime *msg, unsigned num,
|
mu_msg_gmime_mime_part_save (MuMsgGMime *msg, unsigned num,
|
||||||
const char *targetdir)
|
const char *targetdir)
|
||||||
{
|
{
|
||||||
return TRUE; /* FIXME */
|
return TRUE; /* FIXME */
|
||||||
|
|
|
@ -119,10 +119,9 @@ struct _MuMsgGMimeAttach {
|
||||||
size_t size; /* size in bytes, or 0 if not available */
|
size_t size; /* size in bytes, or 0 if not available */
|
||||||
const char* mime_type; /* the mime type */
|
const char* mime_type; /* the mime type */
|
||||||
};
|
};
|
||||||
typedef struct _MuMsgGMimeAttach MuMsgGMimeAttach;
|
typedef struct _MuMsgMimePart MuMsgMimePart;
|
||||||
|
|
||||||
typedef gboolean (*MuMsgGMimeAttachForeachFunc) (MuMsgGMimeAttach *att, gpointer data);
|
|
||||||
|
|
||||||
|
typedef gboolean (*MuMsgMimePartForeachFunc) (MuMsgMimePart *part, gpointer data);
|
||||||
/**
|
/**
|
||||||
* call a user function for each attachment found in the message. the
|
* 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
|
* function will be calle d for each attachment and as long a the
|
||||||
|
@ -134,8 +133,8 @@ typedef gboolean (*MuMsgGMimeAttachForeachFunc) (MuMsgGMimeAttach *att, gpointer
|
||||||
*
|
*
|
||||||
* @return a list of attachment
|
* @return a list of attachment
|
||||||
*/
|
*/
|
||||||
void mu_msg_gmime_attach_foreach (MuMsgGMime* msg,
|
void mu_msg_gmime_mime_part_foreach (MuMsgGMime* msg,
|
||||||
MuMsgGMimeAttachForeachFunc func,
|
MuMsgMimePartForeachFunc func,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,7 +146,7 @@ void mu_msg_gmime_attach_foreach (MuMsgGMime* msg,
|
||||||
*
|
*
|
||||||
* @return TRUE if saving succeeded, FALSE otherwise
|
* @return TRUE if saving succeeded, FALSE otherwise
|
||||||
*/
|
*/
|
||||||
gboolean mu_msg_gmime_save_attachment (MuMsgGMime *msg, unsigned num,
|
gboolean mu_msg_gmime_mime_part_save (MuMsgGMime *msg, unsigned num,
|
||||||
const char *targetdir);
|
const char *targetdir);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user