[2968] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH 1/2] When you zephyr multiple people without using -C, show one outgoing message per recipient.

daemon@ATHENA.MIT.EDU (David Benjamin)
Fri Mar 11 18:20:58 2011

From: David Benjamin <davidben@MIT.EDU>
To: barnowl-dev@mit.edu
Cc: "liudi@MIT.EDU" <liudi@mit.edu>
Date: Fri, 11 Mar 2011 18:20:52 -0500

From: liudi@MIT.EDU <liudi@MIT.EDU>

Fixes bug #63.

[davidben@mit.edu: Fix up comment, rebase to master]
---

Okay, this patch has been sitting around doing nothing for /far/ too long. I've
rebased it and added a second patch to handle the other half of bug #63.

David


 functions.c |   52 ++++++++++++++++++++++++----------------------------
 logging.c   |    3 ++-
 message.c   |    9 ++++-----
 zephyr.c    |    4 +---
 4 files changed, 31 insertions(+), 37 deletions(-)

diff --git a/functions.c b/functions.c
index 2863f65..eed8a64 100644
--- a/functions.c
+++ b/functions.c
@@ -247,25 +247,34 @@ void owl_function_adminmsg(const char *header, const char *body)
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
 }
 
-/* Create an outgoing zephyr message and return a pointer to it.  Does
- * not put it on the global queue, use owl_global_messagequeue_addmsg() for
- * that.
+/* Queues outgoing zephyrs; if z sends to n people, queue n messages
+ * (except in case of cc). If there are no recipients queues 1
+ * message.
  */
-owl_message *owl_function_make_outgoing_zephyr(const owl_zwrite *z)
+void owl_function_add_outgoing_zephyrs(const owl_zwrite *z)
 {
-  owl_message *m;
+  if (z->cc || owl_zwrite_get_numrecips(z) == 0) {
+    /* create the message */
+    owl_message *m = g_new(owl_message, 1);
+    owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), 0);
 
-  /* create the message */
-  m=g_new(owl_message, 1);
-  owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z));
+    owl_global_messagequeue_addmsg(&g, m);
+  } else {
+    int i;
+    for (i = 0; i < owl_zwrite_get_numrecips(z); i++) {
+      /* create the message */
+      owl_message *m = g_new(owl_message, 1);
+      owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), i);
 
