Changeset 4b464a4 for message.c


Ignore:
Timestamp:
Aug 25, 2002, 11:35:03 AM (18 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
56330ff
Parents:
7131cf2
Message:
Messages now have a direciton (in, out or none).  Filters can
     this direction
Outbound messages are no longer type 'admin' but are of the
     appropriate message type (i.e. 'zephyr') and are direction
     'out'.
Smartnarrow now works on outgoing messages
'info' updated to show more information for admin and outgoing
     messages
Renamed pretty_sender to short_zuser and renamed long_sender to
     long_zuser
File:
1 edited

Legend:

Unmodified
Added
Removed
  • message.c

    r1fd0b25 r4b464a4  
    1313static const char fileIdent[] = "$Id$";
    1414
    15 void owl_message_create_admin(owl_message *m, char *header, char *text) {
    16   char *indent;
     15void owl_message_init_raw(owl_message *m) {
    1716  time_t t;
    1817
    1918  m->id=owl_global_get_nextmsgid(&g);
    20   m->type=OWL_MESSAGE_TYPE_ADMIN;
    21   m->admintype=OWL_MESSAGE_ADMINTYPE_GENERIC;
     19  m->type=OWL_MESSAGE_TYPE_GENERIC;
     20  owl_message_set_direction_none(m);
    2221  m->delete=0;
    23   m->sender=owl_strdup("-owl");
     22  m->sender=owl_strdup("");
    2423  m->class=owl_strdup("");
    2524  m->inst=owl_strdup("");
     
    3433  m->time=owl_strdup(ctime(&t));
    3534  m->time[strlen(m->time)-1]='\0';
     35}
     36
     37
     38owl_fmtext *owl_message_get_fmtext(owl_message *m) {
     39  return(&(m->fmtext));
     40}
     41
     42void owl_message_set_class(owl_message *m, char *class) {
     43  if (m->class) owl_free(m->class);
     44  m->class=owl_strdup(class);
     45}
     46
     47char *owl_message_get_class(owl_message *m) {
     48  return(m->class);
     49}
     50
     51void owl_message_set_instance(owl_message *m, char *inst) {
     52  if (m->inst) owl_free(m->inst);
     53  m->inst=owl_strdup(inst);
     54}
     55
     56char *owl_message_get_instance(owl_message *m) {
     57  return(m->inst);
     58}
     59
     60void owl_message_set_sender(owl_message *m, char *sender) {
     61  if (m->sender) owl_free(m->sender);
     62  m->sender=owl_strdup(sender);
     63}
     64
     65char *owl_message_get_sender(owl_message *m) {
     66  return(m->sender);
     67}
     68
     69void owl_message_set_recipient(owl_message *m, char *recip) {
     70  if (m->recip) owl_free(m->recip);
     71  m->recip=owl_strdup(recip);
     72}
     73
     74char *owl_message_get_recipient(owl_message *m) {
     75  /* this is stupid for outgoing messages, we need to fix it. */
     76     
     77  if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) {
     78    return(m->recip);
     79  } else if (owl_message_is_direction_out(m)) {
     80    return(m->zwriteline);
     81  } else {
     82    return(m->recip);
     83  }
     84}
     85
     86void owl_message_set_realm(owl_message *m, char *realm) {
     87  if (m->realm) owl_free(m->realm);
     88  m->realm=owl_strdup(realm);
     89}
     90
     91char *owl_message_get_realm(owl_message *m) {
     92  return(m->realm);
     93}
     94
     95void owl_message_set_opcode(owl_message *m, char *opcode) {
     96  if (m->opcode) free(m->opcode);
     97  m->opcode=owl_strdup(opcode);
     98}
     99
     100char *owl_message_get_opcode(owl_message *m) {
     101  return(m->opcode);
     102}
     103
     104char *owl_message_get_timestr(owl_message *m) {
     105  return(m->time);
     106}
     107
     108void owl_message_set_type_admin(owl_message *m) {
     109  m->type=OWL_MESSAGE_TYPE_ADMIN;
     110}
     111
     112void owl_message_set_type_zephyr(owl_message *m) {
     113  m->type=OWL_MESSAGE_TYPE_ZEPHYR;
     114}
     115                                               
     116int owl_message_is_type_admin(owl_message *m) {
     117  if (m->type==OWL_MESSAGE_TYPE_ADMIN) return(1);
     118  return(0);
     119}
     120
     121int owl_message_is_type_zephyr(owl_message *m) {
     122  if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return(1);
     123  return(0);
     124}
     125
     126int owl_message_is_type_generic(owl_message *m) {
     127  if (m->type==OWL_MESSAGE_TYPE_GENERIC) return(1);
     128  return(0);
     129}
     130
     131char *owl_message_get_text(owl_message *m) {
     132  return(owl_fmtext_get_text(&(m->fmtext)));
     133}
     134
     135char *owl_message_get_body(owl_message *m) {
     136  return(m->body);
     137}
     138
     139void owl_message_set_direction_in(owl_message *m) {
     140  m->direction=OWL_MESSAGE_DIRECTION_IN;
     141}
     142
     143void owl_message_set_direction_out(owl_message *m) {
     144  m->direction=OWL_MESSAGE_DIRECTION_OUT;
     145}
     146
     147void owl_message_set_direction_none(owl_message *m) {
     148  m->direction=OWL_MESSAGE_DIRECTION_NONE;
     149}
     150
     151int owl_message_is_direction_in(owl_message *m) {
     152  if (m->direction==OWL_MESSAGE_DIRECTION_IN) return(1);
     153  return(0);
     154}
     155
     156int owl_message_is_direction_out(owl_message *m) {
     157  if (m->direction==OWL_MESSAGE_DIRECTION_OUT) return(1);
     158  return(0);
     159}
     160
     161int owl_message_is_direction_none(owl_message *m) {
     162  if (m->direction==OWL_MESSAGE_DIRECTION_NONE) return(1);
     163  return(0);
     164}
     165
     166int owl_message_get_numlines(owl_message *m) {
     167  if (m == NULL) return(0);
     168  return(owl_fmtext_num_lines(&(m->fmtext)));
     169}
     170
     171void owl_message_mark_delete(owl_message *m) {
     172  if (m == NULL) return;
     173  m->delete=1;
     174}
     175
     176void owl_message_unmark_delete(owl_message *m) {
     177  if (m == NULL) return;
     178  m->delete=0;
     179}
     180
     181char *owl_message_get_zwriteline(owl_message *m) {
     182  return(m->zwriteline);
     183}
     184
     185void owl_message_set_zwriteline(owl_message *m, char *line) {
     186  m->zwriteline=strdup(line);
     187}
     188
     189int owl_message_is_delete(owl_message *m) {
     190  if (m == NULL) return(0);
     191  if (m->delete==1) return(1);
     192  return(0);
     193}
     194
     195ZNotice_t *owl_message_get_notice(owl_message *m) {
     196  return(&(m->notice));
     197}
     198
     199char *owl_message_get_hostname(owl_message *m) {
     200  return(m->hostname);
     201}
     202
     203
     204void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color) {
     205  owl_fmtext a, b;
     206
     207  owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
     208  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
     209  if (color!=OWL_COLOR_DEFAULT) {
     210    owl_fmtext_colorize(&b, color);
     211  }
     212
     213  if (owl_global_is_search_active(&g)) {
     214    owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g));
     215  }
     216     
     217  owl_fmtext_curs_waddstr(&b, win);
     218
     219  owl_fmtext_free(&a);
     220  owl_fmtext_free(&b);
     221}
     222
     223int owl_message_is_personal(owl_message *m) {
     224  if (strcasecmp(owl_message_get_class(m), "message")) return(0);
     225  if (strcasecmp(owl_message_get_instance(m), "personal")) return(0);
     226  if (!strcmp(owl_message_get_recipient(m), ZGetSender()) ||
     227      !strcmp(owl_message_get_sender(m), ZGetSender())) {
     228    return(1);
     229  }
     230  return(0);
     231}
     232
     233int owl_message_is_private(owl_message *m) {
     234  if (!strcmp(owl_message_get_recipient(m), ZGetSender())) return(1);
     235  return(0);
     236}
     237
     238int owl_message_is_mail(owl_message *m) {
     239  if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) {
     240    return(1);
     241  }
     242  return(0);
     243}
     244
     245int owl_message_is_ping(owl_message *m) {
     246  if (!strcasecmp(owl_message_get_opcode(m), "ping")) return(1);
     247  return(0);
     248}
     249
     250int owl_message_is_login(owl_message *m) {
     251  if (!strcasecmp(owl_message_get_class(m), "login")) return(1);
     252  return(0);
     253  /* is this good enough? */
     254}
     255
     256int owl_message_is_burningears(owl_message *m) {
     257  /* we should add a global to cache the short zsender */
     258  char sender[LINE], *ptr;
     259
     260  /* if the message is from us or to us, it doesn't count */
     261  if (!strcasecmp(ZGetSender(), owl_message_get_sender(m))) return(0);
     262  if (!strcasecmp(ZGetSender(), owl_message_get_recipient(m))) return(0);
     263
     264  strcpy(sender, ZGetSender());
     265  ptr=strchr(sender, '@');
     266  if (ptr) *ptr='\0';
     267
     268  if (stristr(owl_message_get_body(m), sender)) {
     269    return(1);
     270  }
     271  return(0);
     272}
     273
     274/* caller must free return value. */
     275char *owl_message_get_cc(owl_message *m) {
     276  char *cur, *out, *end;
     277
     278  cur = owl_message_get_body(m);
     279  while (*cur && *cur==' ') cur++;
     280  if (strncasecmp(cur, "cc:", 2)) return(NULL);
     281  cur+=3;
     282  while (*cur && *cur==' ') cur++;
     283  out = owl_strdup(cur);
     284  end = strchr(out, '\n');
     285  if (end) end[0] = '\0';
     286  return(out);
     287}
     288
     289int owl_message_get_id(owl_message *m) {
     290  return(m->id);
     291}
     292                                       
     293int owl_message_search(owl_message *m, char *string) {
     294  /* return 1 if the message contains "string", 0 otherwise.  This is
     295   * case insensitive because the functions it uses are */
     296
     297  return (owl_fmtext_search(&(m->fmtext), string));
     298}
     299
     300void owl_message_create(owl_message *m, char *header, char *text) {
     301  char *indent;
     302
     303  owl_message_init_raw(m);
     304
     305  m->body=owl_strdup(text);
     306
     307  indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
     308  owl_text_indent(indent, text, OWL_MSGTAB);
     309  owl_fmtext_init_null(&(m->fmtext));
     310  owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
     311  owl_fmtext_append_ztext(&(m->fmtext), header);
     312  owl_fmtext_append_normal(&(m->fmtext), "\n");
     313  owl_fmtext_append_ztext(&(m->fmtext), indent);
     314  if (text[strlen(text)-1]!='\n') {
     315    owl_fmtext_append_normal(&(m->fmtext), "\n");
     316  }
     317
     318  owl_free(indent);
     319}
     320
     321void owl_message_create_admin(owl_message *m, char *header, char *text) {
     322  char *indent;
     323
     324  owl_message_init_raw(m);
     325  owl_message_set_type_admin(m);
    36326
    37327  m->body=owl_strdup(text);
     
    60350
    61351  m->id=owl_global_get_nextmsgid(&g);
    62   m->type=OWL_MESSAGE_TYPE_ZEPHYR;
     352  owl_message_set_type_zephyr(m);
     353  owl_message_set_direction_in(m);
    63354 
    64355  /* first save the full notice */
     
    194485    }
    195486    owl_fmtext_append_normal(&(m->fmtext), " for ");
    196     ptr=pretty_sender(n->z_class_inst);
     487    ptr=short_zuser(n->z_class_inst);
    197488    owl_fmtext_append_bold(&(m->fmtext), ptr);
    198489    owl_free(ptr);
     
    297588    }
    298589    owl_fmtext_append_normal(&(m->fmtext), " for ");
    299     ptr=pretty_sender(n->z_class_inst);
     590    ptr=short_zuser(n->z_class_inst);
    300591    owl_fmtext_append_bold(&(m->fmtext), ptr);
    301592    owl_free(ptr);
     
    376667
    377668
    378 int owl_message_get_numlines(owl_message *m) {
    379   if (m == NULL) return(0);
    380   return(owl_fmtext_num_lines(&(m->fmtext)));
    381 }
    382 
    383 
    384 void owl_message_mark_delete(owl_message *m) {
    385   if (m == NULL) return;
    386   m->delete=1;
    387   /* _owl_message_make_text_from_notice(m); */
    388 }
    389 
    390 
    391 void owl_message_unmark_delete(owl_message *m) {
    392   if (m == NULL) return;
    393   m->delete=0;
    394 }
    395 
    396 
    397 int owl_message_set_admintype(owl_message *m, int admintype) {
    398   if (m->type != OWL_MESSAGE_TYPE_ADMIN) return(-1);
    399   m->admintype=admintype;
    400   return(0);
    401 }
    402 
    403 
    404 int owl_message_get_admintype(owl_message *m) {
    405   return(m->admintype);
    406 }
    407 
    408 void owl_message_set_admin_outgoing(owl_message *m, char *zwriteline) {
    409   owl_message_set_admintype(m, OWL_MESSAGE_ADMINTYPE_OUTGOING);
    410   if (m->zwriteline) {
    411     owl_free(m->zwriteline);
    412     m->zwriteline=owl_strdup(zwriteline);
    413   }
    414 }
    415 
    416 char *owl_message_get_zwriteline(owl_message *m) {
    417   return(m->zwriteline);
    418 }
    419 
    420 int owl_message_is_delete(owl_message *m) {
    421   if (m == NULL) return(0);
    422   if (m->delete==1) return(1);
    423   return(0);
    424 }
    425 
    426 ZNotice_t *owl_message_get_notice(owl_message *m) {
    427   return(&(m->notice));
    428 }
    429 
    430 
    431669void owl_message_free(owl_message *m) {
    432   if (owl_message_is_zephyr(m)) {
     670  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
    433671    ZFreeNotice(&(m->notice));
    434672  }
     
    446684}
    447685
    448 
    449 char *owl_message_get_hostname(owl_message *m) {
    450   return(m->hostname);
    451 }
    452 
    453 
    454 void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color) {
    455   owl_fmtext a, b;
    456 
    457   owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
    458   owl_fmtext_truncate_cols(&a, acol, bcol, &b);
    459   if (color!=OWL_COLOR_DEFAULT) {
    460     owl_fmtext_colorize(&b, color);
    461   }
    462 
    463   if (owl_global_is_search_active(&g)) {
    464     owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g));
    465   }
    466      
    467   owl_fmtext_curs_waddstr(&b, win);
    468 
    469   owl_fmtext_free(&a);
    470   owl_fmtext_free(&b);
    471 }
    472 
    473 owl_fmtext *owl_message_get_fmtext(owl_message *m) {
    474   return(&(m->fmtext));
    475 }
    476 
    477 void owl_message_set_class(owl_message *m, char *class) {
    478   if (m->class) owl_free(m->class);
    479   m->class=owl_strdup(class);
    480 }
    481 
    482 
    483 char *owl_message_get_class(owl_message *m) {
    484   return(m->class);
    485 }
    486 
    487 void owl_message_set_instance(owl_message *m, char *inst) {
    488   if (m->inst) owl_free(m->inst);
    489   m->inst=owl_strdup(inst);
    490 }
    491 
    492 char *owl_message_get_instance(owl_message *m) {
    493   return(m->inst);
    494 }
    495 
    496 void owl_message_set_sender(owl_message *m, char *sender) {
    497   if (m->sender) owl_free(m->sender);
    498   m->sender=owl_strdup(sender);
    499 }
    500 
    501 char *owl_message_get_sender(owl_message *m) {
    502   return(m->sender);
    503 }
    504 
    505 void owl_message_set_recipient(owl_message *m, char *recip) {
    506   if (m->recip) owl_free(m->recip);
    507   m->recip=owl_strdup(recip);
    508 }
    509 
    510 char *owl_message_get_recipient(owl_message *m) {
    511   /* this is very, very stupid for outgoing messages, we need to
    512      fix that. */
    513      
    514   if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) {
    515     return(m->recip);
    516   } else if (m->type==OWL_MESSAGE_TYPE_ADMIN &&
    517              m->admintype==OWL_MESSAGE_ADMINTYPE_OUTGOING) {
    518     return(m->zwriteline);
    519   } else {
    520     return(m->recip);
    521   }
    522 }
    523 
    524 void owl_message_set_realm(owl_message *m, char *realm) {
    525   if (m->realm) owl_free(m->realm);
    526   m->realm=owl_strdup(realm);
    527 }
    528 
    529 char *owl_message_get_realm(owl_message *m) {
    530   return(m->realm);
    531 }
    532 
    533 void owl_message_set_opcode(owl_message *m, char *opcode) {
    534   if (m->opcode) free(m->opcode);
    535   m->opcode=owl_strdup(opcode);
    536 }
    537 
    538 char *owl_message_get_opcode(owl_message *m) {
    539   return(m->opcode);
    540 }
    541 
    542 char *owl_message_get_timestr(owl_message *m) {
    543   return(m->time);
    544 }
    545 
    546 int owl_message_is_admin(owl_message *m) {
    547   if (m->type==OWL_MESSAGE_TYPE_ADMIN) return(1);
    548   return(0);
    549 }
    550 
    551 int owl_message_is_zephyr(owl_message *m) {
    552   if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return(1);
    553   return(0);
    554 }
    555 
    556 char *owl_message_get_text(owl_message *m) {
    557   return(owl_fmtext_get_text(&(m->fmtext)));
    558 }
    559 
    560 char *owl_message_get_body(owl_message *m) {
    561   return(m->body);
    562 }
    563 
    564 int owl_message_is_personal(owl_message *m) {
    565   if (!strcasecmp(owl_message_get_class(m), "message") &&
    566       !strcasecmp(owl_message_get_instance(m), "personal") &&
    567       !strcmp(owl_message_get_recipient(m), ZGetSender())) {
    568     return(1);
    569   }
    570   return(0);
    571 }
    572 
    573 int owl_message_is_private(owl_message *m) {
    574   if (!strcmp(owl_message_get_recipient(m), ZGetSender())) return(1);
    575   return(0);
    576 }
    577 
    578 int owl_message_is_mail(owl_message *m) {
    579   if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) {
    580     return(1);
    581   }
    582   return(0);
    583 }
    584 
    585 int owl_message_is_ping(owl_message *m) {
    586   if (!strcasecmp(owl_message_get_opcode(m), "ping")) return(1);
    587   return(0);
    588 }
    589 
    590 int owl_message_is_login(owl_message *m) {
    591   if (!strcasecmp(owl_message_get_class(m), "login")) return(1);
    592   return(0);
    593   /* is this good enough? */
    594 }
    595 
    596 int owl_message_is_burningears(owl_message *m) {
    597   /* we should add a global to cache the short zsender */
    598   char sender[LINE], *ptr;
    599 
    600   /* if the message is from us or to us, it doesn't count */
    601   if (!strcasecmp(ZGetSender(), owl_message_get_sender(m))) return(0);
    602   if (!strcasecmp(ZGetSender(), owl_message_get_recipient(m))) return(0);
    603 
    604   strcpy(sender, ZGetSender());
    605   ptr=strchr(sender, '@');
    606   if (ptr) *ptr='\0';
    607 
    608   if (stristr(owl_message_get_body(m), sender)) {
    609     return(1);
    610   }
    611   return(0);
    612 }
    613 
    614 /* caller must free return value. */
    615 char *owl_message_get_cc(owl_message *m) {
    616   char *cur, *out, *end;
    617 
    618   cur = owl_message_get_body(m);
    619   while (*cur && *cur==' ') cur++;
    620   if (strncasecmp(cur, "cc:", 2)) return(NULL);
    621   cur+=3;
    622   while (*cur && *cur==' ') cur++;
    623   out = owl_strdup(cur);
    624   end = strchr(out, '\n');
    625   if (end) end[0] = '\0';
    626   return(out);
    627 }
    628 
    629 int owl_message_get_id(owl_message *m) {
    630   return(m->id);
    631 }
    632                                        
    633 int owl_message_search(owl_message *m, char *string) {
    634   /* return 1 if the message contains "string", 0 otherwise.  This is
    635    * case insensitive because the functions it uses are */
    636 
    637   return (owl_fmtext_search(&(m->fmtext), string));
    638 }
Note: See TracChangeset for help on using the changeset viewer.