[2740] in BarnOwl Developers

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

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

daemon@ATHENA.MIT.EDU (DD)
Sat Nov 6 22:35:58 2010

From: DD <liudi@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Sat,  6 Nov 2010 22:35:54 -0400

Fixes bug #63.
---
 functions.c |   52 ++++++++++++++++++++++++----------------------------
 logging.c   |    3 ++-
 message.c   |    6 +++---
 zephyr.c    |    4 +---
 4 files changed, 30 insertions(+), 35 deletions(-)

diff --git a/functions.c b/functions.c
index 7a8a880..6b0c9c7 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 = owl_malloc(sizeof(owl_message));
+    owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), 0);
 
-  /* create the message */
-  m=owl_malloc(sizeof(owl_message));
-  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 = owl_malloc(sizeof(owl_message));
+      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)
 {
@@ -372,12 +381,11 @@ 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
  */
 void owl_function_zwrite(owl_zwrite *z, const char *msg)
 {
-  owl_message *m;
   int ret;
 
   if(strcmp(z->cmd, "zcrypt") == 0) {
@@ -400,23 +408,16 @@ 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);
   }
 }
 
-/* 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;
@@ -458,12 +459,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 90a0453..462e9a9 100644
--- a/logging.c
+++ b/logging.c
@@ -182,7 +182,8 @@ void owl_log_outgoing_zephyr_error(const owl_zwrite *zw, const char *text)
    * owl_log_shouldlog_message(void)
    */
   m = owl_malloc(sizeof(owl_message));
-  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 2ab9051..5eee826 100644
--- a/message.c
+++ b/message.c
@@ -959,7 +959,7 @@ void owl_message_create_pseudo_zlogin(owl_message *m, int direction, const char
   owl_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)
 {
   int ret;
   char hostbuff[5000];
@@ -972,8 +972,8 @@ 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));
+  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); /* only gets the first user, must fix */
     owl_free(longzuser);
diff --git a/zephyr.c b/zephyr.c
index cc3487f..c4eae4b 100644
--- a/zephyr.c
+++ b/zephyr.c
@@ -857,7 +857,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
@@ -899,8 +898,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_free(tmpbuff);
   owl_zwrite_delete(z);
 #endif
-- 
1.7.1


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