mirror of https://github.com/djcb/mu.git
* some further cleanups
This commit is contained in:
parent
6539ae4bd7
commit
aa22e5e90d
|
@ -48,11 +48,9 @@ mu_LDADD= \
|
|||
libmu_la_SOURCES= \
|
||||
mu-bookmarks.c \
|
||||
mu-bookmarks.h \
|
||||
mu-cmd-extract.c \
|
||||
mu-cmd-find.c \
|
||||
mu-cmd-index.c \
|
||||
mu-cmd-mkdir.c \
|
||||
mu-cmd-view.c \
|
||||
mu-cmd.c \
|
||||
mu-cmd.h \
|
||||
mu-config.c \
|
||||
mu-config.h \
|
||||
|
@ -95,7 +93,6 @@ libmu_la_SOURCES= \
|
|||
mu-str.c \
|
||||
mu-str.h \
|
||||
mu-util-db.cc \
|
||||
mu-util-db.h \
|
||||
mu-util.c \
|
||||
mu-util.h
|
||||
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2008-2011 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "mu-maildir.h"
|
||||
#include "mu-cmd.h"
|
||||
#include "mu-util.h"
|
||||
|
||||
MuExitCode
|
||||
mu_cmd_mkdir (MuConfig *opts)
|
||||
{
|
||||
int i;
|
||||
|
||||
g_return_val_if_fail (opts, MU_EXITCODE_ERROR);
|
||||
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_MKDIR,
|
||||
MU_EXITCODE_ERROR);
|
||||
|
||||
if (!opts->params[1]) {
|
||||
g_printerr ("usage: mu mkdir [-u,--mode=<mode>] "
|
||||
"<dir> [more dirs]");
|
||||
return MU_EXITCODE_ERROR;
|
||||
}
|
||||
|
||||
i = 1;
|
||||
while (opts->params[i]) {
|
||||
GError *err;
|
||||
err = NULL;
|
||||
if (!mu_maildir_mkdir (opts->params[i], opts->dirmode,
|
||||
FALSE, &err))
|
||||
if (err && err->message) {
|
||||
g_printerr ("mu: %s", err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
return 1;
|
||||
++i;
|
||||
}
|
||||
|
||||
return MU_EXITCODE_OK;
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2008-2011 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "mu-msg.h"
|
||||
#include "mu-str.h"
|
||||
#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)
|
||||
{
|
||||
const char *field;
|
||||
time_t date;
|
||||
|
||||
if ((field = mu_msg_get_from (msg)))
|
||||
g_print ("From: %s\n", field);
|
||||
|
||||
if ((field = mu_msg_get_to (msg)))
|
||||
g_print ("To: %s\n", field);
|
||||
|
||||
if ((field = mu_msg_get_cc (msg)))
|
||||
g_print ("Cc: %s\n", field);
|
||||
|
||||
if ((field = mu_msg_get_subject (msg)))
|
||||
g_print ("Subject: %s\n", field);
|
||||
|
||||
if ((date = mu_msg_get_date (msg)))
|
||||
g_print ("Date: %s\n", mu_str_date_s ("%c", date));
|
||||
|
||||
if (summary_len > 0) {
|
||||
field = mu_msg_get_summary (msg, summary_len);
|
||||
g_print ("Summary: %s\n", field ? field : "<none>");
|
||||
} else if ((field = mu_msg_get_body_text (msg)))
|
||||
g_print ("\n%s\n", field);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
MuExitCode
|
||||
mu_cmd_view (MuConfig *opts)
|
||||
{
|
||||
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);
|
||||
|
||||
/* note: params[0] will be 'view' */
|
||||
if (!opts->params[0] || !opts->params[1]) {
|
||||
g_warning ("usage: mu view [options] <file> [<files>]");
|
||||
return MU_EXITCODE_ERROR;
|
||||
}
|
||||
|
||||
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);
|
||||
return MU_EXITCODE_ERROR;
|
||||
}
|
||||
|
||||
if (!view_msg (msg, NULL, opts->summary_len))
|
||||
rv = MU_EXITCODE_ERROR;
|
||||
|
||||
mu_msg_destroy (msg);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
|
@ -27,6 +27,8 @@
|
|||
#include "mu-msg-part.h"
|
||||
#include "mu-cmd.h"
|
||||
#include "mu-util.h"
|
||||
#include "mu-str.h"
|
||||
#include "mu-maildir.h"
|
||||
|
||||
static gboolean
|
||||
save_numbered_parts (MuMsg *msg, MuConfig *opts)
|
||||
|
@ -251,3 +253,100 @@ mu_cmd_extract (MuConfig *opts)
|
|||
|
||||
return rv ? MU_EXITCODE_OK : MU_EXITCODE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
/* we ignore fields for now */
|
||||
static gboolean
|
||||
view_msg (MuMsg *msg, const gchar *fields, size_t summary_len)
|
||||
{
|
||||
const char *field;
|
||||
time_t date;
|
||||
|
||||
if ((field = mu_msg_get_from (msg)))
|
||||
g_print ("From: %s\n", field);
|
||||
|
||||
if ((field = mu_msg_get_to (msg)))
|
||||
g_print ("To: %s\n", field);
|
||||
|
||||
if ((field = mu_msg_get_cc (msg)))
|
||||
g_print ("Cc: %s\n", field);
|
||||
|
||||
if ((field = mu_msg_get_subject (msg)))
|
||||
g_print ("Subject: %s\n", field);
|
||||
|
||||
if ((date = mu_msg_get_date (msg)))
|
||||
g_print ("Date: %s\n", mu_str_date_s ("%c", date));
|
||||
|
||||
if (summary_len > 0) {
|
||||
field = mu_msg_get_summary (msg, summary_len);
|
||||
g_print ("Summary: %s\n", field ? field : "<none>");
|
||||
} else if ((field = mu_msg_get_body_text (msg)))
|
||||
g_print ("\n%s\n", field);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
MuExitCode
|
||||
mu_cmd_view (MuConfig *opts)
|
||||
{
|
||||
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);
|
||||
|
||||
/* note: params[0] will be 'view' */
|
||||
if (!opts->params[0] || !opts->params[1]) {
|
||||
g_warning ("usage: mu view [options] <file> [<files>]");
|
||||
return MU_EXITCODE_ERROR;
|
||||
}
|
||||
|
||||
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);
|
||||
return MU_EXITCODE_ERROR;
|
||||
}
|
||||
|
||||
if (!view_msg (msg, NULL, opts->summary_len))
|
||||
rv = MU_EXITCODE_ERROR;
|
||||
|
||||
mu_msg_destroy (msg);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
MuExitCode
|
||||
mu_cmd_mkdir (MuConfig *opts)
|
||||
{
|
||||
int i;
|
||||
|
||||
g_return_val_if_fail (opts, MU_EXITCODE_ERROR);
|
||||
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_MKDIR,
|
||||
MU_EXITCODE_ERROR);
|
||||
|
||||
if (!opts->params[1]) {
|
||||
g_warning ("usage: mu mkdir [-u,--mode=<mode>] "
|
||||
"<dir> [more dirs]");
|
||||
return MU_EXITCODE_ERROR;
|
||||
}
|
||||
|
||||
for (i = 1; opts->params[i]; ++i) {
|
||||
GError *err = NULL;
|
||||
if (!mu_maildir_mkdir (opts->params[i], opts->dirmode,
|
||||
FALSE, &err))
|
||||
if (err && err->message) {
|
||||
g_warning ("%s", err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
return MU_EXITCODE_ERROR;
|
||||
}
|
||||
|
||||
return MU_EXITCODE_OK;
|
||||
}
|
|
@ -75,7 +75,7 @@ create_maildir (const char *path, mode_t mode, GError **err)
|
|||
fullpath = mu_str_fullpath_s (path, subdirs[i]);
|
||||
rv = g_mkdir_with_parents (fullpath, (int)mode);
|
||||
if (rv != 0) {
|
||||
g_set_error (err, 0, MU_FILE_ERROR_CANNOT_MKDIR,
|
||||
g_set_error (err, 0, MU_ERROR_FILE_CANNOT_MKDIR,
|
||||
"g_mkdir_with_parents failed: %s",
|
||||
strerror (errno));
|
||||
return FALSE;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <glib.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h> /* for mode_t */
|
||||
#include <mu-util.h> /* for MuResult, MuError */
|
||||
#include <mu-util.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2008-2011 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
|
||||
|
@ -21,13 +21,12 @@
|
|||
#include "config.h"
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
#include <xapian.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <errno.h>
|
||||
|
||||
#include <xapian.h>
|
||||
|
||||
#include "mu-util.h"
|
||||
#include "mu-util-db.h"
|
||||
|
||||
char*
|
||||
mu_util_db_version (const gchar *xpath)
|
||||
|
@ -89,8 +88,6 @@ mu_util_db_is_empty (const gchar* xpath)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
gboolean
|
||||
mu_util_clear_database (const gchar *xpath)
|
||||
{
|
||||
|
|
|
@ -1,74 +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 of the License, 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_UTIL_DB_H__
|
||||
#define __MU_UTIL_DB_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* get the version of the xapian database (ie., the version of the
|
||||
* 'schema' we are using). If this version != MU_XAPIAN_DB_VERSION,
|
||||
* it's means we need to a full reindex.
|
||||
*
|
||||
* @param xpath path to the xapian database
|
||||
*
|
||||
* @return the version of the database as a newly allocated string
|
||||
* (free with g_free); if there is no version yet, it will return NULL
|
||||
*/
|
||||
gchar* mu_util_db_version (const gchar *xpath) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
/**
|
||||
* check whether the database is empty (contains 0 documents); in
|
||||
* addition, a non-existing database is considered 'empty' too
|
||||
*
|
||||
* @param xpath path to the xapian database
|
||||
*
|
||||
* @return TRUE if the database is empty, FALSE otherwise
|
||||
*/
|
||||
gboolean mu_util_db_is_empty (const gchar *xpath);
|
||||
|
||||
/**
|
||||
* check if the 'schema' of the current database is up-to-date
|
||||
*
|
||||
* @param xpath path to the xapian database
|
||||
*
|
||||
* @return TRUE if it's up-to-date, FALSE otherwise
|
||||
*/
|
||||
gboolean mu_util_db_version_up_to_date (const gchar *xpath);
|
||||
|
||||
/**
|
||||
* clear the database, ie., remove all of the contents. This is a
|
||||
* destructive operation, but the database can be restored be doing a
|
||||
* full scan of the maildirs.
|
||||
*
|
||||
* @param xpath path to the database
|
||||
*
|
||||
* @return TRUE if the clearing succeeded, FALSE otherwise.
|
||||
*/
|
||||
gboolean mu_util_clear_database (const gchar *xpath);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__MU_UTIL_DB_H__*/
|
|
@ -112,6 +112,51 @@ int mu_util_create_writeable_fd (const char* filename, const char* dir,
|
|||
gboolean overwrite)
|
||||
G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
/**
|
||||
* get the version of the xapian database (ie., the version of the
|
||||
* 'schema' we are using). If this version != MU_XAPIAN_DB_VERSION,
|
||||
* it's means we need to a full reindex.
|
||||
*
|
||||
* @param xpath path to the xapian database
|
||||
*
|
||||
* @return the version of the database as a newly allocated string
|
||||
* (free with g_free); if there is no version yet, it will return NULL
|
||||
*/
|
||||
gchar* mu_util_db_version (const gchar *xpath) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
/**
|
||||
* check whether the database is empty (contains 0 documents); in
|
||||
* addition, a non-existing database is considered 'empty' too
|
||||
*
|
||||
* @param xpath path to the xapian database
|
||||
*
|
||||
* @return TRUE if the database is empty, FALSE otherwise
|
||||
*/
|
||||
gboolean mu_util_db_is_empty (const gchar *xpath);
|
||||
|
||||
/**
|
||||
* check if the 'schema' of the current database is up-to-date
|
||||
*
|
||||
* @param xpath path to the xapian database
|
||||
*
|
||||
* @return TRUE if it's up-to-date, FALSE otherwise
|
||||
*/
|
||||
gboolean mu_util_db_version_up_to_date (const gchar *xpath);
|
||||
|
||||
/**
|
||||
* clear the database, ie., remove all of the contents. This is a
|
||||
* destructive operation, but the database can be restored be doing a
|
||||
* full scan of the maildirs.
|
||||
*
|
||||
* @param xpath path to the database
|
||||
*
|
||||
* @return TRUE if the clearing succeeded, FALSE otherwise.
|
||||
*/
|
||||
gboolean mu_util_clear_database (const gchar *xpath);
|
||||
|
||||
|
||||
/**
|
||||
* convert a string array in to a string, with the elements separated
|
||||
* by ' '
|
||||
|
@ -265,9 +310,9 @@ enum _MuError {
|
|||
MU_ERROR_FILE_CANNOT_OPEN,
|
||||
MU_ERROR_FILE_CANNOT_READ,
|
||||
MU_ERROR_FILE_CANNOT_CREATE,
|
||||
MU_FILE_ERROR_CANNOT_MKDIR,
|
||||
MU_FILE_ERROR_STAT_FAILED,
|
||||
MU_FILE_ERROR_READDIR_FAILED,
|
||||
MU_ERROR_FILE_CANNOT_MKDIR,
|
||||
MU_ERROR_FILE_STAT_FAILED,
|
||||
MU_ERROR_FILE_READDIR_FAILED,
|
||||
/* generic file-related error */
|
||||
MU_ERROR_FILE,
|
||||
|
||||
|
@ -276,10 +321,6 @@ enum _MuError {
|
|||
};
|
||||
typedef enum _MuError MuError;
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /*__MU_UTIL_H__*/
|
||||
|
|
Loading…
Reference in New Issue