utils/mu-date: remove
Remove mu-date.[ch] and convert its last users to use time_to_string instead.
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright (C) 2012-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2012-2022 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
|
||||||
@ -20,11 +20,12 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <utils/mu-utils.hh>
|
||||||
|
|
||||||
|
#include "gmime/gmime-signature.h"
|
||||||
#include "mu-msg.hh"
|
#include "mu-msg.hh"
|
||||||
#include "mu-msg-priv.hh"
|
#include "mu-msg-priv.hh"
|
||||||
#include "mu-msg-part.hh"
|
#include "mu-msg-part.hh"
|
||||||
#include "utils/mu-date.h"
|
|
||||||
|
|
||||||
#include <gmime/gmime.h>
|
#include <gmime/gmime.h>
|
||||||
#include <gmime/gmime-multipart-signed.h>
|
#include <gmime/gmime-multipart-signed.h>
|
||||||
@ -96,12 +97,12 @@ get_cert_data(GMimeCertificate* cert)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return g_strdup_printf("signer:%s, key:%s (%s,%s), trust:%s",
|
return g_strdup_printf("signer:%s, key:%s (%s,%s), trust:%s",
|
||||||
name ? name : "?",
|
name ? name : "?",
|
||||||
/* email ? email : "?", */
|
/* email ? email : "?", */
|
||||||
keyid,
|
keyid,
|
||||||
pubkey_algo,
|
pubkey_algo,
|
||||||
digest_algo,
|
digest_algo,
|
||||||
trust);
|
trust);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
@ -134,9 +135,9 @@ get_signature_status(GMimeSignatureStatus status)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
g_string_append_printf(descr,
|
g_string_append_printf(descr,
|
||||||
"%s%s",
|
"%s%s",
|
||||||
descr->len > 0 ? ", " : "",
|
descr->len > 0 ? ", " : "",
|
||||||
status_info[n].name);
|
status_info[n].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_string_free(descr, FALSE);
|
return g_string_free(descr, FALSE);
|
||||||
@ -146,26 +147,28 @@ get_signature_status(GMimeSignatureStatus status)
|
|||||||
static char*
|
static char*
|
||||||
get_verdict_report(GMimeSignature* msig)
|
get_verdict_report(GMimeSignature* msig)
|
||||||
{
|
{
|
||||||
time_t t;
|
gchar * certdata, *report, *status;
|
||||||
const char * created, *expires;
|
GMimeSignatureStatus sigstat;
|
||||||
gchar * certdata, *report, *status;
|
|
||||||
GMimeSignatureStatus sigstat;
|
|
||||||
|
|
||||||
sigstat = g_mime_signature_get_status(msig);
|
sigstat = g_mime_signature_get_status(msig);
|
||||||
status = get_signature_status(sigstat);
|
status = get_signature_status(sigstat);
|
||||||
|
|
||||||
t = g_mime_signature_get_created(msig);
|
auto date_str = [](time_t t)->std::string {
|
||||||
created = (t == 0 || t == (time_t)-1) ? "?" : mu_date_str_s("%x", t);
|
if (t == 0 || t == static_cast<time_t>(-1))
|
||||||
|
return "?";
|
||||||
|
else
|
||||||
|
return time_to_string("%x", t);
|
||||||
|
};
|
||||||
|
|
||||||
t = g_mime_signature_get_expires(msig);
|
const auto created = date_str(g_mime_signature_get_created(msig));
|
||||||
expires = (t == 0 || t == (time_t)-1) ? "?" : mu_date_str_s("%x", t);
|
const auto expires = date_str(g_mime_signature_get_expires(msig));
|
||||||
|
|
||||||
certdata = get_cert_data(g_mime_signature_get_certificate(msig));
|
certdata = get_cert_data(g_mime_signature_get_certificate(msig));
|
||||||
report = g_strdup_printf("%s; created:%s, expires:%s, %s",
|
report = g_strdup_printf("%s; created:%s, expires:%s, %s",
|
||||||
status,
|
status,
|
||||||
created,
|
created.c_str(),
|
||||||
expires,
|
expires.c_str(),
|
||||||
certdata ? certdata : "?");
|
certdata ? certdata : "?");
|
||||||
g_free(certdata);
|
g_free(certdata);
|
||||||
g_free(status);
|
g_free(status);
|
||||||
|
|
||||||
@ -220,15 +223,15 @@ get_status_report(GMimeSignatureList* sigs)
|
|||||||
status != MU_MSG_PART_SIG_STATUS_ERROR)
|
status != MU_MSG_PART_SIG_STATUS_ERROR)
|
||||||
status = MU_MSG_PART_SIG_STATUS_ERROR;
|
status = MU_MSG_PART_SIG_STATUS_ERROR;
|
||||||
else if ((sigstat & GMIME_SIGNATURE_STATUS_RED) &&
|
else if ((sigstat & GMIME_SIGNATURE_STATUS_RED) &&
|
||||||
status == MU_MSG_PART_SIG_STATUS_GOOD)
|
status == MU_MSG_PART_SIG_STATUS_GOOD)
|
||||||
status = MU_MSG_PART_SIG_STATUS_BAD;
|
status = MU_MSG_PART_SIG_STATUS_BAD;
|
||||||
|
|
||||||
rep = get_verdict_report(msig);
|
rep = get_verdict_report(msig);
|
||||||
report = g_strdup_printf("%s%s%d: %s",
|
report = g_strdup_printf("%s%s%d: %s",
|
||||||
report ? report : "",
|
report ? report : "",
|
||||||
report ? "; " : "",
|
report ? "; " : "",
|
||||||
i + 1,
|
i + 1,
|
||||||
rep);
|
rep);
|
||||||
g_free(rep);
|
g_free(rep);
|
||||||
|
|
||||||
cert = g_mime_signature_get_certificate(msig);
|
cert = g_mime_signature_get_certificate(msig);
|
||||||
@ -263,9 +266,9 @@ static inline void
|
|||||||
tag_with_sig_status(GObject* part, MuMsgPartSigStatusReport* report)
|
tag_with_sig_status(GObject* part, MuMsgPartSigStatusReport* report)
|
||||||
{
|
{
|
||||||
g_object_set_data_full(part,
|
g_object_set_data_full(part,
|
||||||
SIG_STATUS_REPORT,
|
SIG_STATUS_REPORT,
|
||||||
report,
|
report,
|
||||||
(GDestroyNotify)mu_msg_part_sig_status_report_destroy);
|
(GDestroyNotify)mu_msg_part_sig_status_report_destroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -316,10 +319,10 @@ check_decrypt_result(GMimeMultipartEncrypted* part, GMimeDecryptResult* res, GEr
|
|||||||
|
|
||||||
GMimeObject* /* this is declared in mu-msg-priv.h */
|
GMimeObject* /* this is declared in mu-msg-priv.h */
|
||||||
Mu::mu_msg_crypto_decrypt_part(GMimeMultipartEncrypted* enc,
|
Mu::mu_msg_crypto_decrypt_part(GMimeMultipartEncrypted* enc,
|
||||||
MuMsgOptions opts,
|
MuMsgOptions opts,
|
||||||
MuMsgPartPasswordFunc func,
|
MuMsgPartPasswordFunc func,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
GError** err)
|
GError** err)
|
||||||
{
|
{
|
||||||
GMimeObject* dec;
|
GMimeObject* dec;
|
||||||
GMimeDecryptResult* res;
|
GMimeDecryptResult* res;
|
||||||
|
|||||||
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
#include "utils/mu-util.h"
|
#include "utils/mu-util.h"
|
||||||
#include "utils/mu-str.h"
|
#include "utils/mu-str.h"
|
||||||
#include "utils/mu-date.h"
|
|
||||||
#include "utils/mu-utils.hh"
|
#include "utils/mu-utils.hh"
|
||||||
#include "utils/mu-xapian-utils.hh"
|
#include "utils/mu-xapian-utils.hh"
|
||||||
|
|
||||||
|
|||||||
@ -54,8 +54,6 @@ libmu_utils_la_SOURCES= \
|
|||||||
mu-async-queue.hh \
|
mu-async-queue.hh \
|
||||||
mu-command-parser.cc \
|
mu-command-parser.cc \
|
||||||
mu-command-parser.hh \
|
mu-command-parser.hh \
|
||||||
mu-date.c \
|
|
||||||
mu-date.h \
|
|
||||||
mu-error.hh \
|
mu-error.hh \
|
||||||
mu-logger.cc \
|
mu-logger.cc \
|
||||||
mu-logger.hh \
|
mu-logger.hh \
|
||||||
|
|||||||
@ -19,8 +19,6 @@ lib_mu_utils=static_library('mu-utils', [
|
|||||||
'mu-async-queue.hh',
|
'mu-async-queue.hh',
|
||||||
'mu-command-parser.cc',
|
'mu-command-parser.cc',
|
||||||
'mu-command-parser.hh',
|
'mu-command-parser.hh',
|
||||||
'mu-date.c',
|
|
||||||
'mu-date.h',
|
|
||||||
'mu-error.hh',
|
'mu-error.hh',
|
||||||
'mu-logger.cc',
|
'mu-logger.cc',
|
||||||
'mu-logger.hh',
|
'mu-logger.hh',
|
||||||
|
|||||||
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
** Copyright (C) 2012 <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 <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#include "mu-util.h"
|
|
||||||
#include "mu-date.h"
|
|
||||||
#include "mu-str.h"
|
|
||||||
|
|
||||||
const char*
|
|
||||||
mu_date_str_s (const char* frm, time_t t)
|
|
||||||
{
|
|
||||||
struct tm *tmbuf;
|
|
||||||
static char buf[128];
|
|
||||||
static int is_utf8 = -1;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (G_UNLIKELY(is_utf8 == -1))
|
|
||||||
is_utf8 = mu_util_locale_is_utf8 () ? 1 : 0;
|
|
||||||
|
|
||||||
g_return_val_if_fail (frm, NULL);
|
|
||||||
|
|
||||||
tmbuf = localtime(&t);
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
|
||||||
len = strftime (buf, sizeof(buf) - 1, frm, tmbuf);
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
|
|
||||||
if (len == 0)
|
|
||||||
return ""; /* not necessarily an error... */
|
|
||||||
|
|
||||||
if (!is_utf8) {
|
|
||||||
/* charset is _not_ utf8, so we need to convert it, so
|
|
||||||
* the date could contain locale-specific characters*/
|
|
||||||
gchar *conv;
|
|
||||||
GError *err;
|
|
||||||
err = NULL;
|
|
||||||
conv = g_locale_to_utf8 (buf, -1, NULL, NULL, &err);
|
|
||||||
if (err) {
|
|
||||||
g_warning ("conversion failed: %s", err->message);
|
|
||||||
g_error_free (err);
|
|
||||||
strcpy (buf, "<error>");
|
|
||||||
} else {
|
|
||||||
strncpy (buf, conv, sizeof(buf)-1);
|
|
||||||
buf[sizeof(buf)-1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (conv);
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
char*
|
|
||||||
mu_date_str (const char *frm, time_t t)
|
|
||||||
{
|
|
||||||
return g_strdup (mu_date_str_s(frm, t));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
|
||||||
mu_date_display_s (time_t t)
|
|
||||||
{
|
|
||||||
time_t now;
|
|
||||||
static const time_t SECS_IN_DAY = 24 * 60 * 60;
|
|
||||||
|
|
||||||
now = time (NULL);
|
|
||||||
|
|
||||||
if (ABS(now - t) > SECS_IN_DAY)
|
|
||||||
return mu_date_str_s ("%x", t);
|
|
||||||
else
|
|
||||||
return mu_date_str_s ("%X", t);
|
|
||||||
}
|
|
||||||
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
** Copyright (C) 2012-2013 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 <glib.h>
|
|
||||||
|
|
||||||
#ifndef __MU_DATE_H__
|
|
||||||
#define __MU_DATE_H__
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @addtogroup MuDate
|
|
||||||
* Date-related functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get a string for a given time_t
|
|
||||||
*
|
|
||||||
* mu_date_str_s returns a ptr to a static buffer,
|
|
||||||
* while mu_date_str returns dynamically allocated
|
|
||||||
* memory that must be freed after use.
|
|
||||||
*
|
|
||||||
* @param frm the format of the string (in strftime(3) format)
|
|
||||||
* @param t the time as time_t
|
|
||||||
*
|
|
||||||
* @return a string representation of the time; see above for what to
|
|
||||||
* do with it. Length is max. 128 bytes, inc. the ending \0. if the
|
|
||||||
* format is too long, the value will be truncated. in practice this
|
|
||||||
* should not happen.
|
|
||||||
*/
|
|
||||||
const char* mu_date_str_s (const char* frm, time_t t) G_GNUC_CONST;
|
|
||||||
char* mu_date_str (const char* frm, time_t t) G_GNUC_WARN_UNUSED_RESULT;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get a display string for a given time_t; if the given is less than
|
|
||||||
* 24h from the current time, we display the time, otherwise the date,
|
|
||||||
* using the preferred date/time for the current locale
|
|
||||||
*
|
|
||||||
* mu_str_display_date_s returns a ptr to a static buffer,
|
|
||||||
*
|
|
||||||
* @param t the time as time_t
|
|
||||||
*
|
|
||||||
* @return a string representation of the time/date
|
|
||||||
*/
|
|
||||||
const char* mu_date_display_s (time_t t);
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
#endif /*__MU_DATE_H__*/
|
|
||||||
@ -33,7 +33,6 @@
|
|||||||
#include "utils/mu-utils.hh"
|
#include "utils/mu-utils.hh"
|
||||||
#include "utils/mu-error.hh"
|
#include "utils/mu-error.hh"
|
||||||
#include "utils/mu-str.h"
|
#include "utils/mu-str.h"
|
||||||
#include "utils/mu-date.h"
|
|
||||||
|
|
||||||
using namespace Mu;
|
using namespace Mu;
|
||||||
|
|
||||||
@ -184,7 +183,7 @@ print_header(const MuConfigFormat format)
|
|||||||
switch (format) {
|
switch (format) {
|
||||||
case MU_CONFIG_FORMAT_BBDB:
|
case MU_CONFIG_FORMAT_BBDB:
|
||||||
g_print(";; -*-coding: utf-8-emacs;-*-\n"
|
g_print(";; -*-coding: utf-8-emacs;-*-\n"
|
||||||
";;; file-version: 6\n");
|
";;; file-version: 6\n");
|
||||||
break;
|
break;
|
||||||
case MU_CONFIG_FORMAT_MUTT_AB:
|
case MU_CONFIG_FORMAT_MUTT_AB:
|
||||||
g_print("Matching addresses in the mu database:\n");
|
g_print("Matching addresses in the mu database:\n");
|
||||||
@ -197,31 +196,30 @@ print_header(const MuConfigFormat format)
|
|||||||
static void
|
static void
|
||||||
each_contact_bbdb(const std::string& email, const std::string& name, time_t tstamp)
|
each_contact_bbdb(const std::string& email, const std::string& name, time_t tstamp)
|
||||||
{
|
{
|
||||||
char *fname, *lname, *now, *timestamp;
|
char *fname, *lname;
|
||||||
|
|
||||||
fname = guess_first_name(name.c_str());
|
fname = guess_first_name(name.c_str());
|
||||||
lname = guess_last_name(name.c_str());
|
lname = guess_last_name(name.c_str());
|
||||||
now = mu_date_str("%Y-%m-%d", time(NULL));
|
|
||||||
timestamp = mu_date_str("%Y-%m-%d", tstamp);
|
const auto now{time_to_string("%Y-%m-%d", time(NULL))};
|
||||||
|
const auto timestamp{time_to_string("%Y-%m-%d", tstamp)};
|
||||||
|
|
||||||
g_print("[\"%s\" \"%s\" nil nil nil nil (\"%s\") "
|
g_print("[\"%s\" \"%s\" nil nil nil nil (\"%s\") "
|
||||||
"((creation-date . \"%s\") (time-stamp . \"%s\")) nil]\n",
|
"((creation-date . \"%s\") (time-stamp . \"%s\")) nil]\n",
|
||||||
fname,
|
fname,
|
||||||
lname,
|
lname,
|
||||||
email.c_str(),
|
email.c_str(),
|
||||||
now,
|
now.c_str(),
|
||||||
timestamp);
|
timestamp.c_str());
|
||||||
|
|
||||||
g_free(now);
|
|
||||||
g_free(timestamp);
|
|
||||||
g_free(fname);
|
g_free(fname);
|
||||||
g_free(lname);
|
g_free(lname);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
each_contact_mutt_alias(const std::string& email,
|
each_contact_mutt_alias(const std::string& email,
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
GHashTable* nicks)
|
GHashTable* nicks)
|
||||||
{
|
{
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
return;
|
return;
|
||||||
@ -234,8 +232,8 @@ each_contact_mutt_alias(const std::string& email,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
each_contact_wl(const std::string& email,
|
each_contact_wl(const std::string& email,
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
GHashTable* nicks)
|
GHashTable* nicks)
|
||||||
{
|
{
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
return;
|
return;
|
||||||
@ -287,9 +285,9 @@ each_contact(const Mu::MessageContact& ci, ECData& ecdata)
|
|||||||
if (ecdata.rx &&
|
if (ecdata.rx &&
|
||||||
!g_regex_match(ecdata.rx, ci.email.c_str(), (GRegexMatchFlags)0, NULL) &&
|
!g_regex_match(ecdata.rx, ci.email.c_str(), (GRegexMatchFlags)0, NULL) &&
|
||||||
!g_regex_match(ecdata.rx,
|
!g_regex_match(ecdata.rx,
|
||||||
ci.name.empty() ? "" : ci.name.c_str(),
|
ci.name.empty() ? "" : ci.name.c_str(),
|
||||||
(GRegexMatchFlags)0,
|
(GRegexMatchFlags)0,
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
++ecdata.n;
|
++ecdata.n;
|
||||||
@ -305,26 +303,26 @@ each_contact(const Mu::MessageContact& ci, ECData& ecdata)
|
|||||||
case MU_CONFIG_FORMAT_ORG_CONTACT:
|
case MU_CONFIG_FORMAT_ORG_CONTACT:
|
||||||
if (!ci.name.empty())
|
if (!ci.name.empty())
|
||||||
mu_util_print_encoded("* %s\n:PROPERTIES:\n:EMAIL: %s\n:END:\n\n",
|
mu_util_print_encoded("* %s\n:PROPERTIES:\n:EMAIL: %s\n:END:\n\n",
|
||||||
ci.name.c_str(),
|
ci.name.c_str(),
|
||||||
ci.email.c_str());
|
ci.email.c_str());
|
||||||
break;
|
break;
|
||||||
case MU_CONFIG_FORMAT_BBDB: each_contact_bbdb(ci.email, ci.name, ci.message_date); break;
|
case MU_CONFIG_FORMAT_BBDB: each_contact_bbdb(ci.email, ci.name, ci.message_date); break;
|
||||||
case MU_CONFIG_FORMAT_CSV:
|
case MU_CONFIG_FORMAT_CSV:
|
||||||
mu_util_print_encoded("%s,%s\n",
|
mu_util_print_encoded("%s,%s\n",
|
||||||
ci.name.empty() ? "" : Mu::quote(ci.name).c_str(),
|
ci.name.empty() ? "" : Mu::quote(ci.name).c_str(),
|
||||||
Mu::quote(ci.email).c_str());
|
Mu::quote(ci.email).c_str());
|
||||||
break;
|
break;
|
||||||
case MU_CONFIG_FORMAT_DEBUG: {
|
case MU_CONFIG_FORMAT_DEBUG: {
|
||||||
char datebuf[32];
|
char datebuf[32];
|
||||||
strftime(datebuf, sizeof(datebuf), "%F %T", gmtime(&ci.message_date));
|
strftime(datebuf, sizeof(datebuf), "%F %T", gmtime(&ci.message_date));
|
||||||
g_print("%s\n\tname: %s\n\t%s\n\tpersonal: %s\n\tfreq: %zu\n"
|
g_print("%s\n\tname: %s\n\t%s\n\tpersonal: %s\n\tfreq: %zu\n"
|
||||||
"\tlast-seen: %s\n",
|
"\tlast-seen: %s\n",
|
||||||
ci.email.c_str(),
|
ci.email.c_str(),
|
||||||
ci.name.empty() ? "<none>" : ci.name.c_str(),
|
ci.name.empty() ? "<none>" : ci.name.c_str(),
|
||||||
ci.display_name().c_str(),
|
ci.display_name().c_str(),
|
||||||
ci.personal ? "yes" : "no",
|
ci.personal ? "yes" : "no",
|
||||||
ci.frequency,
|
ci.frequency,
|
||||||
datebuf);
|
datebuf);
|
||||||
} break;
|
} break;
|
||||||
default: print_plain(ci.email, ci.name, ecdata.color);
|
default: print_plain(ci.email, ci.name, ecdata.color);
|
||||||
}
|
}
|
||||||
@ -332,12 +330,12 @@ each_contact(const Mu::MessageContact& ci, ECData& ecdata)
|
|||||||
|
|
||||||
static MuError
|
static MuError
|
||||||
run_cmd_cfind(const Mu::Store& store,
|
run_cmd_cfind(const Mu::Store& store,
|
||||||
const char* pattern,
|
const char* pattern,
|
||||||
gboolean personal,
|
gboolean personal,
|
||||||
time_t after,
|
time_t after,
|
||||||
const MuConfigFormat format,
|
const MuConfigFormat format,
|
||||||
gboolean color,
|
gboolean color,
|
||||||
GError** err)
|
GError** err)
|
||||||
{
|
{
|
||||||
ECData ecdata{};
|
ECData ecdata{};
|
||||||
|
|
||||||
@ -392,7 +390,7 @@ cfind_params_valid(const MuConfig* opts)
|
|||||||
case MU_CONFIG_FORMAT_DEBUG: break;
|
case MU_CONFIG_FORMAT_DEBUG: break;
|
||||||
default:
|
default:
|
||||||
g_printerr("invalid output format %s\n",
|
g_printerr("invalid output format %s\n",
|
||||||
opts->formatstr ? opts->formatstr : "<none>");
|
opts->formatstr ? opts->formatstr : "<none>");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,20 +411,20 @@ Mu::mu_cmd_cfind(const Mu::Store& store, const MuConfig* opts, GError** err)
|
|||||||
|
|
||||||
if (!cfind_params_valid(opts))
|
if (!cfind_params_valid(opts))
|
||||||
throw Mu::Error(Mu::Error::Code::InvalidArgument,
|
throw Mu::Error(Mu::Error::Code::InvalidArgument,
|
||||||
"invalid parameters");
|
"invalid parameters");
|
||||||
|
|
||||||
auto res = run_cmd_cfind(store,
|
auto res = run_cmd_cfind(store,
|
||||||
opts->params[1],
|
opts->params[1],
|
||||||
opts->personal,
|
opts->personal,
|
||||||
opts->after,
|
opts->after,
|
||||||
opts->format,
|
opts->format,
|
||||||
!opts->nocolor,
|
!opts->nocolor,
|
||||||
err);
|
err);
|
||||||
|
|
||||||
if (res != MU_OK && res != MU_ERROR_NO_MATCHES)
|
if (res != MU_OK && res != MU_ERROR_NO_MATCHES)
|
||||||
throw Mu::Error(Mu::Error::Code::Internal,
|
throw Mu::Error(Mu::Error::Code::Internal,
|
||||||
err /*consumes*/,
|
err /*consumes*/,
|
||||||
"error in cfind");
|
"error in cfind");
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,9 +37,9 @@
|
|||||||
|
|
||||||
#include "utils/mu-util.h"
|
#include "utils/mu-util.h"
|
||||||
#include "utils/mu-str.h"
|
#include "utils/mu-str.h"
|
||||||
#include "utils/mu-date.h"
|
|
||||||
|
|
||||||
#include "mu-cmd.hh"
|
#include "mu-cmd.hh"
|
||||||
|
#include "utils/mu-utils.hh"
|
||||||
|
|
||||||
using namespace Mu;
|
using namespace Mu;
|
||||||
|
|
||||||
@ -58,10 +58,10 @@ using OutputFunc = std::function<bool(MuMsg*, const OutputInfo&, const MuConfig*
|
|||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
print_internal(const Store& store,
|
print_internal(const Store& store,
|
||||||
const std::string& expr,
|
const std::string& expr,
|
||||||
gboolean xapian,
|
gboolean xapian,
|
||||||
gboolean warn,
|
gboolean warn,
|
||||||
GError** err)
|
GError** err)
|
||||||
{
|
{
|
||||||
std::cout << store.parse_query(expr, xapian) << "\n";
|
std::cout << store.parse_query(expr, xapian) << "\n";
|
||||||
|
|
||||||
@ -81,10 +81,10 @@ sort_field_from_string(const char* fieldstr, GError** err)
|
|||||||
mfid = mu_msg_field_id_from_shortcut(fieldstr[0], FALSE);
|
mfid = mu_msg_field_id_from_shortcut(fieldstr[0], FALSE);
|
||||||
if (mfid == MU_MSG_FIELD_ID_NONE)
|
if (mfid == MU_MSG_FIELD_ID_NONE)
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
MU_ERROR_DOMAIN,
|
MU_ERROR_DOMAIN,
|
||||||
MU_ERROR_IN_PARAMETERS,
|
MU_ERROR_IN_PARAMETERS,
|
||||||
"not a valid sort field: '%s'\n",
|
"not a valid sort field: '%s'\n",
|
||||||
fieldstr);
|
fieldstr);
|
||||||
return mfid;
|
return mfid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,20 +142,20 @@ resolve_bookmark(const MuConfig* opts, GError** err)
|
|||||||
bm = mu_bookmarks_new(bmfile);
|
bm = mu_bookmarks_new(bmfile);
|
||||||
if (!bm) {
|
if (!bm) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
MU_ERROR_DOMAIN,
|
MU_ERROR_DOMAIN,
|
||||||
MU_ERROR_FILE_CANNOT_OPEN,
|
MU_ERROR_FILE_CANNOT_OPEN,
|
||||||
"failed to open bookmarks file '%s'",
|
"failed to open bookmarks file '%s'",
|
||||||
bmfile);
|
bmfile);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
val = (gchar*)mu_bookmarks_lookup(bm, opts->bookmark);
|
val = (gchar*)mu_bookmarks_lookup(bm, opts->bookmark);
|
||||||
if (!val)
|
if (!val)
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
MU_ERROR_DOMAIN,
|
MU_ERROR_DOMAIN,
|
||||||
MU_ERROR_NO_MATCHES,
|
MU_ERROR_NO_MATCHES,
|
||||||
"bookmark '%s' not found",
|
"bookmark '%s' not found",
|
||||||
opts->bookmark);
|
opts->bookmark);
|
||||||
else
|
else
|
||||||
val = g_strdup(val);
|
val = g_strdup(val);
|
||||||
|
|
||||||
@ -305,7 +305,7 @@ flags_s(MessageFlags flags)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char*
|
static std::string
|
||||||
display_field(MuMsg* msg, MuMsgFieldId mfid)
|
display_field(MuMsg* msg, MuMsgFieldId mfid)
|
||||||
{
|
{
|
||||||
gint64 val;
|
gint64 val;
|
||||||
@ -328,9 +328,8 @@ display_field(MuMsg* msg, MuMsgFieldId mfid)
|
|||||||
return mu_msg_get_field_string(msg, mfid);
|
return mu_msg_get_field_string(msg, mfid);
|
||||||
|
|
||||||
case MU_MSG_FIELD_TYPE_TIME_T:
|
case MU_MSG_FIELD_TYPE_TIME_T:
|
||||||
val = mu_msg_get_field_numeric(msg, mfid);
|
return time_to_string(
|
||||||
return mu_date_str_s("%c", (time_t)val);
|
"%c", static_cast<::time_t>(mu_msg_get_field_numeric(msg, mfid)));
|
||||||
|
|
||||||
case MU_MSG_FIELD_TYPE_BYTESIZE:
|
case MU_MSG_FIELD_TYPE_BYTESIZE:
|
||||||
val = mu_msg_get_field_numeric(msg, mfid);
|
val = mu_msg_get_field_numeric(msg, mfid);
|
||||||
return mu_str_size_s((unsigned)val);
|
return mu_str_size_s((unsigned)val);
|
||||||
@ -391,8 +390,8 @@ thread_indent(const QueryMatch& info, const MuConfig* opts)
|
|||||||
else
|
else
|
||||||
::fputs(" ", stdout);
|
::fputs(" ", stdout);
|
||||||
::fputs(empty_parent ? "*> " : is_dup ? "=> "
|
::fputs(empty_parent ? "*> " : is_dup ? "=> "
|
||||||
: "-> ",
|
: "-> ",
|
||||||
stdout);
|
stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,7 +413,8 @@ output_plain_fields(MuMsg* msg, const char* fields, gboolean color, gboolean thr
|
|||||||
|
|
||||||
else {
|
else {
|
||||||
ansi_color_maybe(mfid, color);
|
ansi_color_maybe(mfid, color);
|
||||||
nonempty += mu_util_fputs_encoded(display_field(msg, mfid), stdout);
|
nonempty += mu_util_fputs_encoded(display_field(msg, mfid).c_str(),
|
||||||
|
stdout);
|
||||||
ansi_reset_maybe(mfid, color);
|
ansi_reset_maybe(mfid, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -482,7 +482,7 @@ to_string(const Mu::Sexp& sexp, bool color, size_t level = 0)
|
|||||||
break;
|
break;
|
||||||
case Sexp::Type::Symbol:
|
case Sexp::Type::Symbol:
|
||||||
sstrm << (col.fg(sexp.value().at(0) == ':' ? Color::BrightGreen
|
sstrm << (col.fg(sexp.value().at(0) == ':' ? Color::BrightGreen
|
||||||
: Color::BrightBlue))
|
: Color::BrightBlue))
|
||||||
<< sexp.value() << col.reset();
|
<< sexp.value() << col.reset();
|
||||||
break;
|
break;
|
||||||
default: throw std::logic_error("invalid type");
|
default: throw std::logic_error("invalid type");
|
||||||
@ -517,8 +517,8 @@ output_json(MuMsg* msg, const OutputInfo& info, const MuConfig* opts, GError** e
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_print("%s%s\n",
|
g_print("%s%s\n",
|
||||||
msg_to_sexp(msg, info.docid, MU_MSG_OPTION_HEADERS_ONLY).to_json_string().c_str(),
|
msg_to_sexp(msg, info.docid, MU_MSG_OPTION_HEADERS_ONLY).to_json_string().c_str(),
|
||||||
info.last ? "" : ",");
|
info.last ? "" : ",");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -601,13 +601,13 @@ output_query_results(const QueryResults& qres, const MuConfig* opts, GError** er
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
rv = output_func(msg,
|
rv = output_func(msg,
|
||||||
{item.doc_id(),
|
{item.doc_id(),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
n == qres.size(), /* last? */
|
n == qres.size(), /* last? */
|
||||||
item.query_match()},
|
item.query_match()},
|
||||||
opts,
|
opts,
|
||||||
err);
|
err);
|
||||||
if (!rv)
|
if (!rv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -660,16 +660,16 @@ format_params_valid(const MuConfig* opts, GError** err)
|
|||||||
case MU_CONFIG_FORMAT_MQUERY:
|
case MU_CONFIG_FORMAT_MQUERY:
|
||||||
if (opts->exec) {
|
if (opts->exec) {
|
||||||
mu_util_g_set_error(err,
|
mu_util_g_set_error(err,
|
||||||
MU_ERROR_IN_PARAMETERS,
|
MU_ERROR_IN_PARAMETERS,
|
||||||
"--exec and --format cannot be combined");
|
"--exec and --format cannot be combined");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mu_util_g_set_error(err,
|
mu_util_g_set_error(err,
|
||||||
MU_ERROR_IN_PARAMETERS,
|
MU_ERROR_IN_PARAMETERS,
|
||||||
"invalid output format %s",
|
"invalid output format %s",
|
||||||
opts->formatstr ? opts->formatstr : "<none>");
|
opts->formatstr ? opts->formatstr : "<none>");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -680,8 +680,8 @@ format_params_valid(const MuConfig* opts, GError** err)
|
|||||||
|
|
||||||
if (opts->linksdir && opts->format != MU_CONFIG_FORMAT_LINKS) {
|
if (opts->linksdir && opts->format != MU_CONFIG_FORMAT_LINKS) {
|
||||||
mu_util_g_set_error(err,
|
mu_util_g_set_error(err,
|
||||||
MU_ERROR_IN_PARAMETERS,
|
MU_ERROR_IN_PARAMETERS,
|
||||||
"--linksdir is only valid with --format=links");
|
"--linksdir is only valid with --format=links");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -703,9 +703,9 @@ query_params_valid(const MuConfig* opts, GError** err)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
mu_util_g_set_error(err,
|
mu_util_g_set_error(err,
|
||||||
MU_ERROR_FILE_CANNOT_READ,
|
MU_ERROR_FILE_CANNOT_READ,
|
||||||
"'%s' is not a readable Xapian directory",
|
"'%s' is not a readable Xapian directory",
|
||||||
xpath);
|
xpath);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
#include "utils/mu-util.h"
|
#include "utils/mu-util.h"
|
||||||
#include "utils/mu-str.h"
|
#include "utils/mu-str.h"
|
||||||
#include "utils/mu-date.h"
|
|
||||||
|
|
||||||
#include "utils/mu-error.hh"
|
#include "utils/mu-error.hh"
|
||||||
|
|
||||||
@ -164,8 +163,10 @@ view_msg_plain(MuMsg* msg, const MuConfig* opts)
|
|||||||
print_field("Bcc", mu_msg_get_bcc(msg), color);
|
print_field("Bcc", mu_msg_get_bcc(msg), color);
|
||||||
print_field("Subject", mu_msg_get_subject(msg), color);
|
print_field("Subject", mu_msg_get_subject(msg), color);
|
||||||
|
|
||||||
if ((date = mu_msg_get_date(msg)))
|
if ((date = mu_msg_get_date(msg))) {
|
||||||
print_field("Date", mu_date_str_s("%c", date), color);
|
const auto dstr{time_to_string("%c", date)};
|
||||||
|
print_field("Date", dstr.c_str(), color);
|
||||||
|
}
|
||||||
|
|
||||||
if ((lst = mu_msg_get_tags(msg))) {
|
if ((lst = mu_msg_get_tags(msg))) {
|
||||||
gchar* tags;
|
gchar* tags;
|
||||||
|
|||||||
Reference in New Issue
Block a user