-  return(m);
+      owl_global_messagequeue_addmsg(&g, m);
+    }
+  }
 }
 
 /* Create an outgoing AIM message, returns a pointer to the created
  * message or NULL if we're not logged into AIM (and thus unable to
  * create the message).  Does not put it on the global queue.  Use
- * owl_global_messagequeue_addmsg() for that .
+ * owl_global_messagequeue_addmsg() for that.
  */
 owl_message *owl_function_make_outgoing_aim(const char *body, const char *to)
 {
@@ -375,13 +384,12 @@ void owl_callback_zwrite(owl_editwin *e) {
   owl_function_zwrite(z, owl_editwin_get_text(e));
 }
 
-/* send, log and display an outgoing zephyr.  If 'msg' is NULL
- * the message is expected to be set from the zwrite line itself
+/* send, log and display outgoing zephyrs.  If 'msg' is NULL the
+ * message is expected to be set from the zwrite line itself
  */
 #ifdef HAVE_LIBZEPHYR
 void owl_function_zwrite(owl_zwrite *z, const char *msg)
 {
-  owl_message *m;
   int ret;
 
   if(strcmp(z->cmd, "zcrypt") == 0) {
@@ -404,13 +412,7 @@ void owl_function_zwrite(owl_zwrite *z, const char *msg)
   /* If it's personal */
   if (owl_zwrite_is_personal(z)) {
     /* create the outgoing message */
-    m=owl_function_make_outgoing_zephyr(z);
-
-    if (m) {
-      owl_global_messagequeue_addmsg(&g, m);
-    } else {
-      owl_function_error("Could not create outgoing zephyr message");
-    }
+    owl_function_add_outgoing_zephyrs(z);
   }
 }
 #else
@@ -418,13 +420,12 @@ void owl_function_zwrite(owl_zwrite *z, const char *msg) {
 }
 #endif
 
-/* send, log and display an outgoing zcrypt zephyr.  If 'msg' is NULL
+/* send, log and display outgoing zcrypt zephyrs.  If 'msg' is NULL
  * the message is expected to be set from the zwrite line itself
  */
 void owl_function_zcrypt(owl_zwrite *z, const char *msg)
 {
   char *cryptmsg;
-  owl_message *m;
   const char *argv[7];
   char *zcrypt;
   int rv, status;
@@ -466,12 +467,7 @@ void owl_function_zcrypt(owl_zwrite *z, const char *msg)
   if (owl_zwrite_is_personal(z)) {
     /* Create the outgoing message. Restore the un-crypted message for display. */
     owl_zwrite_set_message_raw(z, old_msg);
-    m=owl_function_make_outgoing_zephyr(z);
-    if (m) {
-      owl_global_messagequeue_addmsg(&g, m);
-    } else {
-      owl_function_error("Could not create outgoing zephyr message");
-    }
+    owl_function_add_outgoing_zephyrs(z);
   }
 
   /* free the zwrite */
diff --git a/logging.c b/logging.c
index 8042386..c4a53b5 100644
--- a/logging.c
+++ b/logging.c
@@ -185,7 +185,8 @@ void owl_log_outgoing_zephyr_error(const owl_zwrite *zw, const char *text)
    * owl_log_shouldlog_message(void)
    */
   m = g_new(owl_message, 1);
-  owl_message_create_from_zwrite(m, zw, text);
+  /* recip_index = 0 because there can only be one recipient anyway */
+  owl_message_create_from_zwrite(m, zw, text, 0);
   if (!owl_log_shouldlog_message(m)) {
     owl_message_delete(m);
     return;
diff --git a/message.c b/message.c
index e994587..0acedac 100644
--- a/message.c
+++ b/message.c
@@ -957,7 +957,7 @@ void owl_message_create_pseudo_zlogin(owl_message *m, int direction, const char
   g_free(longuser);
 }
 
-void owl_message_create_from_zwrite(owl_message *m, const owl_zwrite *z, const char *body)
+void owl_message_create_from_zwrite(owl_message *m, const owl_zwrite *z, const char *body, int recip_index)
 {
   char *replyline;
   
@@ -969,10 +969,9 @@ void owl_message_create_from_zwrite(owl_message *m, const owl_zwrite *z, const c
   owl_message_set_sender(m, owl_zephyr_get_sender());
   owl_message_set_class(m, owl_zwrite_get_class(z));
   owl_message_set_instance(m, owl_zwrite_get_instance(z));
-  if (owl_zwrite_get_numrecips(z)>0) {
-    char *longzuser = long_zuser(owl_zwrite_get_recip_n(z, 0));
-    owl_message_set_recipient(m,
-			      longzuser); /* only gets the first user, must fix */
+  if (owl_zwrite_get_numrecips(z) > recip_index) {
+    char *longzuser = long_zuser(owl_zwrite_get_recip_n(z, recip_index));
+    owl_message_set_recipient(m, longzuser);
     g_free(longzuser);
   }
   owl_message_set_opcode(m, owl_zwrite_get_opcode(z));
diff --git a/zephyr.c b/zephyr.c
index b66b32b..e9f26e4 100644
--- a/zephyr.c
+++ b/zephyr.c
@@ -850,7 +850,6 @@ void owl_zephyr_zaway(const owl_message *m)
 {
 #ifdef HAVE_LIBZEPHYR
   char *tmpbuff, *myuser, *to;
-  owl_message *mout;
   owl_zwrite *z;
   
   /* bail if it doesn't look like a message we should reply to.  Some
@@ -897,8 +896,7 @@ void owl_zephyr_zaway(const owl_message *m)
   owl_zwrite_set_zsig(z, "Automated reply:");
 
   /* display the message as an admin message in the receive window */
-  mout=owl_function_make_outgoing_zephyr(z);
-  owl_global_messagequeue_addmsg(&g, mout);
+  owl_function_add_outgoing_zephyrs(z);
   owl_zwrite_delete(z);
 #endif
 }
-- 
1.7.3.3.399.g06ddf


home help back first fref pref prev next nref lref last post