Changeset b45293f


Ignore:
Timestamp:
Oct 11, 2002, 11:56:23 PM (22 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
68b41b0
Parents:
2adaf1d
Message:
Outgoing messages now go through the config for formatting
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r2adaf1d rb45293f  
    11$Id$
    22
     31.2.7
     4        Outgoing messages now go through the config for formatting
     5       
    361.2.6
    47        Started adding code for newmsgproc.  It doesn't fully work yet!
  • functions.c

    r2adaf1d rb45293f  
    8282}
    8383
    84 void owl_function_make_outgoing_zephyr(char *header, char *body, char *zwriteline, char *zsig) {
     84void owl_function_make_outgoing_zephyr(char *body, char *zwriteline, char *zsig) {
    8585  owl_message *m;
    8686  int followlast;
    8787  owl_zwrite z;
    88   char *tobuff, *recip;
    8988 
    9089  followlast=owl_global_should_followlast(&g);
     
    9392  owl_zwrite_create_from_line(&z, zwriteline);
    9493
    95   /* in 'tobuff' place the "Message sent to foo" string.
    96    * Right now this only works for one recipient */
    97   tobuff=owl_malloc(strlen(owl_zwrite_get_recip_n(&z, 0))+100);
    98   sprintf(tobuff, "Zephyr sent to %s  (Zsig: %s)", owl_zwrite_get_recip_n(&z, 0), zsig);
    99 
    10094  /* create the message */
    10195  m=owl_malloc(sizeof(owl_message));
    102   owl_message_create(m,  tobuff, body);
    103   owl_message_set_direction_out(m);
    104   owl_message_set_type_zephyr(m);
    105 
    106   /* set zwriteline */
    107   owl_message_set_zwriteline(m, zwriteline);
    108 
    109   owl_message_set_class(m, owl_zwrite_get_class(&z));
    110   owl_message_set_instance(m, owl_zwrite_get_instance(&z));
    111   owl_message_set_opcode(m, owl_zwrite_get_opcode(&z));
    112   owl_message_set_realm(m, owl_zwrite_get_realm(&z));
    113   owl_message_set_sender(m, ZGetSender());
    114   /* this only gets the first recipient for now, must fix */
    115   recip=long_zuser(owl_zwrite_get_recip_n(&z, 0));
    116   owl_message_set_recipient(m, recip);
    117   owl_free(recip);
     96  owl_message_create_from_zwriteline(m, zwriteline, body, zsig);
    11897
    11998  /* add it to the global list */
     
    130109  wnoutrefresh(owl_global_get_curs_recwin(&g));
    131110  owl_global_set_needrefresh(&g);
    132   owl_free(tobuff);
    133111  owl_zwrite_free(&z);
    134112}
     
    176154
    177155void owl_function_zwrite(char *line) {
    178   char *tmpbuff, buff[1024];
     156  char buff[1024];
    179157  owl_zwrite z;
    180158  int i, j;
     
    188166  if (owl_global_is_displayoutgoing(&g) && owl_zwrite_is_personal(&z)) {
    189167    owl_zwrite_get_recipstr(&z, buff);
    190     tmpbuff = owl_sprintf("Message sent to %s", buff);
    191     owl_function_make_outgoing_zephyr(tmpbuff, owl_editwin_get_text(owl_global_get_typwin(&g)), line, owl_zwrite_get_zsig(&z));
    192     owl_free(tmpbuff);
     168    owl_function_make_outgoing_zephyr(owl_editwin_get_text(owl_global_get_typwin(&g)), line, owl_zwrite_get_zsig(&z));
    193169  }
    194170
     
    953929  if (owl_global_is_bell(&g)) {
    954930    beep();
     931    owl_global_set_needrefresh(&g); /* do we really need this? */
    955932  }
    956933}
  • message.c

    r3a2daac rb45293f  
    11#include <zephyr/zephyr.h>
    22#include <stdlib.h>
     3#include <unistd.h>
    34#include <string.h>
    45#include <sys/socket.h>
     
    2627  m->opcode=owl_strdup("");
    2728  m->realm=owl_strdup("");
     29  m->zsig=owl_strdup("");
    2830  strcpy(m->hostname, "");
    2931  m->zwriteline=strdup("");
     
    6567char *owl_message_get_sender(owl_message *m) {
    6668  return(m->sender);
     69}
     70
     71void owl_message_set_zsig(owl_message *m, char *zsig) {
     72  if (m->zsig) owl_free(m->zsig);
     73  m->zsig=owl_strdup(zsig);
     74}
     75
     76char *owl_message_get_zsig(owl_message *m) {
     77  return(m->zsig);
    6778}
    6879
     
    347358}
    348359
    349 void owl_message_create_from_zephyr(owl_message *m, ZNotice_t *n) {
     360void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n) {
    350361  struct hostent *hent;
    351362  int k;
     
    374385    n->z_opcode=owl_strdup("");
    375386  }
     387  m->zsig=owl_strdup(n->z_message);
    376388
    377389  if ((ptr=strchr(n->z_recipient, '@'))!=NULL) {
     
    383395  m->zwriteline=strdup("");
    384396
     397  /* set the body */
    385398  ptr=owl_zephyr_get_message(n, &k);
    386399  m->body=owl_malloc(k+10);
     
    412425}
    413426
     427void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig) {
     428  owl_zwrite z;
     429  int ret;
     430 
     431  owl_message_init_raw(m);
     432
     433  /* create a zwrite for the purpose of filling in other message fields */
     434  owl_zwrite_create_from_line(&z, line);
     435
     436  /* set things */
     437  owl_message_set_direction_out(m);
     438  owl_message_set_type_zephyr(m);
     439  m->sender=owl_strdup(ZGetSender());
     440  m->class=owl_strdup(owl_zwrite_get_class(&z));
     441  m->inst=owl_strdup(owl_zwrite_get_instance(&z));
     442  m->recip=long_zuser(owl_zwrite_get_recip_n(&z, 0)); /* only gets the first user, must fix */
     443  owl_zwrite_get_recipstr(&z, m->recip);
     444  m->opcode=owl_strdup(owl_zwrite_get_opcode(&z));
     445  m->realm=owl_strdup(owl_zwrite_get_realm(&z)); /* also a hack, but not here */
     446  m->zwriteline=owl_strdup(line);
     447  m->body=owl_strdup(body);
     448  m->zsig=owl_strdup(zsig);
     449 
     450  /* save the hostname */
     451  ret=gethostname(m->hostname, MAXHOSTNAMELEN);
     452  if (ret) {
     453    strcpy(m->hostname, "localhost");
     454  }
     455
     456  /* create the formatted message */
     457  if (owl_global_is_config_format(&g)) {
     458    _owl_message_make_text_from_config(m);
     459  } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
     460    _owl_message_make_text_from_zwriteline_standard(m);
     461  } else {
     462    _owl_message_make_text_from_zwriteline_simple(m);
     463  }
     464
     465  owl_zwrite_free(&z);
     466}
    414467
    415468void _owl_message_make_text_from_config(owl_message *m) {
     
    432485}
    433486
     487void _owl_message_make_text_from_zwriteline_standard(owl_message *m) {
     488  char *indent, *text, *zsigbuff;
     489
     490  text=owl_message_get_body(m);
     491
     492  indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
     493  owl_text_indent(indent, text, OWL_MSGTAB);
     494  owl_fmtext_init_null(&(m->fmtext));
     495  owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
     496  owl_fmtext_append_normal(&(m->fmtext), "Zephyr sent to ");
     497  owl_fmtext_append_normal(&(m->fmtext), owl_message_get_recipient(m));
     498  owl_fmtext_append_normal(&(m->fmtext), "  (Zsig: ");
     499
     500  zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m)));
     501  owl_message_pretty_zsig(m, zsigbuff);
     502  owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
     503  owl_free(zsigbuff);
     504 
     505  owl_fmtext_append_normal(&(m->fmtext), ")");
     506  owl_fmtext_append_normal(&(m->fmtext), "\n");
     507  owl_fmtext_append_ztext(&(m->fmtext), indent);
     508  if (text[strlen(text)-1]!='\n') {
     509    owl_fmtext_append_normal(&(m->fmtext), "\n");
     510  }
     511
     512  owl_free(indent);
     513}
     514
     515void _owl_message_make_text_from_zwriteline_simple(owl_message *m) {
     516  _owl_message_make_text_from_zwriteline_standard(m);
     517}
     518
    434519void _owl_message_make_text_from_notice_standard(owl_message *m) {
    435   char *body, *indent, *ptr;
    436   char frombuff[1024];
    437   char zsigbuff[LINE];
     520  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
    438521  ZNotice_t *n;
    439522  int len;
     
    514597
    515598    /* stick on the zsig */
    516     _owl_message_get_zsig(m, zsigbuff, LINE);
    517     if (zsigbuff[0]!='\0') {
    518       owl_fmtext_append_normal(&(m->fmtext), "    (");
    519       owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
    520       owl_fmtext_append_normal(&(m->fmtext), ")");
    521     }
    522     owl_fmtext_append_normal(&(m->fmtext), "\n");
     599    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m)));
     600    owl_message_pretty_zsig(m, zsigbuff);
     601    owl_fmtext_append_normal(&(m->fmtext), "    (");
     602    owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
     603    owl_fmtext_append_normal(&(m->fmtext), ")");
     604    owl_fmtext_append_normal(&(m->fmtext), "\n");
     605    owl_free(zsigbuff);
     606
     607    /* then the indented message */
    523608    owl_fmtext_append_ztext(&(m->fmtext), indent);
    524609
     
    536621
    537622void _owl_message_make_text_from_notice_simple(owl_message *m) {
    538   char *body, *indent, *ptr;
    539   char frombuff[1024];
    540   char zsigbuff[LINE];
     623  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
    541624  ZNotice_t *n;
    542625  int len;
     
    616699
    617700    /* stick on the zsig */
    618     _owl_message_get_zsig(m, zsigbuff, LINE);
    619     if (zsigbuff[0]!='\0') {
    620       owl_fmtext_append_normal(&(m->fmtext), "    (");
    621       owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
    622       owl_fmtext_append_normal(&(m->fmtext), ")");
    623     }
    624     owl_fmtext_append_normal(&(m->fmtext), "\n");
     701    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m)));
     702    owl_message_pretty_zsig(m, zsigbuff);
     703    owl_fmtext_append_normal(&(m->fmtext), "    (");
     704    owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
     705    owl_fmtext_append_normal(&(m->fmtext), ")");
     706    owl_fmtext_append_normal(&(m->fmtext), "\n");
     707    owl_free(zsigbuff);
     708
     709    /* then the indented message */
    625710    owl_fmtext_append_ztext(&(m->fmtext), indent);
    626711
     
    637722}
    638723
    639 void _owl_message_get_zsig(owl_message *m, char *buff, int size) {
     724void owl_message_pretty_zsig(owl_message *m, char *buff) {
     725  /* stick a one line version of the zsig in buff */
    640726  char *ptr;
    641   ZNotice_t n;
    642   int len;
    643   /* just a hackish thing for now.  We'll only present the first line
    644      or the first 'size'. characters.  If the message is not
    645      appropriate for having a zsig we'll return an empty string */
    646   n=m->notice;
    647 
    648 
    649   /* bail if it shouldn't have a zsig */
    650   buff[0]='\0';
    651   if (!strcasecmp(n.z_opcode, "ping")) {
    652     return;
    653   }
    654 
    655   /* find the right length to copy */
    656   len=strlen(n.z_message);
    657   if (size < len) {
    658     len=size;
    659   }
    660   if ((ptr=strchr(n.z_message, '\n'))!=NULL) {
    661     if ((ptr-n.z_message) < len) {
    662       len=ptr-n.z_message;
    663     }
    664   }
    665 
    666   /* copy */
    667   strncpy(buff, n.z_message, len);
    668   buff[len]='\0';
    669 }
    670 
     727
     728  strcpy(buff, m->zsig);
     729  ptr=strchr(buff, '\n');
     730  if (ptr) ptr[0]='\0';
     731}
    671732
    672733void owl_message_free(owl_message *m) {
  • owl.c

    r55a4578 rb45293f  
    3232  owl_editwin *tw;
    3333  owl_popwin *pw;
    34   int j, ret, initialsubs, debug, newzephyrs, argcsave, followlast;
     34  int j, ret, initialsubs, debug, newzephyrs, argcsave, followlast, nexttimediff;
    3535  struct sigaction sigact;
    36   char *configfile, *tty, *perlout;
    37   char buff[LINE], startupmsg[LINE];
    38   char **argvsave;
     36  char *configfile, *tty, *perlout, **argvsave, buff[LINE], startupmsg[LINE];
    3937  owl_filter *f;
    4038  time_t nexttime;
    41   int nexttimediff;
    4239
    4340  argcsave=argc;
     
    139136  /* setup the default filters */
    140137  f=malloc(sizeof(owl_filter));
    141   owl_filter_init_fromstring(f, "personal", "class ^message$ and instance ^personal$ and ( recipient ^%me%$ or sender ^%me%$ )"); /* fix to use admintype */
     138  owl_filter_init_fromstring(f, "personal", "class ^message$ and instance ^personal$ and ( recipient ^%me%$ or sender ^%me%$ )");
    142139  owl_list_append_element(owl_global_get_filterlist(&g), f);
    143140
     
    189186  sepwin=owl_global_get_curs_sepwin(&g);
    190187  typwin=owl_global_get_curs_typwin(&g);
    191 
    192188  tw=owl_global_get_typwin(&g);
    193189
     
    279275      /* create the new message */
    280276      m=owl_malloc(sizeof(owl_message));
    281       owl_message_create_from_zephyr(m, &notice);
     277      owl_message_create_from_znotice(m, &notice);
    282278     
    283279      /* if it's on the puntlist then, nuke it and continue */
     
    305301      if (owl_global_is_personalbell(&g) && owl_message_is_personal(m)) {
    306302        owl_function_beep();
    307         owl_global_set_needrefresh(&g);
    308303      }
    309304
  • owl.h

    r88736cb rb45293f  
    1212static const char owl_h_fileIdent[] = "$Id$";
    1313
    14 #define OWL_VERSION         1.2.6
    15 #define OWL_VERSION_STRING "1.2.6"
     14#define OWL_VERSION         1.2.7
     15#define OWL_VERSION_STRING "1.2.7"
    1616
    1717#define OWL_DEBUG 0
     
    242242  char *body;
    243243  char *zwriteline;
     244  char *zsig;
    244245} owl_message;
    245246
  • readconfig.c

    r4b464a4 rb45293f  
    6262  /* create variables */
    6363  perl_get_sv("owl::id", TRUE);
     64  perl_get_sv("owl::type", TRUE);
     65  perl_get_sv("owl::direction", TRUE);
    6466  perl_get_sv("owl::class", TRUE);
    6567  perl_get_sv("owl::instance", TRUE);
     
    127129  int i, j, len;
    128130  char *ptr, *ptr2;
    129   ZNotice_t *n;
    130131
    131132  if (!owl_global_have_config(&g)) return("");
    132133
    133134  /* set owl::msg */
    134   n=owl_message_get_notice(m);
    135   ptr=owl_zephyr_get_message(n, &len);
     135  ptr=owl_message_get_body(m);
     136  len=strlen(ptr);
    136137  ptr2=owl_malloc(len+20);
    137138  memcpy(ptr2, ptr, len);
     
    144145
    145146  /* set owl::zsig */
    146   ptr=owl_zephyr_get_zsig(n, &len);
     147  ptr=owl_message_get_zsig(m);
     148  len=strlen(ptr);
    147149  if (len>0) {
    148150    ptr2=owl_malloc(len+20);
     
    165167  } else {
    166168    sv_setpv(perl_get_sv("owl::type", TRUE), "unknown");
     169  }
     170
     171  /* set owl::direction */
     172  if (owl_message_is_direction_in(m)) {
     173    sv_setpv(perl_get_sv("owl::direction", TRUE), "in");
     174  } else if (owl_message_is_direction_out(m)) {
     175    sv_setpv(perl_get_sv("owl::direction", TRUE), "out");
     176  } else if (owl_message_is_direction_none(m)) {
     177    sv_setpv(perl_get_sv("owl::direction", TRUE), "none");
     178  } else {
     179    sv_setpv(perl_get_sv("owl::direction", TRUE), "unknown");
    167180  }
    168181
     
    189202
    190203  /* set owl::fields */
    191   av_clear(perl_get_av("owl::fields", TRUE));
    192   j=owl_zephyr_get_num_fields(n);
    193   for (i=0; i<j; i++) {
    194     ptr=owl_zephyr_get_field(n, i+1, &len);
    195     ptr2=owl_malloc(len+10);
    196     memcpy(ptr2, ptr, len);
    197     ptr2[len]='\0';
    198     av_push(perl_get_av("owl::fields", TRUE), newSVpvn(ptr2, len));
    199     owl_free(ptr2);
     204  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
     205    av_clear(perl_get_av("owl::fields", TRUE));
     206    j=owl_zephyr_get_num_fields(owl_message_get_notice(m));
     207    for (i=0; i<j; i++) {
     208      ptr=owl_zephyr_get_field(owl_message_get_notice(m), i+1, &len);
     209      ptr2=owl_malloc(len+10);
     210      memcpy(ptr2, ptr, len);
     211      ptr2[len]='\0';
     212      av_push(perl_get_av("owl::fields", TRUE), newSVpvn(ptr2, len));
     213      owl_free(ptr2);
     214    }
    200215  }
    201216
    202217  /* for backwards compatibilty, because I'm an idiot */
    203   av_clear(perl_get_av("fields", TRUE));
    204   j=owl_zephyr_get_num_fields(n);
    205   for (i=0; i<j; i++) {
    206     ptr=owl_zephyr_get_field(n, i+1, &len);
    207     ptr2=owl_malloc(len+10);
    208     memcpy(ptr2, ptr, len);
    209     ptr2[len]='\0';
    210     av_push(perl_get_av("fields", TRUE), newSVpvn(ptr2, len));
    211     owl_free(ptr2);
     218  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
     219    av_clear(perl_get_av("fields", TRUE));
     220    j=owl_zephyr_get_num_fields(owl_message_get_notice(m));
     221    for (i=0; i<j; i++) {
     222      ptr=owl_zephyr_get_field(owl_message_get_notice(m), i+1, &len);
     223      ptr2=owl_malloc(len+10);
     224      memcpy(ptr2, ptr, len);
     225      ptr2[len]='\0';
     226      av_push(perl_get_av("fields", TRUE), newSVpvn(ptr2, len));
     227      owl_free(ptr2);
     228    }
    212229  }
    213230
Note: See TracChangeset for help on using the changeset viewer.