source: message.c @ f1645da

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since f1645da was 25dd31a, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Added a timestamp to the default style.
  • Property mode set to 100644
File size: 19.8 KB
Line 
1#include <stdlib.h>
2#include <unistd.h>
3#include <string.h>
4#include <sys/socket.h>
5#include <netdb.h>
6#include <sys/types.h>
7#include <sys/socket.h>
8#include <netinet/in.h>
9#include <arpa/inet.h>
10#include <time.h>
11#include "owl.h"
12
13static const char fileIdent[] = "$Id$";
14
15void owl_message_init(owl_message *m)
16{
17  m->id=owl_global_get_nextmsgid(&g);
18  m->type=OWL_MESSAGE_TYPE_GENERIC;
19  owl_message_set_direction_none(m);
20  m->delete=0;
21  strcpy(m->hostname, "");
22  m->zwriteline=strdup("");
23  m->invalid_format=1;
24
25  owl_list_create(&(m->attributes));
26 
27  /* save the time */
28  m->time=time(NULL);
29  m->timestr=owl_strdup(ctime(&(m->time)));
30  m->timestr[strlen(m->timestr)-1]='\0';
31
32  /* initialize the fmtext */
33  owl_fmtext_init_null(&(m->fmtext));
34}
35
36void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue)
37{
38  /* add the named attribute to the message.  If an attribute with the
39     name already exists, replace the old value with the new value */
40
41  int i, j;
42  owl_pair *p;
43
44  /* look for an existing pair with this key, and nuke the entry if
45     found */
46  j=owl_list_get_size(&(m->attributes));
47  for (i=0; i<j; i++) {
48    p=owl_list_get_element(&(m->attributes), i);
49    if (!strcmp(owl_pair_get_key(p), attrname)) {
50      owl_free(owl_pair_get_key(p));
51      owl_free(owl_pair_get_value(p));
52      owl_free(p);
53      owl_list_remove_element(&(m->attributes), i);
54      break;
55    }
56  }
57
58  p=owl_malloc(sizeof(owl_pair));
59  owl_pair_create(p, owl_strdup(attrname), owl_strdup(attrvalue));
60  owl_list_append_element(&(m->attributes), p);
61}
62
63char *owl_message_get_attribute_value(owl_message *m, char *attrname)
64{
65  /* return the value associated with the named attribute, or NULL if
66     the attribute does not exist */
67  int i, j;
68  owl_pair *p;
69
70  j=owl_list_get_size(&(m->attributes));
71  for (i=0; i<j; i++) {
72    p=owl_list_get_element(&(m->attributes), i);
73    if (!strcmp(owl_pair_get_key(p), attrname)) {
74      return(owl_pair_get_value(p));
75    }
76  }
77
78  /*
79  owl_function_debugmsg("No attribute %s found for message %i",
80                        attrname,
81                        owl_message_get_id(m));
82  */
83  return(NULL);
84}
85
86/* We cheat and indent it for now, since we really want this for
87 * the 'info' function.  Later there should just be a generic
88 * function to indent fmtext.
89 */
90void owl_message_attributes_tofmtext(owl_message *m, owl_fmtext *fm) {
91  int i, j;
92  owl_pair *p;
93  char *buff;
94
95  owl_fmtext_init_null(fm);
96
97  j=owl_list_get_size(&(m->attributes));
98  for (i=0; i<j; i++) {
99    p=owl_list_get_element(&(m->attributes), i);
100    buff=owl_sprintf("  %-15.15s: %-35.35s\n", owl_pair_get_key(p), owl_pair_get_value(p));
101    owl_fmtext_append_normal(fm, buff);
102    owl_free(buff);
103  }
104}
105
106void owl_message_invalidate_format(owl_message *m)
107{
108  m->invalid_format=1;
109}
110
111owl_fmtext *owl_message_get_fmtext(owl_message *m)
112{
113  owl_message_format(m);
114  return(&(m->fmtext));
115}
116
117void owl_message_format(owl_message *m)
118{
119  owl_style *s;
120  owl_view *v;
121
122  if (m->invalid_format) {
123    /* for now we assume there's jsut the one view and use that style */
124    v=owl_global_get_current_view(&g);
125    s=owl_view_get_style(v);
126
127    owl_fmtext_free(&(m->fmtext));
128    owl_fmtext_init_null(&(m->fmtext));
129    owl_style_get_formattext(s, &(m->fmtext), m);
130    m->invalid_format=0;
131  }
132}
133
134void owl_message_set_class(owl_message *m, char *class)
135{
136  owl_message_set_attribute(m, "class", class);
137}
138
139char *owl_message_get_class(owl_message *m)
140{
141  char *class;
142
143  class=owl_message_get_attribute_value(m, "class");
144  if (!class) return("");
145  return(class);
146}
147
148void owl_message_set_instance(owl_message *m, char *inst)
149{
150  owl_message_set_attribute(m, "instance", inst);
151}
152
153char *owl_message_get_instance(owl_message *m)
154{
155  char *instance;
156
157  instance=owl_message_get_attribute_value(m, "instance");
158  if (!instance) return("");
159  return(instance);
160}
161
162void owl_message_set_sender(owl_message *m, char *sender)
163{
164  owl_message_set_attribute(m, "sender", sender);
165}
166
167char *owl_message_get_sender(owl_message *m)
168{
169  char *sender;
170
171  sender=owl_message_get_attribute_value(m, "sender");
172  if (!sender) return("");
173  return(sender);
174}
175
176void owl_message_set_zsig(owl_message *m, char *zsig)
177{
178  owl_message_set_attribute(m, "zsig", zsig);
179}
180
181char *owl_message_get_zsig(owl_message *m)
182{
183  char *zsig;
184
185  zsig=owl_message_get_attribute_value(m, "zsig");
186  if (!zsig) return("");
187  return(zsig);
188}
189
190void owl_message_set_recipient(owl_message *m, char *recip)
191{
192  owl_message_set_attribute(m, "recipient", recip);
193}
194
195char *owl_message_get_recipient(owl_message *m)
196{
197  /* this is stupid for outgoing messages, we need to fix it. */
198
199  char *recip;
200
201  recip=owl_message_get_attribute_value(m, "recipient");
202  if (!recip) return("");
203  return(recip);
204}
205
206void owl_message_set_realm(owl_message *m, char *realm)
207{
208  owl_message_set_attribute(m, "realm", realm);
209}
210
211char *owl_message_get_realm(owl_message *m)
212{
213  char *realm;
214 
215  realm=owl_message_get_attribute_value(m, "realm");
216  if (!realm) return("");
217  return(realm);
218}
219
220void owl_message_set_body(owl_message *m, char *body)
221{
222  owl_message_set_attribute(m, "body", body);
223}
224
225char *owl_message_get_body(owl_message *m)
226{
227  char *body;
228
229  body=owl_message_get_attribute_value(m, "body");
230  if (!body) return("");
231  return(body);
232}
233
234
235void owl_message_set_opcode(owl_message *m, char *opcode)
236{
237  owl_message_set_attribute(m, "opcode", opcode);
238}
239
240char *owl_message_get_opcode(owl_message *m)
241{
242  char *opcode;
243
244  opcode=owl_message_get_attribute_value(m, "opcode");
245  if (!opcode) return("");
246  return(opcode);
247}
248
249
250void owl_message_set_islogin(owl_message *m)
251{
252  owl_message_set_attribute(m, "loginout", "login");
253}
254
255
256void owl_message_set_islogout(owl_message *m)
257{
258  owl_message_set_attribute(m, "loginout", "logout");
259}
260
261int owl_message_is_loginout(owl_message *m)
262{
263  char *res;
264
265  res=owl_message_get_attribute_value(m, "loginout");
266  if (!res) return(0);
267  return(1);
268}
269
270int owl_message_is_login(owl_message *m)
271{
272  char *res;
273
274  res=owl_message_get_attribute_value(m, "loginout");
275  if (!res) return(0);
276  if (!strcmp(res, "login")) return(1);
277  return(0);
278}
279
280
281int owl_message_is_logout(owl_message *m)
282{
283  char *res;
284
285  res=owl_message_get_attribute_value(m, "loginout");
286  if (!res) return(0);
287  if (!strcmp(res, "logout")) return(1);
288  return(0);
289}
290
291void owl_message_set_isprivate(owl_message *m)
292{
293  owl_message_set_attribute(m, "isprivate", "");
294}
295
296int owl_message_is_private(owl_message *m)
297{
298  char *res;
299
300  res=owl_message_get_attribute_value(m, "isprivate");
301  if (!res) return(0);
302  return(1);
303}
304
305char *owl_message_get_timestr(owl_message *m)
306{
307  if (m->timestr) return(m->timestr);
308  return("");
309}
310
311/* caller must free the return */
312char *owl_message_get_shorttimestr(owl_message *m)
313{
314  struct tm *tmstruct;
315  char *out;
316
317  tmstruct=localtime(&(m->time));
318  out=owl_sprintf("%2.2i:%2.2i", tmstruct->tm_hour, tmstruct->tm_min);
319  if (out) return(out);
320  return("??:??");
321}
322
323void owl_message_set_type_admin(owl_message *m)
324{
325  m->type=OWL_MESSAGE_TYPE_ADMIN;
326}
327
328void owl_message_set_type_loopback(owl_message *m)
329{
330  m->type=OWL_MESSAGE_TYPE_LOOPBACK;
331}
332
333void owl_message_set_type_zephyr(owl_message *m)
334{
335  m->type=OWL_MESSAGE_TYPE_ZEPHYR;
336}
337
338void owl_message_set_type_aim(owl_message *m)
339{
340  m->type=OWL_MESSAGE_TYPE_AIM;
341}
342                                               
343int owl_message_is_type_admin(owl_message *m)
344{
345  if (m->type==OWL_MESSAGE_TYPE_ADMIN) return(1);
346  return(0);
347}
348
349int owl_message_is_type_loopback(owl_message *m)
350{
351  if (m->type==OWL_MESSAGE_TYPE_LOOPBACK) return(1);
352  return(0);
353}
354
355int owl_message_is_type_zephyr(owl_message *m)
356{
357  if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return(1);
358  return(0);
359}
360
361int owl_message_is_type_aim(owl_message *m)
362{
363  if (m->type==OWL_MESSAGE_TYPE_AIM) return(1);
364  return(0);
365}
366
367int owl_message_is_type_generic(owl_message *m)
368{
369  if (m->type==OWL_MESSAGE_TYPE_GENERIC) return(1);
370  return(0);
371}
372
373char *owl_message_get_text(owl_message *m)
374{
375  return(owl_fmtext_get_text(&(m->fmtext)));
376}
377
378void owl_message_set_direction_in(owl_message *m)
379{
380  m->direction=OWL_MESSAGE_DIRECTION_IN;
381}
382
383void owl_message_set_direction_out(owl_message *m)
384{
385  m->direction=OWL_MESSAGE_DIRECTION_OUT;
386}
387
388void owl_message_set_direction_none(owl_message *m)
389{
390  m->direction=OWL_MESSAGE_DIRECTION_NONE;
391}
392
393int owl_message_is_direction_in(owl_message *m)
394{
395  if (m->direction==OWL_MESSAGE_DIRECTION_IN) return(1);
396  return(0);
397}
398
399int owl_message_is_direction_out(owl_message *m)
400{
401  if (m->direction==OWL_MESSAGE_DIRECTION_OUT) return(1);
402  return(0);
403}
404
405int owl_message_is_direction_none(owl_message *m)
406{
407  if (m->direction==OWL_MESSAGE_DIRECTION_NONE) return(1);
408  return(0);
409}
410
411int owl_message_get_numlines(owl_message *m)
412{
413  if (m == NULL) return(0);
414  owl_message_format(m);
415  return(owl_fmtext_num_lines(&(m->fmtext)));
416}
417
418void owl_message_mark_delete(owl_message *m)
419{
420  if (m == NULL) return;
421  m->delete=1;
422}
423
424void owl_message_unmark_delete(owl_message *m)
425{
426  if (m == NULL) return;
427  m->delete=0;
428}
429
430char *owl_message_get_zwriteline(owl_message *m)
431{
432  return(m->zwriteline);
433}
434
435void owl_message_set_zwriteline(owl_message *m, char *line)
436{
437  m->zwriteline=strdup(line);
438}
439
440int owl_message_is_delete(owl_message *m)
441{
442  if (m == NULL) return(0);
443  if (m->delete==1) return(1);
444  return(0);
445}
446
447#ifdef HAVE_LIBZEPHYR
448ZNotice_t *owl_message_get_notice(owl_message *m)
449{
450  return(&(m->notice));
451}
452#else
453void *owl_message_get_notice(owl_message *m)
454{
455  return(NULL);
456}
457#endif
458
459char *owl_message_get_hostname(owl_message *m)
460{
461  return(m->hostname);
462}
463
464void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color)
465{
466  owl_fmtext a, b;
467
468  /* this will ensure that our cached copy is up to date */
469  owl_message_format(m);
470
471  owl_fmtext_init_null(&a);
472  owl_fmtext_init_null(&b);
473 
474  owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
475  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
476  if (color!=OWL_COLOR_DEFAULT) {
477    owl_fmtext_colorize(&b, color);
478  }
479
480  if (owl_global_is_search_active(&g)) {
481    owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g));
482  }
483     
484  owl_fmtext_curs_waddstr(&b, win);
485
486  owl_fmtext_free(&a);
487  owl_fmtext_free(&b);
488}
489
490int owl_message_is_personal(owl_message *m)
491{
492  if (owl_message_is_type_zephyr(m)) {
493    if (strcasecmp(owl_message_get_class(m), "message")) return(0);
494    if (strcasecmp(owl_message_get_instance(m), "personal")) return(0);
495    if (!strcasecmp(owl_message_get_recipient(m), owl_zephyr_get_sender()) ||
496        !strcasecmp(owl_message_get_sender(m), owl_zephyr_get_sender())) {
497      return(1);
498    }
499  }
500  return(0);
501}
502
503int owl_message_is_from_me(owl_message *m)
504{
505  if (owl_message_is_type_zephyr(m)) {
506    if (!strcasecmp(owl_message_get_sender(m), owl_zephyr_get_sender())) {
507      return(1);
508    } else {
509      return(0);
510    }
511  } else if (owl_message_is_type_aim(m)) {
512    if (!strcasecmp(owl_message_get_sender(m), owl_global_get_aim_screenname(&g))) {
513      return(1);
514    } else {
515      return(0);
516    }
517  } else if (owl_message_is_type_admin(m)) {
518    return(0);
519  }
520  return(0);
521}
522
523int owl_message_is_mail(owl_message *m)
524{
525  if (owl_message_is_type_zephyr(m)) {
526    if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) {
527      return(1);
528    } else {
529      return(0);
530    }
531  }
532  return(0);
533}
534
535int owl_message_is_ping(owl_message *m)
536{
537  if (owl_message_is_type_zephyr(m)) {
538    if (!strcasecmp(owl_message_get_opcode(m), "ping")) {
539      return(1);
540    } else {
541      return(0);
542    }
543  }
544  return(0);
545}
546
547int owl_message_is_burningears(owl_message *m)
548{
549  /* we should add a global to cache the short zsender */
550  char sender[LINE], *ptr;
551
552  /* if the message is from us or to us, it doesn't count */
553  if (owl_message_is_from_me(m) || owl_message_is_private(m)) return(0);
554
555  if (owl_message_is_type_zephyr(m)) {
556    strcpy(sender, owl_zephyr_get_sender());
557    ptr=strchr(sender, '@');
558    if (ptr) *ptr='\0';
559  } else if (owl_message_is_type_aim(m)) {
560    strcpy(sender, owl_global_get_aim_screenname(&g));
561  } else {
562    return(0);
563  }
564
565  if (stristr(owl_message_get_body(m), sender)) {
566    return(1);
567  }
568  return(0);
569}
570
571/* caller must free return value. */
572char *owl_message_get_cc(owl_message *m)
573{
574  char *cur, *out, *end;
575
576  cur = owl_message_get_body(m);
577  while (*cur && *cur==' ') cur++;
578  if (strncasecmp(cur, "cc:", 3)) return(NULL);
579  cur+=3;
580  while (*cur && *cur==' ') cur++;
581  out = owl_strdup(cur);
582  end = strchr(out, '\n');
583  if (end) end[0] = '\0';
584  return(out);
585}
586
587int owl_message_get_id(owl_message *m)
588{
589  return(m->id);
590}
591
592char *owl_message_get_type(owl_message *m) {
593  switch (m->type) {
594  case OWL_MESSAGE_TYPE_ADMIN:
595    return("admin");
596  case OWL_MESSAGE_TYPE_ZEPHYR:
597    return("zephyr");
598  case OWL_MESSAGE_TYPE_GENERIC:
599    return("generic");
600  case OWL_MESSAGE_TYPE_AIM:
601    return("aim");
602  case OWL_MESSAGE_TYPE_JABBER:
603    return("jabber");
604  case OWL_MESSAGE_TYPE_ICQ:
605    return("icq");
606  case OWL_MESSAGE_TYPE_YAHOO:
607    return("yahoo");
608  case OWL_MESSAGE_TYPE_MSN:
609    return("msn");
610  case OWL_MESSAGE_TYPE_LOOPBACK:
611    return("loopback");
612  default:
613    return("unknown");
614  }
615}
616
617char *owl_message_get_direction(owl_message *m) {
618  switch (m->direction) {
619  case OWL_MESSAGE_DIRECTION_IN:
620    return("in");
621  case OWL_MESSAGE_DIRECTION_OUT:
622    return("out");
623  case OWL_MESSAGE_DIRECTION_NONE:
624    return("none");
625  default:
626    return("unknown");
627  }
628}
629
630char *owl_message_get_login(owl_message *m) {
631  if (owl_message_is_login(m)) {
632    return "login";
633  } else if (owl_message_is_logout(m)) {
634    return "logout";
635  } else {
636    return "none";
637  }
638}
639
640char *owl_message_get_header(owl_message *m) {
641  return owl_message_get_attribute_value(m, "adminheader");
642}
643
644/* return 1 if the message contains "string", 0 otherwise.  This is
645 * case insensitive because the functions it uses are
646 */
647int owl_message_search(owl_message *m, char *string)
648{
649
650  owl_message_format(m); /* is this necessary? */
651 
652  return (owl_fmtext_search(&(m->fmtext), string));
653}
654
655
656/* if loginout == -1 it's a logout message
657 *                 0 it's not a login/logout message
658 *                 1 it's a login message
659 */
660void owl_message_create_aim(owl_message *m, char *sender, char *recipient, char *text, int direction, int loginout)
661{
662  owl_message_init(m);
663  owl_message_set_body(m, text);
664  owl_message_set_sender(m, sender);
665  owl_message_set_recipient(m, recipient);
666  owl_message_set_type_aim(m);
667
668  if (direction==OWL_MESSAGE_DIRECTION_IN) {
669    owl_message_set_direction_in(m);
670  } else if (direction==OWL_MESSAGE_DIRECTION_OUT) {
671    owl_message_set_direction_out(m);
672  }
673
674  /* for now all messages that aren't loginout are private */
675  if (!loginout) {
676    owl_message_set_isprivate(m);
677  }
678
679  if (loginout==-1) {
680    owl_message_set_islogout(m);
681  } else if (loginout==1) {
682    owl_message_set_islogin(m);
683  }
684}
685
686void owl_message_create_admin(owl_message *m, char *header, char *text)
687{
688  owl_message_init(m);
689  owl_message_set_type_admin(m);
690  owl_message_set_body(m, text);
691  owl_message_set_attribute(m, "adminheader", header); /* just a hack for now */
692}
693
694/* caller should set the direction */
695void owl_message_create_loopback(owl_message *m, char *text)
696{
697  owl_message_init(m);
698  owl_message_set_type_loopback(m);
699  owl_message_set_body(m, text);
700  owl_message_set_sender(m, "loopsender");
701  owl_message_set_recipient(m, "looprecip");
702  owl_message_set_isprivate(m);
703}
704
705#ifdef HAVE_LIBZEPHYR
706void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n)
707{
708  struct hostent *hent;
709  int k;
710  char *ptr, *tmp, *tmp2;
711
712  owl_message_init(m);
713 
714  owl_message_set_type_zephyr(m);
715  owl_message_set_direction_in(m);
716 
717  /* first save the full notice */
718  memcpy(&(m->notice), n, sizeof(ZNotice_t));
719
720  /* a little gross, we'll replace \r's with ' ' for now */
721  owl_zephyr_hackaway_cr(&(m->notice));
722 
723  m->delete=0;
724
725  /* save the time, we need to nuke the string saved by message_init */
726  if (m->timestr) {
727    owl_free(m->timestr);
728  }
729  m->time=n->z_time.tv_sec;
730  m->timestr=owl_strdup(ctime(&(m->time)));
731  m->timestr[strlen(m->timestr)-1]='\0';
732
733  /* set other info */
734  owl_message_set_sender(m, n->z_sender);
735  owl_message_set_class(m, n->z_class);
736  owl_message_set_instance(m, n->z_class_inst);
737  owl_message_set_recipient(m, n->z_recipient);
738  if (n->z_opcode) {
739    owl_message_set_opcode(m, n->z_opcode);
740  } else {
741    owl_message_set_opcode(m, "");
742  }
743  owl_message_set_zsig(m, n->z_message);
744
745  if ((ptr=strchr(n->z_recipient, '@'))!=NULL) {
746    owl_message_set_realm(m, ptr+1);
747  } else {
748    owl_message_set_realm(m, owl_zephyr_get_realm());
749  }
750
751  /* Set the "isloginout" attribute if it's a login message */
752  if (!strcasecmp(n->z_class, "login") || !strcasecmp(n->z_class, OWL_WEBZEPHYR_CLASS)) {
753    if (!strcasecmp(n->z_opcode, "user_login")) {
754      owl_message_set_islogin(m);
755    } else if (!strcasecmp(n->z_opcode, "user_logout")) {
756      owl_message_set_islogout(m);
757    }
758  }
759
760  /* is the "isprivate" attribute if it's a private zephyr */
761  if (!strcasecmp(n->z_recipient, owl_zephyr_get_sender())) {
762    owl_message_set_isprivate(m);
763  }
764
765  m->zwriteline=strdup("");
766
767  /* set the body */
768  ptr=owl_zephyr_get_message(n, &k);
769  tmp=owl_malloc(k+10);
770  memcpy(tmp, ptr, k);
771  tmp[k]='\0';
772  if (owl_global_is_newlinestrip(&g)) {
773    tmp2=owl_util_stripnewlines(tmp);
774    owl_message_set_body(m, tmp2);
775    owl_free(tmp2);
776  } else {
777    owl_message_set_body(m, tmp);
778  }
779  owl_free(tmp);
780
781#ifdef OWL_ENABLE_ZCRYPT
782  /* if zcrypt is enabled try to decrypt the message */
783  if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) {
784    char *out;
785    int ret;
786
787    out=owl_malloc(strlen(owl_message_get_body(m))*16+20);
788    ret=owl_zcrypt_decrypt(out, owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m));
789    if (ret==0) {
790      owl_message_set_body(m, out);
791    } else {
792      owl_free(out);
793    }
794  }
795#endif 
796
797  /* save the hostname */
798  owl_function_debugmsg("About to do gethostbyaddr");
799  hent=gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET);
800  if (hent && hent->h_name) {
801    strcpy(m->hostname, hent->h_name);
802  } else {
803    strcpy(m->hostname, inet_ntoa(n->z_sender_addr));
804  }
805}
806#else
807void owl_message_create_from_znotice(owl_message *m, void *n)
808{
809}
810#endif
811
812void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig)
813{
814  owl_zwrite z;
815  int ret;
816 
817  owl_message_init(m);
818
819  /* create a zwrite for the purpose of filling in other message fields */
820  owl_zwrite_create_from_line(&z, line);
821
822  /* set things */
823  owl_message_set_direction_out(m);
824  owl_message_set_type_zephyr(m);
825  owl_message_set_sender(m, owl_zephyr_get_sender());
826  owl_message_set_class(m, owl_zwrite_get_class(&z));
827  owl_message_set_instance(m, owl_zwrite_get_instance(&z));
828  if (owl_zwrite_get_numrecips(&z)>0) {
829    owl_message_set_recipient(m,
830                              long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */
831  }
832  owl_message_set_opcode(m, owl_zwrite_get_opcode(&z));
833  owl_message_set_realm(m, owl_zwrite_get_realm(&z)); /* also a hack, but not here */
834  m->zwriteline=owl_strdup(line);
835  owl_message_set_body(m, body);
836  owl_message_set_zsig(m, zsig);
837 
838  /* save the hostname */
839  ret=gethostname(m->hostname, MAXHOSTNAMELEN);
840  if (ret) {
841    strcpy(m->hostname, "localhost");
842  }
843
844  owl_zwrite_free(&z);
845}
846
847void owl_message_pretty_zsig(owl_message *m, char *buff)
848{
849  /* stick a one line version of the zsig in buff */
850  char *ptr;
851
852  strcpy(buff, owl_message_get_zsig(m));
853  ptr=strchr(buff, '\n');
854  if (ptr) ptr[0]='\0';
855}
856
857void owl_message_free(owl_message *m)
858{
859  int i, j;
860  owl_pair *p;
861#ifdef HAVE_LIBZEPHYR   
862  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
863    ZFreeNotice(&(m->notice));
864  }
865#endif
866  if (m->timestr) owl_free(m->timestr);
867  if (m->zwriteline) owl_free(m->zwriteline);
868
869  /* free all the attributes */
870  j=owl_list_get_size(&(m->attributes));
871  for (i=0; i<j; i++) {
872    p=owl_list_get_element(&(m->attributes), i);
873    owl_free(owl_pair_get_key(p));
874    owl_free(owl_pair_get_value(p));
875    owl_free(p);
876  }
877
878  owl_list_free_simple(&(m->attributes));
879 
880  owl_fmtext_free(&(m->fmtext));
881}
Note: See TracBrowser for help on using the repository browser.