Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote branch 'origin/narrow-cc'

  • Loading branch information...
commit 89ab5c8a8d353399621239293ec15edf3d25e313 2 parents aa0a0b5 + ecaec21
@nelhage authored
Showing with 95 additions and 34 deletions.
  1. +32 −0 functions.c
  2. +20 −21 logging.c
  3. +43 −13 message.c
View
32 functions.c
@@ -2500,6 +2500,34 @@ void owl_function_delete_curview_msgs(int flag)
owl_mainwin_redisplay(owl_global_get_mainwin(&g));
}
+static char *owl_function_smartfilter_cc(const owl_message *m) {
+ const char *ccs;
+ char *filtname;
+ char *text;
+ owl_filter *f;
+
+ ccs = owl_message_get_attribute_value(m, "zephyr_ccs");
+
+ filtname = owl_sprintf("conversation-%s", ccs);
+ owl_text_tr(filtname, ' ', '-');
+
+ if (owl_global_get_filter(&g, filtname)) {
+ return filtname;
+ }
+
+ text = owl_sprintf("type ^zephyr$ and filter personal and "
+ "zephyr_ccs ^%s%s%s$",
+ owl_getquoting(ccs), ccs, owl_getquoting(ccs));
+
+ f = owl_filter_new_fromstring(filtname, text);
+
+ owl_global_add_filter(&g, f);
+
+ owl_free(text);
+
+ return filtname;
+}
+
/* Create a filter based on the current message. Returns the name of
* a filter or null. The caller must free this name.
*
@@ -2553,6 +2581,10 @@ char *owl_function_smartfilter(int type, int invert_related)
/* narrow personal and login messages to the sender or recip as appropriate */
if (owl_message_is_type_zephyr(m)) {
if (owl_message_is_personal(m) || owl_message_is_loginout(m)) {
+ if (owl_message_get_attribute_value(m, "zephyr_ccs") != NULL) {
+ return owl_function_smartfilter_cc(m);
+ }
+
if (owl_message_is_direction_in(m)) {
zperson=short_zuser(owl_message_get_sender(m));
} else {
View
41 logging.c
@@ -127,6 +127,7 @@ 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));
@@ -134,17 +135,16 @@ void owl_log_outgoing(const owl_message *m)
/* 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
56 message.c
@@ -592,40 +592,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);
}
@@ -742,6 +733,41 @@ void owl_message_create_loopback(owl_message *m, const char *text)
owl_message_set_isprivate(m);
}
+void owl_message_save_ccs(owl_message *m) {
+ GList *cc;
+ char *tmp;
+
+ cc = owl_message_get_cc_without_recipient(m);
+
+ if (cc != NULL) {
+ GString *recips = g_string_new("");
+ cc = g_list_prepend(cc, short_zuser(owl_message_get_sender(m)));
+ cc = g_list_prepend(cc, short_zuser(owl_message_get_recipient(m)));
+ cc = g_list_sort(cc, (GCompareFunc)strcasecmp);
+
+ while(cc != NULL) {
+ /* Collapse any identical entries */
+ while (cc->next && strcasecmp(cc->data, cc->next->data) == 0) {
+ owl_free(cc->data);
+ cc = g_list_delete_link(cc, cc);
+ }
+
+ tmp = short_zuser(cc->data);
+ g_string_append(recips, tmp);
+
+ owl_free(tmp);
+ owl_free(cc->data);
+ cc = g_list_delete_link(cc, cc);
+
+ if (cc)
+ g_string_append_c(recips, ' ');
+ }
+
+ owl_message_set_attribute(m, "zephyr_ccs", recips->str);
+ g_string_free(recips, true);
+ }
+}
+
#ifdef HAVE_LIBZEPHYR
void owl_message_create_from_znotice(owl_message *m, const ZNotice_t *n)
{
@@ -877,6 +903,8 @@ void owl_message_create_from_znotice(owl_message *m, const ZNotice_t *n)
owl_free(out);
}
}
+
+ owl_message_save_ccs(m);
}
#else
void owl_message_create_from_znotice(owl_message *m, const void *n)
@@ -971,6 +999,8 @@ void owl_message_create_from_zwrite(owl_message *m, const owl_zwrite *z, const c
if (owl_zwrite_is_personal(z)) {
owl_message_set_isprivate(m);
}
+
+ owl_message_save_ccs(m);
}
void owl_message_cleanup(owl_message *m)
Please sign in to comment.
Something went wrong with that request. Please try again.