Permalink
Browse files

Make owl_message_get_cc_without_recipient return a GList.

Signed-off-by: Nelson Elhage <nelhage@mit.edu>
  • Loading branch information...
1 parent a41c8d1 commit 839697d886ff0c8987d4f6233e92a81a5157faed @nelhage committed May 8, 2010
Showing with 24 additions and 34 deletions.
  1. +20 −21 logging.c
  2. +4 −13 message.c
View
@@ -127,24 +127,24 @@ void owl_log_outgoing(const owl_message *m)
{
char filename[MAXPATHLEN], *logpath;
char *to, *temp;
+ GList *cc;
/* expand ~ in path names */
logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g));
/* Figure out what path to log to */
if (owl_message_is_type_zephyr(m)) {
/* If this has CC's, do all but the "recipient" which we'll do below */
- to = owl_message_get_cc_without_recipient(m);
- if (to != NULL) {
- temp = strtok(to, " ");
- while (temp != NULL) {
- temp = short_zuser(temp);
- snprintf(filename, MAXPATHLEN, "%s/%s", logpath, temp);
- owl_log_append(m, filename);
- temp = strtok(NULL, " ");
- }
- owl_free(to);
+ cc = owl_message_get_cc_without_recipient(m);
+ while (cc != NULL) {
+ temp = short_zuser(cc->data);
+ snprintf(filename, MAXPATHLEN, "%s/%s", logpath, temp);
+ owl_log_append(m, filename);
+
+ owl_free(cc->data);
+ cc = g_list_delete_link(cc, cc);
}
+
to = short_zuser(owl_message_get_recipient(m));
} else if (owl_message_is_type_jabber(m)) {
to = owl_sprintf("jabber:%s", owl_message_get_recipient(m));
@@ -324,19 +324,18 @@ void owl_log_incoming(const owl_message *m)
/* We want to log to all of the CC'd people who were not us, or
* the sender, as well.
*/
- char *cc, *temp;
+ char *temp;
+ GList *cc;
cc = owl_message_get_cc_without_recipient(m);
- if (cc != NULL) {
- temp = strtok(cc, " ");
- while (temp != NULL) {
- temp = short_zuser(temp);
- if (strcasecmp(temp, frombuff) != 0) {
- snprintf(filename, MAXPATHLEN, "%s/%s", logpath, temp);
- owl_log_append(m, filename);
- }
- temp = strtok(NULL, " ");
+ while (cc != NULL) {
+ temp = short_zuser(cc->data);
+ if (strcasecmp(temp, frombuff) != 0) {
+ snprintf(filename, MAXPATHLEN, "%s/%s", logpath, temp);
+ owl_log_append(m, filename);
}
- owl_free(cc);
+
+ owl_free(cc->data);
+ cc = g_list_delete_link(cc, cc);
}
}
View
@@ -583,40 +583,31 @@ char *owl_message_get_cc(const owl_message *m)
}
/* caller must free return value */
-char *owl_message_get_cc_without_recipient(const owl_message *m)
+GList *owl_message_get_cc_without_recipient(const owl_message *m)
{
- char *cc, *out, *end, *shortuser, *recip;
+ char *cc, *shortuser, *recip;
const char *user;
+ GList *out = NULL;
cc = owl_message_get_cc(m);
if (cc == NULL)
return NULL;
recip = short_zuser(owl_message_get_recipient(m));
- out = owl_malloc(strlen(cc) + 2);
- end = out;
user = strtok(cc, " ");
while (user != NULL) {
shortuser = short_zuser(user);
if (strcasecmp(shortuser, recip) != 0) {
- strcpy(end, user);
- end[strlen(user)] = ' ';
- end += strlen(user) + 1;
+ out = g_list_prepend(out, owl_strdup(user));
}
owl_free(shortuser);
user = strtok(NULL, " ");
}
- end[0] = '\0';
owl_free(recip);
owl_free(cc);
- if (strlen(out) == 0) {
- owl_free(out);
- out = NULL;
- }
-
return(out);
}

0 comments on commit 839697d

Please sign in to comment.