[bd3f232] | 1 | #include "owl.h" |
---|
| 2 | |
---|
| 3 | static const char fileIdent[] = "$Id$"; |
---|
| 4 | |
---|
[5639bf2] | 5 | /* In all of these functions, 'fm' is expected to already be |
---|
| 6 | * initialized. |
---|
| 7 | */ |
---|
[bc9436f] | 8 | |
---|
| 9 | void 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] | 68 | void 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)) { |
---|
[9aba27b] | 148 | owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD); |
---|
[bd3f232] | 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 | } |
---|