Esempio n. 1
0
const char*
mu_date_interpret_s (const char *datespec, gboolean is_begin)
{
	static char fulldate[14 + 1];
	time_t now, t;

	g_return_val_if_fail (datespec, NULL);

	if (mu_str_is_empty (datespec) && is_begin)
		return "000000000000"; /* beginning of time*/

	now = time(NULL);
	if (strcmp (datespec, "today") == 0) {
		strftime(fulldate, sizeof(fulldate),
			 is_begin ? "%Y%m%d000000" : "%Y%m%d235959",
			 localtime(&now));
		return fulldate;
	}

	if (mu_str_is_empty (datespec) || strcmp (datespec, "now") == 0) {
		strftime(fulldate, sizeof(fulldate), "%Y%m%d%H%M%S",
			 localtime(&now));
		return fulldate;
	}

	t = mu_date_parse_hdwmy (datespec);
	if (t != (time_t)-1) {
		strftime(fulldate, sizeof(fulldate), "%Y%m%d%H%M%S",
			 localtime(&t));
		return fulldate;
	}

	return datespec; /* nothing changed */
}
Esempio n. 2
0
static GHashTable*
read_command_line (GError **err)
{
	char		*line;
	GHashTable	*hash;
	GString		*gstr;

	line = NULL;
	gstr = g_string_sized_new (512);

	fputs (";; mu> ", stdout);

	do {
		int kar;

		kar = fgetc (stdin);
		if (kar == '\n' || kar == EOF)
			break;
		else
			gstr = g_string_append_c (gstr, (char)kar);

	} while (1);

	line = g_string_free (gstr, FALSE);

	if (!mu_str_is_empty (line))
		hash = mu_str_parse_arglist (line, err);
	else
		hash = NULL;

	g_free (line);

	return hash;
}
Esempio n. 3
0
gboolean
mu_contacts_add (MuContacts *self, const char *email, const char* name,
		 time_t tstamp)
{
	ContactInfo *cinfo;
	const char* group;

	g_return_val_if_fail (self, FALSE);
	g_return_val_if_fail (email, FALSE);

	/* add the info, if either there is no info for this email
	 * yet, *OR* the new one is more recent and does not have an
	 * empty name */
	group = encode_email_address (email);

	cinfo = (ContactInfo*) g_hash_table_lookup (self->_hash, group);
	if (!cinfo || (cinfo->_tstamp < tstamp && !mu_str_is_empty(name))) {
		ContactInfo *ci;
		ci = contact_info_new (g_strdup(email),
				       name ? g_strdup(name) : NULL,
				       tstamp);

		g_hash_table_insert (self->_hash, g_strdup(group), ci);

		return self->_dirty = TRUE;
	}

	return FALSE;
}
Esempio n. 4
0
static void
print_attr_xml (const char* elm, const char *str)
{
	gchar *esc;

	if (mu_str_is_empty(str))
		return; /* empty: don't include */

	esc = g_markup_escape_text (str, -1);
	g_print ("\t\t<%s>%s</%s>\n", elm, esc, elm);
	g_free (esc);
}
Esempio n. 5
0
gboolean
mu_contacts_add (MuContacts *self, const char *addr, const char *name,
		 gboolean personal, time_t tstamp)
{
	ContactInfo *cinfo;
	const char *group;

	g_return_val_if_fail (self, FALSE);
	g_return_val_if_fail (addr, FALSE);

	group	= encode_email_address (addr);

	cinfo = (ContactInfo*) g_hash_table_lookup (self->_hash, group);
	if (!cinfo) {
		char *addr_dc;
		if (!(addr_dc = downcase_domain_maybe (addr)))
			return FALSE;
		cinfo = contact_info_new (addr_dc,
					  name ? g_strdup(name) : NULL, personal,
					  tstamp, 1);
		g_hash_table_insert (self->_hash, g_strdup(group), cinfo);
	} else {
		if (cinfo->_tstamp < tstamp) {
			if (!mu_str_is_empty(name)) {
				/* update the name to the last one used, unless it's
				 * empty*/
				g_free (cinfo->_name);
				cinfo->_name = g_strdup (name);
				if (cinfo->_name)
					mu_str_remove_ctrl_in_place (cinfo->_name);
			}
			cinfo->_tstamp = tstamp;
		}
		++cinfo->_freq;
	}


	self->_dirty = TRUE;

	return TRUE;
}
Esempio n. 6
0
static MuError
handle_args (ServerContext *ctx, GSList *args, GError **err)
{
	unsigned u;
	const char *cmd;
	struct {
		const char *cmd;
		CmdFunc func;
	} cmd_map[] = {
		{ "add",	cmd_add },
		{ "compose",	cmd_compose },
		{ "contacts",   cmd_contacts },
		{ "extract",    cmd_extract },
		{ "find",	cmd_find },
		{ "guile",      cmd_guile },
		{ "index",	cmd_index },
		{ "mkdir",	cmd_mkdir },
		{ "move",	cmd_move },
		{ "ping",	cmd_ping },
		{ "quit",	cmd_quit },
		{ "remove",	cmd_remove },
		{ "sent",	cmd_sent },
		{ "view",	cmd_view }
	};

	cmd = (const char*) args->data;

	/* ignore empty */
	if (mu_str_is_empty (cmd))
		return MU_OK;

	for (u = 0; u != G_N_ELEMENTS (cmd_map); ++u)
		if (g_strcmp0(cmd, cmd_map[u].cmd) == 0)
			return cmd_map[u].func (ctx, g_slist_next(args), err);

	mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
			     "unknown command '%s'", cmd ? cmd : "");

	return MU_G_ERROR_CODE (err);
}