mirror of https://github.com/djcb/mu.git
* fix CSV quoting (fields with commas)
This commit is contained in:
parent
f4d3eb2d7a
commit
c50c0695e4
|
@ -456,7 +456,7 @@ mu_util_fputs_encoded (const char *str, FILE *stream)
|
||||||
if (!conv || err) {
|
if (!conv || err) {
|
||||||
/* conversion failed; this happens because is
|
/* conversion failed; this happens because is
|
||||||
* some cases GMime may gives us non-UTF-8
|
* some cases GMime may gives us non-UTF-8
|
||||||
* string from e.g. wrongly encoded
|
* strings from e.g. wrongly encoded
|
||||||
* message-subjects; if so, we escape the
|
* message-subjects; if so, we escape the
|
||||||
* string */
|
* string */
|
||||||
g_warning ("%s: g_locale_from_utf8 failed: %s",
|
g_warning ("%s: g_locale_from_utf8 failed: %s",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.TH MU CFIND 1 "October 2012" "User Manuals"
|
.TH MU CFIND 1 "May 2013" "User Manuals"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
|
|
||||||
|
@ -43,7 +43,8 @@ list of contacts. Note, \fBmu cfind\fR uses does not directly use the
|
||||||
database, but uses a cache file with e-mail addresses, which is populated
|
database, but uses a cache file with e-mail addresses, which is populated
|
||||||
during the indexing process.
|
during the indexing process.
|
||||||
|
|
||||||
The regular expressions are Perl-compatible (as per the PCRE-library).
|
The regular expressions are Perl-compatible (as per the PCRE-library used by
|
||||||
|
GRegex).
|
||||||
|
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
|
|
||||||
|
@ -60,9 +61,15 @@ sets the output format to the given value. The following are available:
|
||||||
| wl | wanderlust addressbook format |
|
| wl | wanderlust addressbook format |
|
||||||
| org-contact | org-mode org-contact format |
|
| org-contact | org-mode org-contact format |
|
||||||
| bbdb | BBDB format |
|
| bbdb | BBDB format |
|
||||||
| csv | comma-separated values |
|
| csv | comma-separated values (*) |
|
||||||
.fi
|
.fi
|
||||||
|
|
||||||
|
|
||||||
|
(*) CSV is not really standardized, but \fBmu cfind\fR follows some common
|
||||||
|
practices: any double-quote is replaced by a double-double quote (thus,
|
||||||
|
"hello" become ""hello"", and fields with commas are put in
|
||||||
|
double-quotes. Normally, this should only apply to name fields.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-personal\fR only show addresses seen in messages where one of 'my'
|
\fB\-\-personal\fR only show addresses seen in messages where one of 'my'
|
||||||
e-mail addresses was seen in one of the address fields; this is to exclude
|
e-mail addresses was seen in one of the address fields; this is to exclude
|
||||||
|
|
|
@ -231,6 +231,38 @@ each_contact_org_contact (const char *email, const char *name)
|
||||||
name, email);
|
name, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_csv_field (const char *str)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return;
|
||||||
|
|
||||||
|
s = mu_str_replace (str, "\"", "\"\"");
|
||||||
|
if (strchr (s, ','))
|
||||||
|
mu_util_print_encoded ("\"%s\"", s);
|
||||||
|
else
|
||||||
|
mu_util_print_encoded ("%s", s);
|
||||||
|
|
||||||
|
g_free (s);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
each_contact_csv (const char *email, const char *name)
|
||||||
|
{
|
||||||
|
print_csv_field (name);
|
||||||
|
mu_util_print_encoded (",");
|
||||||
|
print_csv_field (email);
|
||||||
|
mu_util_print_encoded ("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_plain (const char *email, const char *name, gboolean color)
|
print_plain (const char *email, const char *name, gboolean color)
|
||||||
{
|
{
|
||||||
|
@ -259,6 +291,7 @@ struct _ECData {
|
||||||
typedef struct _ECData ECData;
|
typedef struct _ECData ECData;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
each_contact (const char *email, const char *name, gboolean personal,
|
each_contact (const char *email, const char *name, gboolean personal,
|
||||||
time_t tstamp, ECData *ecdata)
|
time_t tstamp, ECData *ecdata)
|
||||||
|
@ -287,7 +320,7 @@ each_contact (const char *email, const char *name, gboolean personal,
|
||||||
each_contact_bbdb (email, name, tstamp);
|
each_contact_bbdb (email, name, tstamp);
|
||||||
break;
|
break;
|
||||||
case MU_CONFIG_FORMAT_CSV:
|
case MU_CONFIG_FORMAT_CSV:
|
||||||
mu_util_print_encoded ("%s,%s\n", name ? name : "", email);
|
each_contact_csv (email, name);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
print_plain (email, name, ecdata->color);
|
print_plain (email, name, ecdata->color);
|
||||||
|
|
Loading…
Reference in New Issue