source: stylefunc.c @ 3405394

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 3405394 was 789462a, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Do ntohs() when printing zephyr port in zephyr info
  • Property mode set to 100644
File size: 26.6 KB
RevLine 
[bd3f232]1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
[5639bf2]5/* In all of these functions, 'fm' is expected to already be
6 * initialized.
7 */
8   
[bd3f232]9void owl_stylefunc_basic(owl_fmtext *fm, owl_message *m)
10{
[09489b89]11#ifdef HAVE_LIBZEPHYR
[bd3f232]12  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
13  ZNotice_t *n;
[09489b89]14#endif
[bd3f232]15
16  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
[09489b89]17#ifdef HAVE_LIBZEPHYR
[bd3f232]18    n=owl_message_get_notice(m);
[09489b89]19 
[bd3f232]20    /* get the body */
21    body=owl_strdup(owl_message_get_body(m));
22    body=realloc(body, strlen(body)+30);
23
24    /* add a newline if we need to */
25    if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
26      strcat(body, "\n");
27    }
28   
29    /* do the indenting into indent */
30    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
31    owl_text_indent(indent, body, OWL_MSGTAB);
32   
33    /* edit the from addr for printing */
34    strcpy(frombuff, owl_message_get_sender(m));
35    ptr=strchr(frombuff, '@');
[09489b89]36    if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
[bd3f232]37      *ptr='\0';
38    }
39   
40    /* set the message for printing */
41    owl_fmtext_append_normal(fm, OWL_TABSTR);
42   
[8b32593]43    if (owl_message_is_ping(m)) {
[bd3f232]44      owl_fmtext_append_bold(fm, "PING");
45      owl_fmtext_append_normal(fm, " from ");
46      owl_fmtext_append_bold(fm, frombuff);
47      owl_fmtext_append_normal(fm, "\n");
[8b32593]48    } else if (owl_message_is_loginout(m)) {
[5a95b69]49      char *host, *tty;
[8b32593]50
[5a95b69]51      host=owl_message_get_attribute_value(m, "loginhost");
52      tty=owl_message_get_attribute_value(m, "logintty");
53     
[8b32593]54      if (owl_message_is_login(m)) {
[bd3f232]55        owl_fmtext_append_bold(fm, "LOGIN");
[8b32593]56      } else if (owl_message_is_logout(m)) {
[bd3f232]57        owl_fmtext_append_bold(fm, "LOGOUT");
58      }
[5a95b69]59      if (owl_message_is_pseudo(m)) {
60        owl_fmtext_append_bold(fm, " (PSEUDO)");
61      }
[bd3f232]62      owl_fmtext_append_normal(fm, " for ");
63      ptr=short_zuser(owl_message_get_instance(m));
64      owl_fmtext_append_bold(fm, ptr);
65      owl_free(ptr);
66      owl_fmtext_append_normal(fm, " at ");
[5a95b69]67      owl_fmtext_append_normal(fm, host ? host : "");
[bd3f232]68      owl_fmtext_append_normal(fm, " ");
[5a95b69]69      owl_fmtext_append_normal(fm, tty ? tty : "");
[bd3f232]70      owl_fmtext_append_normal(fm, "\n");
71    } else {
72      owl_fmtext_append_normal(fm, "From: ");
73      if (strcasecmp(owl_message_get_class(m), "message")) {
74        owl_fmtext_append_normal(fm, "Class ");
75        owl_fmtext_append_normal(fm, owl_message_get_class(m));
76        owl_fmtext_append_normal(fm, " / Instance ");
77        owl_fmtext_append_normal(fm, owl_message_get_instance(m));
78        owl_fmtext_append_normal(fm, " / ");
79      }
80      owl_fmtext_append_normal(fm, frombuff);
[03955f3]81      if (strcasecmp(owl_message_get_realm(m), owl_zephyr_get_realm())) {
[bd3f232]82        owl_fmtext_append_normal(fm, " {");
83        owl_fmtext_append_normal(fm, owl_message_get_realm(m));
84        owl_fmtext_append_normal(fm, "} ");
85      }
86     
87      /* stick on the zsig */
88      zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
89      owl_message_pretty_zsig(m, zsigbuff);
90      owl_fmtext_append_normal(fm, "    (");
91      owl_fmtext_append_ztext(fm, zsigbuff);
92      owl_fmtext_append_normal(fm, ")");
93      owl_fmtext_append_normal(fm, "\n");
94      owl_free(zsigbuff);
95     
96      /* then the indented message */
97      owl_fmtext_append_ztext(fm, indent);
98     
99      /* make personal messages bold for smaat users */
100      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
101        if (owl_message_is_personal(m)) {
102          owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
103        }
104      }
105    }
106   
107    owl_free(body);
108    owl_free(indent);
[09489b89]109#endif
[bd3f232]110  } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) {
111    char *indent, *text, *zsigbuff, *foo;
112     
113    text=owl_message_get_body(m);
114   
115    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
116    owl_text_indent(indent, text, OWL_MSGTAB);
117    owl_fmtext_append_normal(fm, OWL_TABSTR);
118    owl_fmtext_append_normal(fm, "To: ");
119    foo=short_zuser(owl_message_get_recipient(m));
120    owl_fmtext_append_normal(fm, foo);
121    owl_free(foo);
122    owl_fmtext_append_normal(fm, "  (Zsig: ");
123   
124    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
125    owl_message_pretty_zsig(m, zsigbuff);
126    owl_fmtext_append_ztext(fm, zsigbuff);
127    owl_free(zsigbuff);
128   
129    owl_fmtext_append_normal(fm, ")");
130    owl_fmtext_append_normal(fm, "\n");
131    owl_fmtext_append_ztext(fm, indent);
132    if (text[strlen(text)-1]!='\n') {
133      owl_fmtext_append_normal(fm, "\n");
134    }
135   
136    owl_free(indent);
137  } else if (owl_message_is_type_aim(m)) {
138    char *indent;
139   
140    if (owl_message_is_loginout(m)) {
141      owl_fmtext_append_normal(fm, OWL_TABSTR);
142      if (owl_message_is_login(m)) {
143        owl_fmtext_append_bold(fm, "AIM LOGIN");
144      } else {
145        owl_fmtext_append_bold(fm, "AIM LOGOUT");
146      }
147      owl_fmtext_append_normal(fm, " for ");
148      owl_fmtext_append_normal(fm, owl_message_get_sender(m));
149      owl_fmtext_append_normal(fm, "\n");
150    } else if (owl_message_is_direction_in(m)) {
151      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
152      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
153      owl_fmtext_append_bold(fm, OWL_TABSTR);
154      owl_fmtext_append_bold(fm, "AIM from ");
155      owl_fmtext_append_bold(fm, owl_message_get_sender(m));
156      owl_fmtext_append_bold(fm, "\n");
157      owl_fmtext_append_bold(fm, indent);
158      if (indent[strlen(indent)-1]!='\n') {
159        owl_fmtext_append_normal(fm, "\n");
160      }
161      owl_free(indent);
162    } else if (owl_message_is_direction_out(m)) {
163      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
164      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
165      owl_fmtext_append_normal(fm, OWL_TABSTR);
166      owl_fmtext_append_normal(fm, "AIM sent to ");
167      owl_fmtext_append_normal(fm, owl_message_get_recipient(m));
168      owl_fmtext_append_normal(fm, "\n");
169      owl_fmtext_append_ztext(fm, indent);
170      if (indent[strlen(indent)-1]!='\n') {
171        owl_fmtext_append_normal(fm, "\n");
172      }
173      owl_free(indent);
174    }
175  } else if (owl_message_is_type_admin(m)) {
176    char *text, *header, *indent;
177   
178    text=owl_message_get_body(m);
179    header=owl_message_get_attribute_value(m, "adminheader");
180   
181    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
182    owl_text_indent(indent, text, OWL_MSGTAB);
183    owl_fmtext_append_normal(fm, OWL_TABSTR);
184    owl_fmtext_append_bold(fm, "OWL ADMIN ");
185    owl_fmtext_append_ztext(fm, header);
186    owl_fmtext_append_normal(fm, "\n");
187    owl_fmtext_append_ztext(fm, indent);
188    if (text[strlen(text)-1]!='\n') {
189      owl_fmtext_append_normal(fm, "\n");
190    }
191   
192    owl_free(indent);
[37eab7f]193  } else {
194    char *text, *header, *indent;
195   
196    text=owl_message_get_body(m);
197    header=owl_sprintf("%s from: %s to: %s",
198                       owl_message_get_type(m),
199                       owl_message_get_sender(m),
200                       owl_message_get_recipient(m));
201   
202    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
203    owl_text_indent(indent, text, OWL_MSGTAB);
204    owl_fmtext_append_normal(fm, OWL_TABSTR);
205    owl_fmtext_append_normal(fm, header);
206    owl_fmtext_append_normal(fm, "\n");
207    owl_fmtext_append_normal(fm, indent);
208    if (text[strlen(text)-1]!='\n') {
209      owl_fmtext_append_normal(fm, "\n");
210    }
211   
212    owl_free(indent);
213    owl_free(header);
[bd3f232]214  }
215}
216
217void owl_stylefunc_default(owl_fmtext *fm, owl_message *m)
218{
[25dd31a]219  char *shorttimestr;
[09489b89]220#ifdef HAVE_LIBZEPHYR
[bd3f232]221  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
222  ZNotice_t *n;
[09489b89]223#endif
[bd3f232]224
[25dd31a]225  shorttimestr=owl_message_get_shorttimestr(m);
226
[bd3f232]227  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
[09489b89]228#ifdef HAVE_LIBZEPHYR
[bd3f232]229    n=owl_message_get_notice(m);
[09489b89]230
[bd3f232]231    /* get the body */
232    body=owl_malloc(strlen(owl_message_get_body(m))+30);
233    strcpy(body, owl_message_get_body(m));
234   
235    /* add a newline if we need to */
236    if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
237      strcat(body, "\n");
238    }
239   
240    /* do the indenting into indent */
241    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
242    owl_text_indent(indent, body, OWL_MSGTAB);
243   
244    /* edit the from addr for printing */
245    strcpy(frombuff, owl_message_get_sender(m));
246    ptr=strchr(frombuff, '@');
[09489b89]247    if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
[bd3f232]248      *ptr='\0';
249    }
250   
251    /* set the message for printing */
252    owl_fmtext_append_normal(fm, OWL_TABSTR);
253   
[8b32593]254    if (owl_message_is_ping(m) && owl_message_is_private(m)) {
[bd3f232]255      owl_fmtext_append_bold(fm, "PING");
256      owl_fmtext_append_normal(fm, " from ");
257      owl_fmtext_append_bold(fm, frombuff);
258      owl_fmtext_append_normal(fm, "\n");
[8b32593]259    } else if (owl_message_is_loginout(m)) {
[5a95b69]260      char *host, *tty;
261     
262      host=owl_message_get_attribute_value(m, "loginhost");
263      tty=owl_message_get_attribute_value(m, "logintty");
[bd3f232]264     
[8b32593]265      if (owl_message_is_login(m)) {
[bd3f232]266        owl_fmtext_append_bold(fm, "LOGIN");
[8b32593]267      } else if (owl_message_is_logout(m)) {
[bd3f232]268        owl_fmtext_append_bold(fm, "LOGOUT");
269      }
[5a95b69]270
271      if (owl_message_is_pseudo(m)) owl_fmtext_append_bold(fm, " (PSEUDO)");
272       
[bd3f232]273      owl_fmtext_append_normal(fm, " for ");
[03955f3]274      ptr=short_zuser(owl_message_get_instance(m));
[bd3f232]275      owl_fmtext_append_bold(fm, ptr);
276      owl_free(ptr);
277      owl_fmtext_append_normal(fm, " at ");
[5a95b69]278      owl_fmtext_append_normal(fm, host ? host : "");
[bd3f232]279      owl_fmtext_append_normal(fm, " ");
[5a95b69]280      owl_fmtext_append_normal(fm, tty ? tty : "");
[c7041b3]281      owl_fmtext_append_normal(fm, " ");
282      owl_fmtext_append_normal(fm, shorttimestr);
[bd3f232]283      owl_fmtext_append_normal(fm, "\n");
284    } else {
285      owl_fmtext_append_normal(fm, owl_message_get_class(m));
286      owl_fmtext_append_normal(fm, " / ");
287      owl_fmtext_append_normal(fm, owl_message_get_instance(m));
288      owl_fmtext_append_normal(fm, " / ");
289      owl_fmtext_append_bold(fm, frombuff);
290      if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {
291        owl_fmtext_append_normal(fm, " {");
292        owl_fmtext_append_normal(fm, owl_message_get_realm(m));
[25dd31a]293        owl_fmtext_append_normal(fm, "}");
[bd3f232]294      }
[03955f3]295      if (strcmp(owl_message_get_opcode(m), "")) {
[bd3f232]296        owl_fmtext_append_normal(fm, " [");
297        owl_fmtext_append_normal(fm, owl_message_get_opcode(m));
[25dd31a]298        owl_fmtext_append_normal(fm, "]");
[bd3f232]299      }
[25dd31a]300
301      owl_fmtext_append_normal(fm, "  ");
302      owl_fmtext_append_normal(fm, shorttimestr);
303
[bd3f232]304      /* stick on the zsig */
305      zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
306      owl_message_pretty_zsig(m, zsigbuff);
307      owl_fmtext_append_normal(fm, "    (");
308      owl_fmtext_append_ztext(fm, zsigbuff);
309      owl_fmtext_append_normal(fm, ")");
310      owl_fmtext_append_normal(fm, "\n");
311      owl_free(zsigbuff);
312     
313      /* then the indented message */
314      owl_fmtext_append_ztext(fm, indent);
315     
316      /* make private messages bold for smaat users */
317      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
318        if (owl_message_is_personal(m)) {
319          owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
320        }
321      }
322    }
323   
324    owl_free(body);
325    owl_free(indent);
[09489b89]326#endif
[bd3f232]327  } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) {
328    char *indent, *text, *zsigbuff, *foo;
329   
330    text=owl_message_get_body(m);
331   
332    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
333    owl_text_indent(indent, text, OWL_MSGTAB);
334    owl_fmtext_append_normal(fm, OWL_TABSTR);
335    owl_fmtext_append_normal(fm, "Zephyr sent to ");
336    foo=short_zuser(owl_message_get_recipient(m));
337    owl_fmtext_append_normal(fm, foo);
338    owl_free(foo);
[25dd31a]339
340    owl_fmtext_append_normal(fm, "  ");
341    owl_fmtext_append_normal(fm, shorttimestr);
342
[bd3f232]343    owl_fmtext_append_normal(fm, "  (Zsig: ");
344   
345    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
346    owl_message_pretty_zsig(m, zsigbuff);
347    owl_fmtext_append_ztext(fm, zsigbuff);
348    owl_free(zsigbuff);
349   
350    owl_fmtext_append_normal(fm, ")");
351    owl_fmtext_append_normal(fm, "\n");
352    owl_fmtext_append_ztext(fm, indent);
353    if (text[strlen(text)-1]!='\n') {
354      owl_fmtext_append_normal(fm, "\n");
355    }
356   
357    owl_free(indent);
358  } else if (owl_message_is_type_aim(m)) {
359    char *indent;
360   
361    if (owl_message_is_loginout(m)) {
362      owl_fmtext_append_normal(fm, OWL_TABSTR);
363      if (owl_message_is_login(m)) {
364        owl_fmtext_append_bold(fm, "AIM LOGIN");
365      } else {
366        owl_fmtext_append_bold(fm, "AIM LOGOUT");
367      }
368      owl_fmtext_append_normal(fm, " for ");
369      owl_fmtext_append_normal(fm, owl_message_get_sender(m));
[c7041b3]370      owl_fmtext_append_normal(fm, " ");
371      owl_fmtext_append_normal(fm, shorttimestr);
[bd3f232]372      owl_fmtext_append_normal(fm, "\n");
373    } else if (owl_message_is_direction_in(m)) {
374      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
375      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
376      owl_fmtext_append_bold(fm, OWL_TABSTR);
377      owl_fmtext_append_bold(fm, "AIM from ");
378      owl_fmtext_append_bold(fm, owl_message_get_sender(m));
[25dd31a]379     
380      owl_fmtext_append_normal(fm, "  ");
381      owl_fmtext_append_normal(fm, shorttimestr);
382
[bd3f232]383      owl_fmtext_append_bold(fm, "\n");
384      owl_fmtext_append_bold(fm, indent);
385      if (indent[strlen(indent)-1]!='\n') {
386        owl_fmtext_append_normal(fm, "\n");
387      }
388      owl_free(indent);
389    } else if (owl_message_is_direction_out(m)) {
390      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
391      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
392      owl_fmtext_append_normal(fm, OWL_TABSTR);
393      owl_fmtext_append_normal(fm, "AIM sent to ");
394      owl_fmtext_append_normal(fm, owl_message_get_recipient(m));
[25dd31a]395      owl_fmtext_append_normal(fm, "  ");
396      owl_fmtext_append_normal(fm, shorttimestr);
[bd3f232]397      owl_fmtext_append_normal(fm, "\n");
398      owl_fmtext_append_ztext(fm, indent);
399      if (indent[strlen(indent)-1]!='\n') {
400        owl_fmtext_append_normal(fm, "\n");
401      }
402      owl_free(indent);
403    }
404  } else if (owl_message_is_type_admin(m)) {
405    char *text, *header, *indent;
406   
407    text=owl_message_get_body(m);
408    header=owl_message_get_attribute_value(m, "adminheader");
409   
410    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
411    owl_text_indent(indent, text, OWL_MSGTAB);
412    owl_fmtext_append_normal(fm, OWL_TABSTR);
413    owl_fmtext_append_bold(fm, "OWL ADMIN ");
414    owl_fmtext_append_ztext(fm, header);
415    owl_fmtext_append_normal(fm, "\n");
416    owl_fmtext_append_ztext(fm, indent);
417    if (text[strlen(text)-1]!='\n') {
418      owl_fmtext_append_normal(fm, "\n");
419    }
420   
421    owl_free(indent);
[37eab7f]422  } else {
423    char *text, *header, *indent;
424   
425    text=owl_message_get_body(m);
426    header=owl_sprintf("%s from: %s to: %s",
427                       owl_message_get_type(m),
428                       owl_message_get_sender(m),
429                       owl_message_get_recipient(m));
430   
431    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
432    owl_text_indent(indent, text, OWL_MSGTAB);
433    owl_fmtext_append_normal(fm, OWL_TABSTR);
434    owl_fmtext_append_normal(fm, header);
[25dd31a]435    owl_fmtext_append_normal(fm, "  ");
436    owl_fmtext_append_normal(fm, shorttimestr);
[37eab7f]437    owl_fmtext_append_normal(fm, "\n");
438    owl_fmtext_append_normal(fm, indent);
439    if (text[strlen(text)-1]!='\n') {
440      owl_fmtext_append_normal(fm, "\n");
441    }
442   
443    owl_free(indent);
444    owl_free(header);
[bd3f232]445  }
[25dd31a]446  owl_free(shorttimestr);
[bd3f232]447}
[8b32593]448
449void owl_stylefunc_oneline(owl_fmtext *fm, owl_message *m)
450{
451  char *tmp;
[5ea6fea]452  char *baseformat="%s %-13.13s %-11.11s %-12.12s ";
453  char *sender, *recip;
[09489b89]454#ifdef HAVE_LIBZEPHYR
[778d0a9]455  ZNotice_t *n;
[09489b89]456#endif
[8b32593]457
[5ea6fea]458  sender=short_zuser(owl_message_get_sender(m));
459  recip=short_zuser(owl_message_get_recipient(m));
460 
[8b32593]461  if (owl_message_is_type_zephyr(m)) {
[09489b89]462#ifdef HAVE_LIBZEPHYR
[778d0a9]463    n=owl_message_get_notice(m);
464   
[8b32593]465    owl_fmtext_append_spaces(fm, OWL_TAB);
[778d0a9]466
467    if (owl_message_is_loginout(m)) {
[5a95b69]468      char *host, *tty;
[778d0a9]469     
[5a95b69]470      host=owl_message_get_attribute_value(m, "loginhost");
471      tty=owl_message_get_attribute_value(m, "logintty");
[778d0a9]472
473      if (owl_message_is_login(m)) {
[5a95b69]474        tmp=owl_sprintf(baseformat, "<", owl_message_is_pseudo(m)?"LOGIN-P":"LOGIN", "", sender);
[778d0a9]475        owl_fmtext_append_normal(fm, tmp);
476        owl_free(tmp);
477      } else if (owl_message_is_logout(m)) {
[5a95b69]478        tmp=owl_sprintf(baseformat, "<", owl_message_is_pseudo(m)?"LOGOUT-P":"LOGOUT", "", sender);
[778d0a9]479        owl_fmtext_append_normal(fm, tmp);
480        owl_free(tmp);
481      }
482
483      owl_fmtext_append_normal(fm, "at ");
[5a95b69]484      owl_fmtext_append_normal(fm, host ? host : "");
[778d0a9]485      owl_fmtext_append_normal(fm, " ");
[5a95b69]486      owl_fmtext_append_normal(fm, tty ? tty : "");
[8b32593]487      owl_fmtext_append_normal(fm, "\n");
[778d0a9]488
[8b32593]489    } else if (owl_message_is_ping(m)) {
[5ea6fea]490      tmp=owl_sprintf(baseformat, "<", "PING", "", sender);
[8b32593]491      owl_fmtext_append_normal(fm, tmp);
492      owl_fmtext_append_normal(fm, "\n");
[5ea6fea]493      owl_free(tmp);
[778d0a9]494
[8b32593]495    } else {
496      if (owl_message_is_direction_in(m)) {
[5ea6fea]497        tmp=owl_sprintf(baseformat, "<", owl_message_get_class(m), owl_message_get_instance(m), sender);
[8b32593]498      } else if (owl_message_is_direction_out(m)) {
[5ea6fea]499        tmp=owl_sprintf(baseformat, ">", owl_message_get_class(m), owl_message_get_instance(m), recip);
[8b32593]500      } else {
[5ea6fea]501        tmp=owl_sprintf(baseformat, "-", owl_message_get_class(m), owl_message_get_instance(m), sender);
[8b32593]502      }
503      owl_fmtext_append_normal(fm, tmp);
504      if (tmp) owl_free(tmp);
505     
506      tmp=owl_strdup(owl_message_get_body(m));
[e3d9c77]507      owl_text_tr(tmp, '\n', ' ');
[65e3901]508      owl_fmtext_append_ztext(fm, tmp);
[8b32593]509      owl_fmtext_append_normal(fm, "\n");
510      if (tmp) owl_free(tmp);
511    }
512     
513    /* make personal messages bold for smaat users */
[c3ab155]514    if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) &&
515        owl_message_is_personal(m) &&
516        owl_message_is_direction_in(m)) {
[8b32593]517      owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
518    }
[5ea6fea]519
520    owl_free(sender);
521    owl_free(recip);
[09489b89]522#endif
[8b32593]523  } else if (owl_message_is_type_aim(m)) {
524    owl_fmtext_append_spaces(fm, OWL_TAB);
525    if (owl_message_is_login(m)) {
[5ea6fea]526      tmp=owl_sprintf(baseformat, "<", "AIM LOGIN", "", owl_message_get_sender(m));
[8b32593]527      owl_fmtext_append_normal(fm, tmp);
528      owl_fmtext_append_normal(fm, "\n");
529      if (tmp) owl_free(tmp);
530    } else if (owl_message_is_logout(m)) {
[5ea6fea]531      tmp=owl_sprintf(baseformat, "<", "AIM LOGOUT", "", owl_message_get_sender(m));
[8b32593]532      owl_fmtext_append_normal(fm, tmp);
533      owl_fmtext_append_normal(fm, "\n");
534      if (tmp) owl_free(tmp);
535    } else {
536      if (owl_message_is_direction_in(m)) {
[5ea6fea]537        tmp=owl_sprintf(baseformat, "<", "AIM", "", owl_message_get_sender(m));
[8b32593]538        owl_fmtext_append_normal(fm, tmp);
539        if (tmp) owl_free(tmp);
540      } else if (owl_message_is_direction_out(m)) {
[5ea6fea]541        tmp=owl_sprintf(baseformat, ">", "AIM", "", owl_message_get_recipient(m));
[8b32593]542        owl_fmtext_append_normal(fm, tmp);
543        if (tmp) owl_free(tmp);
544      }
545     
546      tmp=owl_strdup(owl_message_get_body(m));
[e3d9c77]547      owl_text_tr(tmp, '\n', ' ');
[8b32593]548      owl_fmtext_append_normal(fm, tmp);
549      owl_fmtext_append_normal(fm, "\n");
550      if (tmp) owl_free(tmp);
551
[0c502e9]552      /* make personal messages bold for smaat users */
[9c4ec91]553      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) && owl_message_is_direction_in(m)) {
[0c502e9]554        owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
555      }
[8b32593]556    }
557  } else if (owl_message_is_type_admin(m)) {
558    owl_fmtext_append_spaces(fm, OWL_TAB);
[97cd00be]559    owl_fmtext_append_normal(fm, "< ADMIN                                  ");
[8b32593]560   
561    tmp=owl_strdup(owl_message_get_body(m));
[e3d9c77]562    owl_text_tr(tmp, '\n', ' ');
[8b32593]563    owl_fmtext_append_normal(fm, tmp);
564    owl_fmtext_append_normal(fm, "\n");
565    if (tmp) owl_free(tmp);
[37eab7f]566  } else {
567    owl_fmtext_append_spaces(fm, OWL_TAB);
[97cd00be]568    owl_fmtext_append_normal(fm, "< LOOPBACK                               ");
[37eab7f]569   
570    tmp=owl_strdup(owl_message_get_body(m));
[e3d9c77]571    owl_text_tr(tmp, '\n', ' ');
[37eab7f]572    owl_fmtext_append_normal(fm, tmp);
573    owl_fmtext_append_normal(fm, "\n");
574    if (tmp) owl_free(tmp);
575  }   
[8b32593]576
577}
[ec6ff52]578
579void owl_stylefunc_vt(owl_fmtext *fm, owl_message *m)
580{
581#ifdef HAVE_LIBZEPHYR
[789462a]582  char *body, *indent, *ptr, frombuff[LINE];
[ec6ff52]583  owl_fmtext fm_first, fm_other, fm_tmp;
584  ZNotice_t *n;
585#endif
586  char *sender, *hostname, *timestr, *classinst1, *classinst2;
587
588  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
589#ifdef HAVE_LIBZEPHYR
590    n=owl_message_get_notice(m);
591
592    /* get the body */
593    body=owl_malloc(strlen(owl_message_get_body(m))+30);
594    strcpy(body, owl_message_get_body(m));
595   
596    /* add a newline if we need to */
597    if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
598      strcat(body, "\n");
599    }
600
601    owl_fmtext_init_null(&fm_tmp);
602    owl_fmtext_append_ztext(&fm_tmp, body);
603    owl_fmtext_init_null(&fm_first);
604    owl_fmtext_truncate_lines(&fm_tmp, 0, 1, &fm_first);
605
606    /* do the indenting into indent */
607    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
608    owl_text_indent(indent, body, 31);
609
610    owl_fmtext_free(&fm_tmp);
611    owl_fmtext_init_null(&fm_tmp);
612    owl_fmtext_append_ztext(&fm_tmp, indent);
613    owl_fmtext_init_null(&fm_other);
614    owl_fmtext_truncate_lines(&fm_tmp, 1, owl_fmtext_num_lines(&fm_tmp)-1, &fm_other);
615    owl_fmtext_free(&fm_tmp);
616   
617    /* edit the from addr for printing */
618    strcpy(frombuff, owl_message_get_sender(m));
619    ptr=strchr(frombuff, '@');
620    if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
621      *ptr='\0';
622    }
623    sender=owl_sprintf("%-9.9s", frombuff);
624
625    hostname=owl_sprintf("%-9.9s", owl_message_get_hostname(m));
626    timestr=owl_strdup("00:00");
627    classinst1=owl_sprintf("<%s>[%s]", owl_message_get_class(m), owl_message_get_instance(m));
628    classinst2=owl_sprintf("%-9.9s", classinst1);
629   
630    /* set the message for printing */
631    owl_fmtext_append_normal(fm, OWL_TABSTR);
632   
633    if (owl_message_is_ping(m) && owl_message_is_private(m)) {
634      owl_fmtext_append_bold(fm, "PING");
635      owl_fmtext_append_normal(fm, " from ");
636      owl_fmtext_append_bold(fm, frombuff);
637      owl_fmtext_append_normal(fm, "\n");
638    } else if (owl_message_is_loginout(m)) {
[5a95b69]639      char *host, *tty;
640     
641      host=owl_message_get_attribute_value(m, "loginhost");
642      tty=owl_message_get_attribute_value(m, "logintty");
[ec6ff52]643     
644      if (owl_message_is_login(m)) {
645        owl_fmtext_append_bold(fm, "LOGIN");
646      } else if (owl_message_is_logout(m)) {
647        owl_fmtext_append_bold(fm, "LOGOUT");
648      }
[5a95b69]649      if (owl_message_is_pseudo(m)) owl_fmtext_append_bold(fm, " (PSEUDO)");
650
[ec6ff52]651      owl_fmtext_append_normal(fm, " for ");
652      ptr=short_zuser(owl_message_get_instance(m));
653      owl_fmtext_append_bold(fm, ptr);
654      owl_free(ptr);
655      owl_fmtext_append_normal(fm, " at ");
[5a95b69]656      owl_fmtext_append_normal(fm, host ? host : "");
[ec6ff52]657      owl_fmtext_append_normal(fm, " ");
[5a95b69]658      owl_fmtext_append_normal(fm, tty ? tty : "");
[ec6ff52]659      owl_fmtext_append_normal(fm, "\n");
660    } else {
661      owl_fmtext_append_normal(fm, sender);
662      owl_fmtext_append_normal(fm, "|");
663      owl_fmtext_append_normal(fm, hostname);
664      owl_fmtext_append_normal(fm, " ");
665      owl_fmtext_append_normal(fm, timestr);
666      owl_fmtext_append_normal(fm, " ");
667      owl_fmtext_append_normal(fm, classinst2);
668
669      owl_fmtext_append_normal(fm, "   ");
670      owl_fmtext_append_fmtext(fm, &fm_first);
671      owl_fmtext_append_fmtext(fm, &fm_other);
672
673      owl_fmtext_free(&fm_other);
674      owl_fmtext_free(&fm_first);
675     
676      /* make private messages bold for smaat users */
677      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
678        if (owl_message_is_personal(m)) {
679          owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
680        }
681      }
682    }
683
684    owl_free(sender);
685    owl_free(hostname);
686    owl_free(timestr);
687    owl_free(classinst1);
688    owl_free(classinst2);
689   
690    owl_free(body);
691    owl_free(indent);
692#endif
693  } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) {
694    char *indent, *text, *zsigbuff, *foo;
695   
696    text=owl_message_get_body(m);
697   
698    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
699    owl_text_indent(indent, text, OWL_MSGTAB);
700    owl_fmtext_append_normal(fm, OWL_TABSTR);
701    owl_fmtext_append_normal(fm, "Zephyr sent to ");
702    foo=short_zuser(owl_message_get_recipient(m));
703    owl_fmtext_append_normal(fm, foo);
704    owl_free(foo);
705    owl_fmtext_append_normal(fm, "  (Zsig: ");
706   
707    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
708    owl_message_pretty_zsig(m, zsigbuff);
709    owl_fmtext_append_ztext(fm, zsigbuff);
710    owl_free(zsigbuff);
711   
712    owl_fmtext_append_normal(fm, ")");
713    owl_fmtext_append_normal(fm, "\n");
714    owl_fmtext_append_ztext(fm, indent);
715    if (text[strlen(text)-1]!='\n') {
716      owl_fmtext_append_normal(fm, "\n");
717    }
718   
719    owl_free(indent);
720  } else if (owl_message_is_type_aim(m)) {
721    char *indent;
722   
723    if (owl_message_is_loginout(m)) {
724      owl_fmtext_append_normal(fm, OWL_TABSTR);
725      if (owl_message_is_login(m)) {
726        owl_fmtext_append_bold(fm, "AIM LOGIN");
727      } else {
728        owl_fmtext_append_bold(fm, "AIM LOGOUT");
729      }
730      owl_fmtext_append_normal(fm, " for ");
731      owl_fmtext_append_normal(fm, owl_message_get_sender(m));
732      owl_fmtext_append_normal(fm, "\n");
733    } else if (owl_message_is_direction_in(m)) {
734      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
735      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
736      owl_fmtext_append_bold(fm, OWL_TABSTR);
737      owl_fmtext_append_bold(fm, "AIM from ");
738      owl_fmtext_append_bold(fm, owl_message_get_sender(m));
739      owl_fmtext_append_bold(fm, "\n");
740      owl_fmtext_append_bold(fm, indent);
741      if (indent[strlen(indent)-1]!='\n') {
742        owl_fmtext_append_normal(fm, "\n");
743      }
744      owl_free(indent);
745    } else if (owl_message_is_direction_out(m)) {
746      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
747      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
748      owl_fmtext_append_normal(fm, OWL_TABSTR);
749      owl_fmtext_append_normal(fm, "AIM sent to ");
750      owl_fmtext_append_normal(fm, owl_message_get_recipient(m));
751      owl_fmtext_append_normal(fm, "\n");
752      owl_fmtext_append_ztext(fm, indent);
753      if (indent[strlen(indent)-1]!='\n') {
754        owl_fmtext_append_normal(fm, "\n");
755      }
756      owl_free(indent);
757    }
758  } else if (owl_message_is_type_admin(m)) {
759    char *text, *header, *indent;
760   
761    text=owl_message_get_body(m);
762    header=owl_message_get_attribute_value(m, "adminheader");
763   
764    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
765    owl_text_indent(indent, text, OWL_MSGTAB);
766    owl_fmtext_append_normal(fm, OWL_TABSTR);
767    owl_fmtext_append_bold(fm, "OWL ADMIN ");
768    owl_fmtext_append_ztext(fm, header);
769    owl_fmtext_append_normal(fm, "\n");
770    owl_fmtext_append_ztext(fm, indent);
771    if (text[strlen(text)-1]!='\n') {
772      owl_fmtext_append_normal(fm, "\n");
773    }
774   
775    owl_free(indent);
[37eab7f]776  } else {
777
[ec6ff52]778  }
779}
Note: See TracBrowser for help on using the repository browser.