update for lib/utils split

Update sources with the new paths
This commit is contained in:
Dirk-Jan C. Binnema
2019-12-16 21:44:35 +02:00
parent e5337e7658
commit b55e191421
44 changed files with 237 additions and 261 deletions

View File

@ -31,8 +31,6 @@
#include "mu-util.h" /* PATH_MAX */
#include "mu-str.h"
#include "mu-msg-fields.h"
const char*
mu_str_size_s (size_t s)
@ -54,17 +52,6 @@ mu_str_size (size_t s)
return g_strdup (mu_str_size_s(s));
}
const char*
mu_str_flags_s (MuFlags flags)
{
return mu_flags_to_str_s (flags, MU_FLAG_TYPE_ANY);
}
char*
mu_str_flags (MuFlags flags)
{
return g_strdup (mu_str_flags_s(flags));
}
char*
mu_str_summarize (const char* str, size_t max_lines)
@ -108,60 +95,6 @@ mu_str_summarize (const char* str, size_t max_lines)
}
static void
cleanup_contact (char *contact)
{
char *c, *c2;
/* replace "'<> with space */
for (c2 = contact; *c2; ++c2)
if (*c2 == '"' || *c2 == '\'' || *c2 == '<' || *c2 == '>')
*c2 = ' ';
/* remove everything between '()' if it's after the 5th pos;
* good to cleanup corporate contact address spam... */
c = g_strstr_len (contact, -1, "(");
if (c && c - contact > 5)
*c = '\0';
g_strstrip (contact);
}
/* this is still somewhat simplistic... */
const char*
mu_str_display_contact_s (const char *str)
{
static gchar contact[255];
gchar *c, *c2;
str = str ? str : "";
g_strlcpy (contact, str, sizeof(contact));
/* we check for '<', so we can strip out the address stuff in
* e.g. 'Hello World <hello@world.xx>, but only if there is
* something alphanumeric before the <
*/
c = g_strstr_len (contact, -1, "<");
if (c != NULL) {
for (c2 = contact; c2 < c && !(isalnum(*c2)); ++c2);
if (c2 != c) /* apparently, there was something,
* so we can remove the <... part*/
*c = '\0';
}
cleanup_contact (contact);
return contact;
}
char*
mu_str_display_contact (const char *str)
{
g_return_val_if_fail (str, NULL);
return g_strdup (mu_str_display_contact_s (str));
}
char*

View File

