aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordequis <dx@dxzone.com.ar>2015-05-08 01:16:37 -0300
committerdequis <dx@dxzone.com.ar>2015-05-28 02:26:30 -0300
commit0864a524c9fd1184874d550216beb49f6a0bef55 (patch)
treea2a19d6787dd8b7b479fa43378994233aad839e1
parentfaeb521e66d825e68eb7f9eef8f32ddabbfd9c49 (diff)
imcb_notify_email: change parameters to take a format string
Saves some messing with g_strdup_printf for the callers, and flags/sent_at weren't used anyway. Also check if the mail_notifications setting is enabled
-rw-r--r--protocols/bee.h3
-rw-r--r--protocols/bee_user.c21
-rw-r--r--protocols/jabber/iq.c6
-rw-r--r--protocols/msn/ns.c9
-rw-r--r--protocols/purple/purple.c4
-rw-r--r--protocols/yahoo/yahoo.c14
6 files changed, 28 insertions, 29 deletions
diff --git a/protocols/bee.h b/protocols/bee.h
index 1d87f743..afe22c95 100644
--- a/protocols/bee.h
+++ b/protocols/bee.h
@@ -155,8 +155,7 @@ G_MODULE_EXPORT void imcb_buddy_times(struct im_connection *ic, const char *hand
/* Call when a handle says something. 'flags' and 'sent_at may be just 0. */
G_MODULE_EXPORT void imcb_buddy_msg(struct im_connection *ic, const char *handle, const char *msg, guint32 flags,
time_t sent_at);
-G_MODULE_EXPORT void imcb_notify_email(struct im_connection *ic, const char *handle, char *msg, guint32 flags,
- time_t sent_at);
+G_MODULE_EXPORT void imcb_notify_email(struct im_connection *ic, char *format, ...) G_GNUC_PRINTF(2, 3);
/* bee_chat.c */
/* These two functions are to create a group chat.
diff --git a/protocols/bee_user.c b/protocols/bee_user.c
index 562b31b3..3088de5c 100644
--- a/protocols/bee_user.c
+++ b/protocols/bee_user.c
@@ -270,13 +270,30 @@ void imcb_buddy_msg(struct im_connection *ic, const char *handle, const char *ms
}
}
-void imcb_notify_email(struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at)
+void imcb_notify_email(struct im_connection *ic, char *format, ...)
{
+ const char *handle;
+ va_list params;
+ char *msg;
+
+ if (!set_getbool(&ic->acc->set, "mail_notifications")) {
+ return;
+ }
+
+ va_start(params, format);
+ msg = g_strdup_vprintf(format, params);
+ va_end(params);
+
+ /* up to the protocol to set_add this if they want to use this */
+ handle = set_getstr(&ic->acc->set, "notify_handle");
+
if (handle != NULL) {
- imcb_buddy_msg(ic, handle, msg, flags, sent_at);
+ imcb_buddy_msg(ic, handle, msg, 0, 0);
} else {
imcb_log(ic, "%s", msg);
}
+
+ g_free(msg);
}
void imcb_buddy_typing(struct im_connection *ic, const char *handle, uint32_t flags)
diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c
index 3e1a5dfd..1a915e4a 100644
--- a/protocols/jabber/iq.c
+++ b/protocols/jabber/iq.c
@@ -809,7 +809,6 @@ xt_status jabber_iq_parse_gmail(struct im_connection *ic, struct xt_node *node,
struct xt_node *s;
char *subject = "<no subject>";
char *sender = "<no sender>";
- char *msg = NULL;
guint64 t_time;
t_time = g_ascii_strtoull(xt_find_attr(c, "date"), NULL, 10);
@@ -827,12 +826,9 @@ xt_status jabber_iq_parse_gmail(struct im_connection *ic, struct xt_node *node,
subject = s->text;
}
- msg = g_strdup_printf("New mail from %s: %s", sender, subject);
-
- imcb_notify_email(ic, set_getstr(&ic->acc->set, "notify_handle"), msg, 0, 0);
+ imcb_notify_email(ic, "New mail from %s: %s", sender, subject);
c = c->next;
- g_free(msg);
}
if (l_time && (!jd->gmail_time || l_time > jd->gmail_time)) {
diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c
index 130f1c91..766c31e1 100644
--- a/protocols/msn/ns.c
+++ b/protocols/msn/ns.c
@@ -393,11 +393,9 @@ int msn_ns_message(struct msn_data *md, char *msg, int msglen, char **cmd, int n
char *folders = get_rfc822_header(body, "Folders-Unread:", blen);
if (inbox && folders) {
- char *msg = g_strdup_printf(
+ imcb_notify_email(ic,
"INBOX contains %s new messages, plus %s messages in other folders.", inbox,
folders);
- imcb_notify_email(ic, set_getstr(&ic->acc->set, "notify_handle"), msg, 0, 0);
- g_free(msg);
}
g_free(inbox);
@@ -409,10 +407,7 @@ int msn_ns_message(struct msn_data *md, char *msg, int msglen, char **cmd, int n
char *fromname = get_rfc822_header(body, "From:", blen);
if (from && fromname) {
- char *msg = g_strdup_printf("Received an e-mail message from %s <%s>.",
- fromname, from);
- imcb_notify_email(ic, set_getstr(&ic->acc->set, "notify_handle"), msg, 0, 0);
- g_free(msg);
+ imcb_notify_email(ic, "Received an e-mail message from %s <%s>.", fromname, from);
}
g_free(from);
diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c
index 42a5448c..ab958891 100644
--- a/protocols/purple/purple.c
+++ b/protocols/purple/purple.c
@@ -1260,10 +1260,8 @@ static void *prplcb_notify_email(PurpleConnection *gc, const char *subject, cons
const char *to, const char *url)
{
struct im_connection *ic = purple_ic_by_gc(gc);
- char *msg = g_strdup_printf("Received e-mail from %s for %s: %s <%s>", from, to, subject, url);
- imcb_notify_email(ic, set_getstr(&ic->acc->set, "notify_handle"), msg, 0, 0);
- g_free(msg);
+ imcb_notify_email(ic, "Received e-mail from %s for %s: %s <%s>", from, to, subject, url);
return NULL;
}
diff --git a/protocols/yahoo/yahoo.c b/protocols/yahoo/yahoo.c
index 2e7c4831..2df454f3 100644
--- a/protocols/yahoo/yahoo.c
+++ b/protocols/yahoo/yahoo.c
@@ -958,17 +958,11 @@ void ext_yahoo_game_notify(int id, const char *me, const char *who, int stat, co
void ext_yahoo_mail_notify(int id, const char *from, const char *subj, int cnt)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
- char *msg;
- if (set_getbool(&ic->acc->set, "mail_notifications")) {
- if (from && subj) {
- msg = g_strdup_printf("Received e-mail message from %s with subject `%s'", from, subj);
- } else if (cnt > 0) {
- msg = g_strdup_printf("Received %d new e-mails", cnt);
- }
-
- imcb_notify_email(ic, set_getstr(&ic->acc->set, "notify_handle"), msg, 0, 0);
- g_free(msg);
+ if (from && subj) {
+ imcb_notify_email(ic, "Received e-mail message from %s with subject `%s'", from, subj);
+ } else if (cnt > 0) {
+ imcb_notify_email(ic, "Received %d new e-mails", cnt);
}
}