mirror of https://github.com/djcb/mu.git
* update mu extract implementation, support --overwrite and --targetdir (WIP,
needs testing)
This commit is contained in:
parent
364620170c
commit
0ad1fb1165
|
@ -48,8 +48,8 @@ save_numbered_parts (MuMsg *msg, MuConfigOptions *opts)
|
|||
break;
|
||||
}
|
||||
|
||||
/* FIXME: targetdir, overwrite */
|
||||
if (!mu_msg_mime_part_save (msg, idx, NULL, TRUE)) {
|
||||
if (!mu_msg_mime_part_save
|
||||
(msg, idx, opts->targetdir, opts->overwrite)) {
|
||||
g_warning ("failed to save MIME-part %d", idx);
|
||||
rv = FALSE;
|
||||
break;
|
||||
|
@ -66,6 +66,8 @@ struct _SaveData {
|
|||
gboolean attachments_only;
|
||||
gboolean result;
|
||||
guint saved_num;
|
||||
const gchar* targetdir;
|
||||
gboolean overwrite;
|
||||
};
|
||||
typedef struct _SaveData SaveData;
|
||||
|
||||
|
@ -89,7 +91,8 @@ save_part_if (MuMsgPart *part, SaveData *sd)
|
|||
g_ascii_strcasecmp (part->type, "multipart") == 0)
|
||||
return;
|
||||
|
||||
sd->result = mu_msg_mime_part_save (sd->msg, part->index, NULL, TRUE);
|
||||
sd->result = mu_msg_mime_part_save (sd->msg, part->index,
|
||||
sd->targetdir, sd->overwrite);
|
||||
if (!sd->result)
|
||||
g_warning ("failed to save MIME-part %u", part->index);
|
||||
else
|
||||
|
@ -98,7 +101,8 @@ save_part_if (MuMsgPart *part, SaveData *sd)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
save_certain_parts (MuMsg *msg, gboolean attachments_only)
|
||||
save_certain_parts (MuMsg *msg, gboolean attachments_only, const gchar *targetdir,
|
||||
gboolean overwrite)
|
||||
{
|
||||
SaveData sd;
|
||||
|
||||
|
@ -106,6 +110,8 @@ save_certain_parts (MuMsg *msg, gboolean attachments_only)
|
|||
sd.result = TRUE;
|
||||
sd.saved_num = 0;
|
||||
sd.attachments_only = attachments_only;
|
||||
sd.overwrite = overwrite;
|
||||
sd.targetdir = targetdir;
|
||||
|
||||
mu_msg_msg_part_foreach (msg,
|
||||
(MuMsgPartForeachFunc)save_part_if,
|
||||
|
@ -138,9 +144,11 @@ save_parts (const char *path, MuConfigOptions *opts)
|
|||
if (opts->parts)
|
||||
rv = save_numbered_parts (msg, opts);
|
||||
else if (opts->save_attachments) /* all attachments */
|
||||
rv = save_certain_parts (msg, TRUE);
|
||||
rv = save_certain_parts (msg, TRUE,
|
||||
opts->targetdir, opts->overwrite);
|
||||
else if (opts->save_all) /* all parts */
|
||||
rv = save_certain_parts (msg, FALSE);
|
||||
rv = save_certain_parts (msg, FALSE,
|
||||
opts->targetdir, opts->overwrite);
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
||||
|
|
|
@ -218,6 +218,8 @@ config_options_group_extract (MuConfigOptions *opts)
|
|||
"save specific parts", NULL},
|
||||
{"target-dir", 0, 0, G_OPTION_ARG_FILENAME, &opts->targetdir,
|
||||
"target directory for saving", NULL},
|
||||
{"overwrite", 0, 0, G_OPTION_ARG_NONE, &opts->overwrite,
|
||||
"overwrite existing files", NULL},
|
||||
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ struct _MuConfigOptions {
|
|||
gboolean *save_attachments; /* extract all attachment parts */
|
||||
gchar *parts; /* comma-sep'd list of parts to save */
|
||||
char *targetdir; /* where to save the attachments */
|
||||
gboolean overwrite; /* should we overwrite same-named files */
|
||||
};
|
||||
typedef struct _MuConfigOptions MuConfigOptions;
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ save_part (GMimeObject *part, const char *filename,
|
|||
int fd, rv;
|
||||
GMimeDataWrapper *wrapper;
|
||||
GMimeStream *stream;
|
||||
|
||||
|
||||
rv = TRUE;
|
||||
fd = mu_util_create_writeable_fd (filename, targetdir,
|
||||
overwrite);
|
||||
|
@ -110,7 +110,7 @@ save_part (GMimeObject *part, const char *filename,
|
|||
errno != 0 ? strerror(errno) : "");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
stream = g_mime_stream_fs_new (fd);
|
||||
if (!stream) {
|
||||
g_critical ("%s: failed to create stream", __FUNCTION__);
|
||||
|
@ -119,7 +119,7 @@ save_part (GMimeObject *part, const char *filename,
|
|||
}
|
||||
|
||||
g_mime_stream_fs_set_owner (GMIME_STREAM_FS(stream),
|
||||
TRUE); /* GMimeStream will close fd */
|
||||
TRUE); /* GMimeStream will close the fd */
|
||||
|
||||
wrapper = g_mime_part_get_content_object (GMIME_PART(part));
|
||||
if (!wrapper) {
|
||||
|
@ -180,7 +180,7 @@ mu_msg_mime_part_save (MuMsg *msg, int wanted_idx,
|
|||
spd.wanted_idx = wanted_idx;
|
||||
spd.targetdir = targetdir;
|
||||
spd.overwrite = overwrite;
|
||||
spd.stream = FALSE;
|
||||
spd.stream = FALSE; /* not used yet */
|
||||
spd.result = FALSE;
|
||||
|
||||
/* get something fairly unique for building a filename;
|
||||
|
|
Loading…
Reference in New Issue