@ -22,12 +22,10 @@
#ifndef __MU_STR_H__
#define __MU_STR_H__
#include <glib.h>
#include <time.h>
#include <sys/types.h>
#include <mu-msg.h>
#include <mu-flags.h>
G_BEGIN_DECLS
/**
@ -36,28 +34,6 @@ G_BEGIN_DECLS
* @{
*/
/**
* create a 'display contact' from an email header To/Cc/Bcc/From-type address
* ie., turn
* "Foo Bar" <foo@bar.com>
* into
* Foo Bar
* Note that this is based on some simple heuristics. Max length is 255 bytes.
*
* mu_str_display_contact_s returns a statically allocated
* buffer (ie, non-reentrant), while mu_str_display_contact
* returns a newly allocated string that you must free with g_free
* when done with it.
*
* @param str a 'contact str' (ie., what is in the To/Cc/Bcc/From
* fields), or NULL
*
* @return a newly allocated string with a display contact
*/
const char* mu_str_display_contact_s (const char *str) G_GNUC_CONST;
char *mu_str_display_contact (const char *str) G_GNUC_WARN_UNUSED_RESULT;
/**
* get a display size for a given size_t; uses M for sizes >
* 1000*1000, k for smaller sizes. Note: this function use the
@ -88,25 +64,6 @@ char* mu_str_size (size_t s) G_GNUC_WARN_UNUSED_RESULT;
char *mu_str_replace (const char *str, const char *substr, const char *repl);
/**
* get a display string for a given set of flags, OR'ed in
* @param flags; one character per flag:
* D=draft,F=flagged,N=new,P=passed,R=replied,S=seen,T=trashed
* a=has-attachment,s=signed, x=encrypted
*
* mu_str_file_flags_s returns a ptr to a static buffer,
* while mu_str_file_flags returns dynamically allocated
* memory that must be freed after use.
*
* @param flags file flags
*
* @return a string representation of the flags; see above
* for what to do with it
*/
const char* mu_str_flags_s (MuFlags flags) G_GNUC_CONST;
char* mu_str_flags (MuFlags flags)
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
/**
* get a 'summary' of the string, ie. the first /n/ lines of the
* strings, with all newlines removed, replaced by single spaces

View File

@ -30,11 +30,7 @@
#include <locale.h>
#include "test-mu-common.h"
#include "mu-str.h"
#include "mu-msg-prio.h"
static void
@ -76,34 +72,6 @@ test_mu_str_size_02 (void)
static void
test_mu_str_prio_01 (void)
{
g_assert_cmpstr(mu_msg_prio_name(MU_MSG_PRIO_LOW), ==, "low");
g_assert_cmpstr(mu_msg_prio_name(MU_MSG_PRIO_NORMAL), ==, "normal");
g_assert_cmpstr(mu_msg_prio_name(MU_MSG_PRIO_HIGH), ==, "high");
}
static gboolean
ignore_error (const char* log_domain, GLogLevelFlags log_level,
const gchar* msg, gpointer user_data)
{
return FALSE; /* don't abort */
}
static void
test_mu_str_prio_02 (void)
{
/* this must fail */
g_test_log_set_fatal_handler ((GTestLogFatalFunc)ignore_error, NULL);
g_assert_cmpstr (mu_msg_prio_name(666), ==, NULL);
}
static void
test_parse_arglist (void)
{
@ -158,25 +126,6 @@ test_mu_str_esc_to_list (void)
}
static void
test_mu_str_display_contact (void)
{
int i;
struct {
const char* word;
const char* disp;
} words [] = {
{ "\"Foo Bar\" <aap@noot.mies>", "Foo Bar"},
{ "Foo Bar <aap@noot.mies>", "Foo Bar" },
{ "<aap@noot.mies>", "aap@noot.mies" },
{ "foo@bar.nl", "foo@bar.nl" }
};
for (i = 0; i != G_N_ELEMENTS(words); ++i)
g_assert_cmpstr (mu_str_display_contact_s (words[i].word), ==,
words[i].disp);
}
static void
assert_cmplst (GSList *lst, const char *items[])
@ -333,16 +282,6 @@ main (int argc, char *argv[])
g_test_add_func ("/mu-str/mu-str-size-02",
test_mu_str_size_02);
/* mu_str_prio */
g_test_add_func ("/mu-str/mu-str-prio-01",
test_mu_str_prio_01);
g_test_add_func ("/mu-str/mu-str-prio-02",
test_mu_str_prio_02);
g_test_add_func ("/mu-str/mu-str-display_contact",
test_mu_str_display_contact);
g_test_add_func ("/mu-str/mu-str-from-list",
test_mu_str_from_list);
g_test_add_func ("/mu-str/mu-str-to-list",
@ -362,13 +301,6 @@ main (int argc, char *argv[])
g_test_add_func ("/mu-str/mu_str_remove_ctrl_in_place",
test_mu_str_remove_ctrl_in_place);
/* FIXME: add tests for mu_str_flags; but note the
* function simply calls mu_msg_field_str */
g_log_set_handler (NULL,
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL|
G_LOG_FLAG_RECURSION,
(GLogFunc)black_hole, NULL);
return g_test_run ();
}

View File

@ -28,8 +28,7 @@
#include <unistd.h>
#include <limits.h>
#include "test-mu-common.h"
#include "lib/mu-util.h"
#include "mu-util.h"
static void
test_mu_util_dir_expand_00 (void)
@ -245,11 +244,5 @@ main (int argc, char *argv[])
g_test_add_func ("/mu-util/mu-util-program-in-path",
test_mu_util_program_in_path);
g_log_set_handler (NULL,
G_LOG_LEVEL_DEBUG|
G_LOG_LEVEL_MESSAGE|
G_LOG_LEVEL_INFO, (GLogFunc)black_hole, NULL);
return g_test_run ();
}