diff --git a/src/Makefile.am b/src/Makefile.am index 9414a196..edf68505 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/mu-cmd-mkdir.c b/src/mu-cmd-mkdir.c deleted file mode 100644 index 099ef6c8..00000000 --- a/src/mu-cmd-mkdir.c +++ /dev/null @@ -1,64 +0,0 @@ -/* -** Copyright (C) 2008-2011 Dirk-Jan C. Binnema -** -** 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 -#include -#include -#include -#include - -#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=] " - " [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; -} diff --git a/src/mu-cmd-view.c b/src/mu-cmd-view.c deleted file mode 100644 index aae440ce..00000000 --- a/src/mu-cmd-view.c +++ /dev/null @@ -1,100 +0,0 @@ -/* -** Copyright (C) 2008-2011 Dirk-Jan C. Binnema -** -** 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 -#include -#include -#include -#include - -#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 : ""); - } 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] []"); - 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; -} diff --git a/src/mu-cmd-extract.c b/src/mu-cmd.c similarity index 72% rename from src/mu-cmd-extract.c rename to src/mu-cmd.c index f28cadfb..cb1ace17 100644 --- a/src/mu-cmd-extract.c +++ b/src/mu-cmd.c @@ -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 : ""); + } 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] []"); + 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=] " + " [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; +} diff --git a/src/mu-maildir.c b/src/mu-maildir.c index 98492fb3..4d0e54dd 100644 --- a/src/mu-maildir.c +++ b/src/mu-maildir.c @@ -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; diff --git a/src/mu-maildir.h b/src/mu-maildir.h index c8ee45cc..435a57d0 100644 --- a/src/mu-maildir.h +++ b/src/mu-maildir.h @@ -23,7 +23,7 @@ #include #include #include /* for mode_t */ -#include /* for MuResult, MuError */ +#include G_BEGIN_DECLS diff --git a/src/mu-util-db.cc b/src/mu-util-db.cc index 7d41ad0c..2938b7cb 100644 --- a/src/mu-util-db.cc +++ b/src/mu-util-db.cc @@ -1,5 +1,5 @@ /* -** Copyright (C) 2008-2010 Dirk-Jan C. Binnema +** Copyright (C) 2008-2011 Dirk-Jan C. Binnema ** ** 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 - #include #include +#include + #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) { diff --git a/src/mu-util-db.h b/src/mu-util-db.h deleted file mode 100644 index e92b95fd..00000000 --- a/src/mu-util-db.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -** Copyright (C) 2010 Dirk-Jan C. Binnema -** -** 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 - -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__*/ diff --git a/src/mu-util.h b/src/mu-util.h index f0fb4bde..c7093615 100644 --- a/src/mu-util.h +++ b/src/mu-util.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__*/