source: stylefunc.c @ bc9436f

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