source: stylefunc.c @ fa00c5c

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