source: stylefunc.c @ db8b00b

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since db8b00b was 789462a, checked in by James M. Kretchmar <kretch@mit.edu>, 20 years ago
Do ntohs() when printing zephyr port in zephyr info
  • Property mode set to 100644
File size: 26.6 KB
Line 
1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
5/* In all of these functions, 'fm' is expected to already be
6 * initialized.
7 */
8   
9void owl_stylefunc_basic(owl_fmtext *fm, owl_message *m)
10{
11#ifdef HAVE_LIBZEPHYR
12  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
13  ZNotice_t *n;
14#endif
15
16  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
17#ifdef HAVE_LIBZEPHYR
18    n=owl_message_get_notice(m);
19 
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, '@');
36    if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
37      *ptr='\0';
38    }
39   
40    /* set the message for printing */
41    owl_fmtext_append_normal(fm, OWL_TABSTR);
42   
43    if (owl_message_is_ping(m)) {
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");
48    } else if (owl_message_is_loginout(m)) {
49      char *host, *tty;
50
51      host=owl_message_get_attribute_value(m, "loginhost");
52      tty=owl_message_get_attribute_value(m, "logintty");
53     
54      if (owl_message_is_login(m)) {
55        owl_fmtext_append_bold(fm, "LOGIN");
56      } else if (owl_message_is_logout(m)) {
57        owl_fmtext_append_bold(fm, "LOGOUT");
58      }
59      if (owl_message_is_pseudo(m)) {
60        owl_fmtext_append_bold(fm, " (PSEUDO)");
61      }
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 ");
67      owl_fmtext_append_normal(fm, host ? host : "");
68      owl_fmtext_append_normal(fm, " ");
69      owl_fmtext_append_normal(fm, tty ? tty : "");
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);
81      if (strcasecmp(owl_message_get_realm(m), owl_zephyr_get_realm())) {
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);
109#endif
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);
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);
214  }
215}
216
217void owl_stylefunc_default(owl_fmtext *fm, owl_message *m)
218{
219  char *shorttimestr;
220#ifdef HAVE_LIBZEPHYR
221  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
222  ZNotice_t *n;
223#endif
224
225  shorttimestr=owl_message_get_shorttimestr(m);
226
227  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
228#ifdef HAVE_LIBZEPHYR
229    n=owl_message_get_notice(m);
230
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, '@');
247    if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
248      *ptr='\0';
249    }
250   
251    /* set the message for printing */
252    owl_fmtext_append_normal(fm, OWL_TABSTR);
253   
254    if (owl_message_is_ping(m) && owl_message_is_private(m)) {
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");
259    } else if (owl_message_is_loginout(m)) {
260      char *host, *tty;
261     
262      host=owl_message_get_attribute_value(m, "loginhost");
263      tty=owl_message_get_attribute_value(m, "logintty");
264     
265      if (owl_message_is_login(m)) {
266        owl_fmtext_append_bold(fm, "LOGIN");
267      } else if (owl_message_is_logout(m)) {
268        owl_fmtext_append_bold(fm, "LOGOUT");
269      }
270
271      if (owl_message_is_pseudo(m)) owl_fmtext_append_bold(fm, " (PSEUDO)");
272       
273      owl_fmtext_append_normal(fm, " for ");
274      ptr=short_zuser(owl_message_get_instance(m));
275      owl_fmtext_append_bold(fm, ptr);
276      owl_free(ptr);
277      owl_fmtext_append_normal(fm, " at ");
278      owl_fmtext_append_normal(fm, host ? host : "");
279      owl_fmtext_append_normal(fm, " ");
280      owl_fmtext_append_normal(fm, tty ? tty : "");
281      owl_fmtext_append_normal(fm, " ");
282      owl_fmtext_append_normal(fm, shorttimestr);
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));
293        owl_fmtext_append_normal(fm, "}");
294      }
295      if (strcmp(owl_message_get_opcode(m), "")) {
296        owl_fmtext_append_normal(fm, " [");
297        owl_fmtext_append_normal(fm, owl_message_get_opcode(m));
298        owl_fmtext_append_normal(fm, "]");
299      }
300
301      owl_fmtext_append_normal(fm, "  ");
302      owl_fmtext_append_normal(fm, shorttimestr);
303
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);
326#endif
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);
339
340    owl_fmtext_append_normal(fm, "  ");
341    owl_fmtext_append_normal(fm, shorttimestr);
342
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));
370      owl_fmtext_append_normal(fm, " ");
371      owl_fmtext_append_normal(fm, shorttimestr);
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));
379     
380      owl_fmtext_append_normal(fm, "  ");
381      owl_fmtext_append_normal(fm, shorttimestr);
382
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));
395      owl_fmtext_append_normal(fm, "  ");
396      owl_fmtext_append_normal(fm, shorttimestr);
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);
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);
435    owl_fmtext_append_normal(fm, "  ");
436    owl_fmtext_append_normal(fm, shorttimestr);
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);
445  }
446  owl_free(shorttimestr);
447}
448
449void owl_stylefunc_oneline(owl_fmtext *fm, owl_message *m)
450{
451  char *tmp;
452  char *baseformat="%s %-13.13s %-11.11s %-12.12s ";
453  char *sender, *recip;
454#ifdef HAVE_LIBZEPHYR
455  ZNotice_t *n;
456#endif
457
458  sender=short_zuser(owl_message_get_sender(m));
459  recip=short_zuser(owl_message_get_recipient(m));
460 
461  if (owl_message_is_type_zephyr(m)) {
462#ifdef HAVE_LIBZEPHYR
463    n=owl_message_get_notice(m);
464   
465    owl_fmtext_append_spaces(fm, OWL_TAB);
466
467    if (owl_message_is_loginout(m)) {
468      char *host, *tty;
469     
470      host=owl_message_get_attribute_value(m, "loginhost");
471      tty=owl_message_get_attribute_value(m, "logintty");
472
473      if (owl_message_is_login(m)) {
474        tmp=owl_sprintf(baseformat, "<", owl_message_is_pseudo(m)?"LOGIN-P":"LOGIN", "", sender);
475        owl_fmtext_append_normal(fm, tmp);
476        owl_free(tmp);
477      } else if (owl_message_is_logout(m)) {
478        tmp=owl_sprintf(baseformat, "<", owl_message_is_pseudo(m)?"LOGOUT-P":"LOGOUT", "", sender);
479        owl_fmtext_append_normal(fm, tmp);
480        owl_free(tmp);
481      }
482
483      owl_fmtext_append_normal(fm, "at ");
484      owl_fmtext_append_normal(fm, host ? host : "");
485      owl_fmtext_append_normal(fm, " ");
486      owl_fmtext_append_normal(fm, tty ? tty : "");
487      owl_fmtext_append_normal(fm, "\n");
488
489    } else if (owl_message_is_ping(m)) {
490      tmp=owl_sprintf(baseformat, "<", "PING", "", sender);
491      owl_fmtext_append_normal(fm, tmp);
492      owl_fmtext_append_normal(fm, "\n");
493      owl_free(tmp);
494
495    } else {
496      if (owl_message_is_direction_in(m)) {
497        tmp=owl_sprintf(baseformat, "<", owl_message_get_class(m), owl_message_get_instance(m), sender);
498      } else if (owl_message_is_direction_out(m)) {
499        tmp=owl_sprintf(baseformat, ">", owl_message_get_class(m), owl_message_get_instance(m), recip);
500      } else {
501        tmp=owl_sprintf(baseformat, "-", owl_message_get_class(m), owl_message_get_instance(m), sender);
502      }
503      owl_fmtext_append_normal(fm, tmp);
504      if (tmp) owl_free(tmp);
505     
506      tmp=owl_strdup(owl_message_get_body(m));
507      owl_text_tr(tmp, '\n', ' ');
508      owl_fmtext_append_ztext(fm, tmp);
509      owl_fmtext_append_normal(fm, "\n");
510      if (tmp) owl_free(tmp);
511    }
512     
513    /* make personal messages bold for smaat users */
514    if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) &&
515        owl_message_is_personal(m) &&
516        owl_message_is_direction_in(m)) {
517      owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
518    }
519
520    owl_free(sender);
521    owl_free(recip);
522#endif
523  } else if (owl_message_is_type_aim(m)) {
524    owl_fmtext_append_spaces(fm, OWL_TAB);
525    if (owl_message_is_login(m)) {
526      tmp=owl_sprintf(baseformat, "<", "AIM LOGIN", "", owl_message_get_sender(m));
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)) {
531      tmp=owl_sprintf(baseformat, "<", "AIM LOGOUT", "", owl_message_get_sender(m));
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)) {
537        tmp=owl_sprintf(baseformat, "<", "AIM", "", owl_message_get_sender(m));
538        owl_fmtext_append_normal(fm, tmp);
539        if (tmp) owl_free(tmp);
540      } else if (owl_message_is_direction_out(m)) {
541        tmp=owl_sprintf(baseformat, ">", "AIM", "", owl_message_get_recipient(m));
542        owl_fmtext_append_normal(fm, tmp);
543        if (tmp) owl_free(tmp);
544      }
545     
546      tmp=owl_strdup(owl_message_get_body(m));
547      owl_text_tr(tmp, '\n', ' ');
548      owl_fmtext_append_normal(fm, tmp);
549      owl_fmtext_append_normal(fm, "\n");
550      if (tmp) owl_free(tmp);
551
552      /* make personal messages bold for smaat users */
553      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) && owl_message_is_direction_in(m)) {
554        owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
555      }
556    }
557  } else if (owl_message_is_type_admin(m)) {
558    owl_fmtext_append_spaces(fm, OWL_TAB);
559    owl_fmtext_append_normal(fm, "< ADMIN                                  ");
560   
561    tmp=owl_strdup(owl_message_get_body(m));
562    owl_text_tr(tmp, '\n', ' ');
563    owl_fmtext_append_normal(fm, tmp);
564    owl_fmtext_append_normal(fm, "\n");
565    if (tmp) owl_free(tmp);
566  } else {
567    owl_fmtext_append_spaces(fm, OWL_TAB);
568    owl_fmtext_append_normal(fm, "< LOOPBACK                               ");
569   
570    tmp=owl_strdup(owl_message_get_body(m));
571    owl_text_tr(tmp, '\n', ' ');
572    owl_fmtext_append_normal(fm, tmp);
573    owl_fmtext_append_normal(fm, "\n");
574    if (tmp) owl_free(tmp);
575  }   
576
577}
578
579void owl_stylefunc_vt(owl_fmtext *fm, owl_message *m)
580{
581#ifdef HAVE_LIBZEPHYR
582  char *body, *indent, *ptr, frombuff[LINE];
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)) {
639      char *host, *tty;
640     
641      host=owl_message_get_attribute_value(m, "loginhost");
642      tty=owl_message_get_attribute_value(m, "logintty");
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      }
649      if (owl_message_is_pseudo(m)) owl_fmtext_append_bold(fm, " (PSEUDO)");
650
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 ");
656      owl_fmtext_append_normal(fm, host ? host : "");
657      owl_fmtext_append_normal(fm, " ");
658      owl_fmtext_append_normal(fm, tty ? tty : "");
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);
776  } else {
777
778  }
779}
Note: See TracBrowser for help on using the repository browser.