source: stylefunc.c @ d08162a

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