mirror of https://github.com/djcb/mu.git
* update: some refactoring of commands
This commit is contained in:
parent
7ea074431c
commit
a4515de466
|
@ -48,10 +48,10 @@ mu_LDADD= \
|
||||||
libmu_la_SOURCES= \
|
libmu_la_SOURCES= \
|
||||||
mu-cmd.c \
|
mu-cmd.c \
|
||||||
mu-cmd.h \
|
mu-cmd.h \
|
||||||
mu-cmd-find.h \
|
|
||||||
mu-cmd-find.c \
|
mu-cmd-find.c \
|
||||||
mu-cmd-index.h \
|
|
||||||
mu-cmd-index.c \
|
mu-cmd-index.c \
|
||||||
|
mu-cmd-view.c \
|
||||||
|
mu-cmd-mkdir.c \
|
||||||
mu-config.c \
|
mu-config.c \
|
||||||
mu-config.h \
|
mu-config.h \
|
||||||
mu-index.c \
|
mu-index.c \
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
#include "mu-util.h"
|
#include "mu-util.h"
|
||||||
#include "mu-util-xapian.h"
|
#include "mu-util-xapian.h"
|
||||||
#include "mu-cmd-find.h"
|
#include "mu-cmd.h"
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -358,79 +358,3 @@ mu_cmd_find (MuConfigOptions *opts)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we ignore fields for now */
|
|
||||||
static gboolean
|
|
||||||
view_file (const gchar *path, const gchar *fields, size_t summary_len)
|
|
||||||
{
|
|
||||||
MuMsgGMime* msg;
|
|
||||||
const char *field;
|
|
||||||
time_t date;
|
|
||||||
|
|
||||||
msg = mu_msg_gmime_new (path, NULL);
|
|
||||||
if (!msg)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
field = mu_msg_gmime_get_from (msg);
|
|
||||||
if (field)
|
|
||||||
g_print ("From: %s\n", field);
|
|
||||||
|
|
||||||
field = mu_msg_gmime_get_to (msg);
|
|
||||||
if (field)
|
|
||||||
g_print ("To: %s\n", field);
|
|
||||||
|
|
||||||
field = mu_msg_gmime_get_cc (msg);
|
|
||||||
if (field)
|
|
||||||
g_print ("Cc: %s\n", field);
|
|
||||||
|
|
||||||
field = mu_msg_gmime_get_subject (msg);
|
|
||||||
if (field)
|
|
||||||
g_print ("Subject: %s\n", field);
|
|
||||||
|
|
||||||
date = mu_msg_gmime_get_date (msg);
|
|
||||||
if (date)
|
|
||||||
g_print ("Date: %s\n",
|
|
||||||
mu_msg_str_date_s (date));
|
|
||||||
|
|
||||||
if (summary_len > 0) {
|
|
||||||
field = mu_msg_gmime_get_summary (msg, summary_len);
|
|
||||||
g_print ("Summary: %s\n", field ? field : "<none>");
|
|
||||||
} else {
|
|
||||||
|
|
||||||
field = mu_msg_gmime_get_body_text (msg);
|
|
||||||
if (field)
|
|
||||||
g_print ("\n%s\n", field);
|
|
||||||
else
|
|
||||||
/* not really an error */
|
|
||||||
g_debug ("No text body found for %s", path);
|
|
||||||
}
|
|
||||||
|
|
||||||
mu_msg_gmime_destroy (msg);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
mu_cmd_view (MuConfigOptions *opts)
|
|
||||||
{
|
|
||||||
gboolean rv;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
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 = TRUE;
|
|
||||||
for (i = 1; opts->params[i] && rv; ++i)
|
|
||||||
rv = view_file (opts->params[i], NULL,
|
|
||||||
opts->summary_len);
|
|
||||||
|
|
||||||
mu_msg_gmime_uninit();
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "mu-msg-gmime.h"
|
#include "mu-msg-gmime.h"
|
||||||
|
|
||||||
#include "mu-index.h"
|
#include "mu-index.h"
|
||||||
#include "mu-cmd-index.h"
|
#include "mu-cmd.h"
|
||||||
|
|
||||||
static gboolean MU_CAUGHT_SIGNAL;
|
static gboolean MU_CAUGHT_SIGNAL;
|
||||||
|
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
/*
|
|
||||||
** 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.
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __MU_CMD_INDEX_H__
|
|
||||||
#define __MU_CMD_INDEX_H__
|
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
#include "mu-config.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* execute the 'index' command
|
|
||||||
*
|
|
||||||
* @param opts configuration options
|
|
||||||
*
|
|
||||||
* @return TRUE if the command succeede, FALSE otherwise
|
|
||||||
*/
|
|
||||||
gboolean mu_cmd_index (MuConfigOptions *opts);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* execute the 'cleanup' command
|
|
||||||
*
|
|
||||||
* @param opts configuration options
|
|
||||||
*
|
|
||||||
* @return TRUE if the command succeede, FALSE otherwise
|
|
||||||
*/
|
|
||||||
gboolean mu_cmd_cleanup (MuConfigOptions *opts);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /*__MU_CMD_INDEX_H__*/
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** 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
|
** under the terms of the GNU General Public License as published by the
|
||||||
|
@ -17,30 +17,41 @@
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __MU_CMD_FIND_H__
|
#include "config.h"
|
||||||
#define __MU_CMD_FIND_H__
|
|
||||||
|
|
||||||
#include <glib.h>
|
#include <unistd.h>
|
||||||
#include "mu-config.h"
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
/**
|
#include "mu-maildir.h"
|
||||||
* execute the 'find' command
|
#include "mu-cmd.h"
|
||||||
*
|
|
||||||
* @param opts configuration options
|
|
||||||
*
|
|
||||||
* @return TRUE if the command succeede, FALSE otherwise
|
|
||||||
*/
|
|
||||||
gboolean mu_cmd_find (MuConfigOptions *opts);
|
|
||||||
|
|
||||||
|
#include "mu-util.h"
|
||||||
|
|
||||||
/**
|
gboolean
|
||||||
* execute the 'view' command
|
mu_cmd_mkdir (MuConfigOptions *opts)
|
||||||
*
|
{
|
||||||
* @param opts configuration options
|
int i;
|
||||||
*
|
|
||||||
* @return TRUE if the command succeede, FALSE otherwise
|
if (!opts->params[0])
|
||||||
*/
|
return FALSE; /* shouldn't happen */
|
||||||
gboolean mu_cmd_view (MuConfigOptions *opts);
|
|
||||||
|
if (!opts->params[1]) {
|
||||||
|
g_printerr (
|
||||||
|
"usage: mu mkdir [-u,--mode=<mode>] "
|
||||||
|
"<dir> [more dirs]\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
while (opts->params[i]) {
|
||||||
|
if (!mu_maildir_mkmdir (opts->params[i], opts->dirmode,
|
||||||
|
FALSE))
|
||||||
|
return FALSE;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
#endif /*__MU_CMD_FIND_H__*/
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
** Copyright (C) 2008-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 <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "mu-msg-gmime.h"
|
||||||
|
#include "mu-msg-str.h"
|
||||||
|
#include "mu-cmd.h"
|
||||||
|
|
||||||
|
#include "mu-util.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* we ignore fields for now */
|
||||||
|
static gboolean
|
||||||
|
view_file (const gchar *path, const gchar *fields, size_t summary_len)
|
||||||
|
{
|
||||||
|
MuMsgGMime* msg;
|
||||||
|
const char *field;
|
||||||
|
time_t date;
|
||||||
|
|
||||||
|
msg = mu_msg_gmime_new (path, NULL);
|
||||||
|
if (!msg)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
field = mu_msg_gmime_get_from (msg);
|
||||||
|
if (field)
|
||||||
|
g_print ("From: %s\n", field);
|
||||||
|
|
||||||
|
field = mu_msg_gmime_get_to (msg);
|
||||||
|
if (field)
|
||||||
|
g_print ("To: %s\n", field);
|
||||||
|
|
||||||
|
field = mu_msg_gmime_get_cc (msg);
|
||||||
|
if (field)
|
||||||
|
g_print ("Cc: %s\n", field);
|
||||||
|
|
||||||
|
field = mu_msg_gmime_get_subject (msg);
|
||||||
|
if (field)
|
||||||
|
g_print ("Subject: %s\n", field);
|
||||||
|
|
||||||
|
date = mu_msg_gmime_get_date (msg);
|
||||||
|
if (date)
|
||||||
|
g_print ("Date: %s\n",
|
||||||
|
mu_msg_str_date_s (date));
|
||||||
|
|
||||||
|
if (summary_len > 0) {
|
||||||
|
field = mu_msg_gmime_get_summary (msg, summary_len);
|
||||||
|
g_print ("Summary: %s\n", field ? field : "<none>");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
field = mu_msg_gmime_get_body_text (msg);
|
||||||
|
if (field)
|
||||||
|
g_print ("\n%s\n", field);
|
||||||
|
else
|
||||||
|
/* not really an error */
|
||||||
|
g_debug ("No text body found for %s", path);
|
||||||
|
}
|
||||||
|
|
||||||
|
mu_msg_gmime_destroy (msg);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mu_cmd_view (MuConfigOptions *opts)
|
||||||
|
{
|
||||||
|
gboolean rv;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
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 = TRUE;
|
||||||
|
for (i = 1; opts->params[i] && rv; ++i)
|
||||||
|
rv = view_file (opts->params[i], NULL,
|
||||||
|
opts->summary_len);
|
||||||
|
|
||||||
|
mu_msg_gmime_uninit();
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
35
src/mu-cmd.c
35
src/mu-cmd.c
|
@ -26,13 +26,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "mu-maildir.h"
|
#include "mu-maildir.h"
|
||||||
|
|
||||||
#include "mu-cmd-index.h"
|
|
||||||
#include "mu-cmd-find.h"
|
|
||||||
|
|
||||||
#include "mu-cmd.h"
|
#include "mu-cmd.h"
|
||||||
|
|
||||||
|
|
||||||
static MuCmd
|
static MuCmd
|
||||||
cmd_from_string (const char* cmd)
|
cmd_from_string (const char* cmd)
|
||||||
{
|
{
|
||||||
|
@ -57,34 +52,6 @@ cmd_from_string (const char* cmd)
|
||||||
return MU_CMD_UNKNOWN;
|
return MU_CMD_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
cmd_mkdir (MuConfigOptions *opts)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!opts->params[0])
|
|
||||||
return FALSE; /* shouldn't happen */
|
|
||||||
|
|
||||||
if (!opts->params[1]) {
|
|
||||||
g_printerr (
|
|
||||||
"usage: mu mkdir [-u,--mode=<mode>] "
|
|
||||||
"<dir> [more dirs]\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (opts->params[i]) {
|
|
||||||
if (!mu_maildir_mkmdir (opts->params[i], opts->dirmode,
|
|
||||||
FALSE))
|
|
||||||
return FALSE;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
show_usage (gboolean noerror)
|
show_usage (gboolean noerror)
|
||||||
{
|
{
|
||||||
|
@ -142,7 +109,7 @@ mu_cmd_execute (MuConfigOptions *opts)
|
||||||
|
|
||||||
case MU_CMD_INDEX: return mu_cmd_index (opts);
|
case MU_CMD_INDEX: return mu_cmd_index (opts);
|
||||||
case MU_CMD_FIND: return mu_cmd_find (opts);
|
case MU_CMD_FIND: return mu_cmd_find (opts);
|
||||||
case MU_CMD_MKDIR: return cmd_mkdir (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_VIEW: return mu_cmd_view (opts);
|
case MU_CMD_VIEW: return mu_cmd_view (opts);
|
||||||
|
|
||||||
|
|
54
src/mu-cmd.h
54
src/mu-cmd.h
|
@ -38,7 +38,7 @@ enum _MuCmd {
|
||||||
};
|
};
|
||||||
typedef enum _MuCmd MuCmd;
|
typedef enum _MuCmd MuCmd;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* try to execute whatever is specified on the command line
|
* try to execute whatever is specified on the command line
|
||||||
*
|
*
|
||||||
* @param config a config structure with the command line params
|
* @param config a config structure with the command line params
|
||||||
|
@ -47,6 +47,58 @@ typedef enum _MuCmd MuCmd;
|
||||||
*/
|
*/
|
||||||
gboolean mu_cmd_execute (MuConfigOptions *config);
|
gboolean mu_cmd_execute (MuConfigOptions *config);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* execute the 'mkdir' command
|
||||||
|
*
|
||||||
|
* @param opts configuration options
|
||||||
|
*
|
||||||
|
* @return TRUE if the command succeeded, FALSE otherwise
|
||||||
|
*/
|
||||||
|
gboolean mu_cmd_mkdir (MuConfigOptions *opts);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* execute the 'view' command
|
||||||
|
*
|
||||||
|
* @param opts configuration options
|
||||||
|
*
|
||||||
|
* @return TRUE if the command succeeded, FALSE otherwise
|
||||||
|
*/
|
||||||
|
gboolean mu_cmd_view (MuConfigOptions *opts);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* execute the 'index' command
|
||||||
|
*
|
||||||
|
* @param opts configuration options
|
||||||
|
*
|
||||||
|
* @return TRUE if the command succeede, FALSE otherwise
|
||||||
|
*/
|
||||||
|
gboolean mu_cmd_index (MuConfigOptions *opts);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* execute the 'cleanup' command
|
||||||
|
*
|
||||||
|
* @param opts configuration options
|
||||||
|
*
|
||||||
|
* @return TRUE if the command succeede, FALSE otherwise
|
||||||
|
*/
|
||||||
|
gboolean mu_cmd_cleanup (MuConfigOptions *opts);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* execute the 'find' command
|
||||||
|
*
|
||||||
|
* @param opts configuration options
|
||||||
|
*
|
||||||
|
* @return TRUE if the command succeede, FALSE otherwise
|
||||||
|
*/
|
||||||
|
gboolean mu_cmd_find (MuConfigOptions *opts);
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /*__MU_CMD_H__*/
|
#endif /*__MU_CMD_H__*/
|
||||||
|
|
Loading…
Reference in New Issue