[7d4fbcd] | 1 | #include <zephyr/zephyr.h> |
---|
| 2 | #include <stdlib.h> |
---|
[b45293f] | 3 | #include <unistd.h> |
---|
[7d4fbcd] | 4 | #include <string.h> |
---|
| 5 | #include <sys/socket.h> |
---|
| 6 | #include <netdb.h> |
---|
| 7 | #include <sys/types.h> |
---|
| 8 | #include <sys/socket.h> |
---|
| 9 | #include <netinet/in.h> |
---|
| 10 | #include <arpa/inet.h> |
---|
| 11 | #include <time.h> |
---|
| 12 | #include "owl.h" |
---|
| 13 | |
---|
[1aee7d9] | 14 | static const char fileIdent[] = "$Id$"; |
---|
| 15 | |
---|
[d0d65df] | 16 | void owl_message_init(owl_message *m) { |
---|
[7d4fbcd] | 17 | time_t t; |
---|
| 18 | |
---|
| 19 | m->id=owl_global_get_nextmsgid(&g); |
---|
[4b464a4] | 20 | m->type=OWL_MESSAGE_TYPE_GENERIC; |
---|
| 21 | owl_message_set_direction_none(m); |
---|
[7d4fbcd] | 22 | m->delete=0; |
---|
| 23 | strcpy(m->hostname, ""); |
---|
| 24 | m->zwriteline=strdup(""); |
---|
| 25 | |
---|
[d0d65df] | 26 | owl_list_create(&(m->attributes)); |
---|
| 27 | |
---|
[7d4fbcd] | 28 | /* save the time */ |
---|
| 29 | t=time(NULL); |
---|
| 30 | m->time=owl_strdup(ctime(&t)); |
---|
| 31 | m->time[strlen(m->time)-1]='\0'; |
---|
[4b464a4] | 32 | } |
---|
| 33 | |
---|
[d0d65df] | 34 | void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue) { |
---|
| 35 | /* add the named attribute to the message. If an attribute with the |
---|
| 36 | name already exists, replace the old value with the new value */ |
---|
| 37 | |
---|
| 38 | int i, j; |
---|
| 39 | owl_pair *p; |
---|
| 40 | |
---|
| 41 | /* look for an existing pair with this key, and nuke the entry if |
---|
| 42 | found */ |
---|
| 43 | j=owl_list_get_size(&(m->attributes)); |
---|
| 44 | for (i=0; i<j; i++) { |
---|
| 45 | p=owl_list_get_element(&(m->attributes), i); |
---|
| 46 | if (!strcmp(owl_pair_get_key(p), attrname)) { |
---|
| 47 | owl_free(owl_pair_get_key(p)); |
---|
| 48 | owl_free(owl_pair_get_value(p)); |
---|
| 49 | owl_free(p); |
---|
| 50 | owl_list_remove_element(&(m->attributes), i); |
---|
| 51 | break; |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | p=owl_malloc(sizeof(owl_pair)); |
---|
| 56 | owl_pair_create(p, owl_strdup(attrname), owl_strdup(attrvalue)); |
---|
| 57 | owl_list_append_element(&(m->attributes), p); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | char *owl_message_get_attribute_value(owl_message *m, char *attrname) { |
---|
| 61 | /* return the value associated with the named attribute, or NULL if |
---|
| 62 | the attribute does not exist */ |
---|
| 63 | int i, j; |
---|
| 64 | owl_pair *p; |
---|
| 65 | |
---|
| 66 | j=owl_list_get_size(&(m->attributes)); |
---|
| 67 | for (i=0; i<j; i++) { |
---|
| 68 | p=owl_list_get_element(&(m->attributes), i); |
---|
| 69 | if (!strcmp(owl_pair_get_key(p), attrname)) { |
---|
| 70 | return(owl_pair_get_value(p)); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | owl_function_debugmsg("No attribute %s found", attrname); |
---|
| 74 | return(NULL); |
---|
| 75 | } |
---|
| 76 | |
---|
[4b464a4] | 77 | |
---|
| 78 | owl_fmtext *owl_message_get_fmtext(owl_message *m) { |
---|
| 79 | return(&(m->fmtext)); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | void owl_message_set_class(owl_message *m, char *class) { |
---|
[d0d65df] | 83 | owl_message_set_attribute(m, "class", class); |
---|
[4b464a4] | 84 | } |
---|
| 85 | |
---|
| 86 | char *owl_message_get_class(owl_message *m) { |
---|
[d0d65df] | 87 | char *class; |
---|
| 88 | |
---|
| 89 | class=owl_message_get_attribute_value(m, "class"); |
---|
| 90 | if (!class) return(""); |
---|
| 91 | return(class); |
---|
[4b464a4] | 92 | } |
---|
| 93 | |
---|
| 94 | void owl_message_set_instance(owl_message *m, char *inst) { |
---|
[d0d65df] | 95 | owl_message_set_attribute(m, "instance", inst); |
---|
[4b464a4] | 96 | } |
---|
| 97 | |
---|
| 98 | char *owl_message_get_instance(owl_message *m) { |
---|
[d0d65df] | 99 | char *instance; |
---|
| 100 | |
---|
| 101 | instance=owl_message_get_attribute_value(m, "instance"); |
---|
| 102 | if (!instance) return(""); |
---|
| 103 | return(instance); |
---|
[4b464a4] | 104 | } |
---|
| 105 | |
---|
| 106 | void owl_message_set_sender(owl_message *m, char *sender) { |
---|
[d0d65df] | 107 | owl_message_set_attribute(m, "sender", sender); |
---|
[4b464a4] | 108 | } |
---|
| 109 | |
---|
| 110 | char *owl_message_get_sender(owl_message *m) { |
---|
[d0d65df] | 111 | char *sender; |
---|
| 112 | |
---|
| 113 | sender=owl_message_get_attribute_value(m, "sender"); |
---|
| 114 | if (!sender) return(""); |
---|
| 115 | return(sender); |
---|
[4b464a4] | 116 | } |
---|
| 117 | |
---|
[b45293f] | 118 | void owl_message_set_zsig(owl_message *m, char *zsig) { |
---|
[d0d65df] | 119 | owl_message_set_attribute(m, "zsig", zsig); |
---|
[b45293f] | 120 | } |
---|
| 121 | |
---|
| 122 | char *owl_message_get_zsig(owl_message *m) { |
---|
[d0d65df] | 123 | char *zsig; |
---|
| 124 | |
---|
| 125 | zsig=owl_message_get_attribute_value(m, "zsig"); |
---|
| 126 | if (!zsig) return(""); |
---|
| 127 | return(zsig); |
---|
[b45293f] | 128 | } |
---|
| 129 | |
---|
[4b464a4] | 130 | void owl_message_set_recipient(owl_message *m, char *recip) { |
---|
[d0d65df] | 131 | owl_message_set_attribute(m, "recipient", recip); |
---|
[4b464a4] | 132 | } |
---|
| 133 | |
---|
| 134 | char *owl_message_get_recipient(owl_message *m) { |
---|
| 135 | /* this is stupid for outgoing messages, we need to fix it. */ |
---|
[d0d65df] | 136 | |
---|
| 137 | char *recip; |
---|
[4b464a4] | 138 | |
---|
| 139 | if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) { |
---|
[d0d65df] | 140 | recip=owl_message_get_attribute_value(m, "recipient"); |
---|
[4b464a4] | 141 | } else if (owl_message_is_direction_out(m)) { |
---|
[d0d65df] | 142 | recip=m->zwriteline; |
---|
[4b464a4] | 143 | } else { |
---|
[d0d65df] | 144 | recip=owl_message_get_attribute_value(m, "recipient"); |
---|
[4b464a4] | 145 | } |
---|
[d0d65df] | 146 | if (!recip) return(""); |
---|
| 147 | return(recip); |
---|
[4b464a4] | 148 | } |
---|
| 149 | |
---|
| 150 | void owl_message_set_realm(owl_message *m, char *realm) { |
---|
[d0d65df] | 151 | owl_message_set_attribute(m, "realm", realm); |
---|
[4b464a4] | 152 | } |
---|
| 153 | |
---|
| 154 | char *owl_message_get_realm(owl_message *m) { |
---|
[d0d65df] | 155 | char *realm; |
---|
| 156 | |
---|
| 157 | realm=owl_message_get_attribute_value(m, "realm"); |
---|
| 158 | if (!realm) return(""); |
---|
| 159 | return(realm); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | void owl_message_set_body(owl_message *m, char *body) { |
---|
| 163 | owl_message_set_attribute(m, "body", body); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | char *owl_message_get_body(owl_message *m) { |
---|
| 167 | char *body; |
---|
| 168 | |
---|
| 169 | body=owl_message_get_attribute_value(m, "body"); |
---|
| 170 | if (!body) return(""); |
---|
| 171 | return(body); |
---|
[4b464a4] | 172 | } |
---|
| 173 | |
---|
[d0d65df] | 174 | |
---|
[4b464a4] | 175 | void owl_message_set_opcode(owl_message *m, char *opcode) { |
---|
[d0d65df] | 176 | owl_message_set_attribute(m, "opcode", opcode); |
---|
[4b464a4] | 177 | } |
---|
| 178 | |
---|
| 179 | char *owl_message_get_opcode(owl_message *m) { |
---|
[d0d65df] | 180 | char *opcode; |
---|
| 181 | |
---|
| 182 | opcode=owl_message_get_attribute_value(m, "opcode"); |
---|
| 183 | if (!opcode) return(""); |
---|
| 184 | return(opcode); |
---|
[4b464a4] | 185 | } |
---|
| 186 | |
---|
| 187 | char *owl_message_get_timestr(owl_message *m) { |
---|
| 188 | return(m->time); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | void owl_message_set_type_admin(owl_message *m) { |
---|
| 192 | m->type=OWL_MESSAGE_TYPE_ADMIN; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | void owl_message_set_type_zephyr(owl_message *m) { |
---|
| 196 | m->type=OWL_MESSAGE_TYPE_ZEPHYR; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | int owl_message_is_type_admin(owl_message *m) { |
---|
| 200 | if (m->type==OWL_MESSAGE_TYPE_ADMIN) return(1); |
---|
| 201 | return(0); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | int owl_message_is_type_zephyr(owl_message *m) { |
---|
| 205 | if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return(1); |
---|
| 206 | return(0); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | int owl_message_is_type_generic(owl_message *m) { |
---|
| 210 | if (m->type==OWL_MESSAGE_TYPE_GENERIC) return(1); |
---|
| 211 | return(0); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | char *owl_message_get_text(owl_message *m) { |
---|
| 215 | return(owl_fmtext_get_text(&(m->fmtext))); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | void owl_message_set_direction_in(owl_message *m) { |
---|
| 219 | m->direction=OWL_MESSAGE_DIRECTION_IN; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | void owl_message_set_direction_out(owl_message *m) { |
---|
| 223 | m->direction=OWL_MESSAGE_DIRECTION_OUT; |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | void owl_message_set_direction_none(owl_message *m) { |
---|
| 227 | m->direction=OWL_MESSAGE_DIRECTION_NONE; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | int owl_message_is_direction_in(owl_message *m) { |
---|
| 231 | if (m->direction==OWL_MESSAGE_DIRECTION_IN) return(1); |
---|
| 232 | return(0); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | int owl_message_is_direction_out(owl_message *m) { |
---|
| 236 | if (m->direction==OWL_MESSAGE_DIRECTION_OUT) return(1); |
---|
| 237 | return(0); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | int owl_message_is_direction_none(owl_message *m) { |
---|
| 241 | if (m->direction==OWL_MESSAGE_DIRECTION_NONE) return(1); |
---|
| 242 | return(0); |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | int owl_message_get_numlines(owl_message *m) { |
---|
| 246 | if (m == NULL) return(0); |
---|
| 247 | return(owl_fmtext_num_lines(&(m->fmtext))); |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | void owl_message_mark_delete(owl_message *m) { |
---|
| 251 | if (m == NULL) return; |
---|
| 252 | m->delete=1; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | void owl_message_unmark_delete(owl_message *m) { |
---|
| 256 | if (m == NULL) return; |
---|
| 257 | m->delete=0; |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | char *owl_message_get_zwriteline(owl_message *m) { |
---|
| 261 | return(m->zwriteline); |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | void owl_message_set_zwriteline(owl_message *m, char *line) { |
---|
| 265 | m->zwriteline=strdup(line); |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | int owl_message_is_delete(owl_message *m) { |
---|
| 269 | if (m == NULL) return(0); |
---|
| 270 | if (m->delete==1) return(1); |
---|
| 271 | return(0); |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | ZNotice_t *owl_message_get_notice(owl_message *m) { |
---|
| 275 | return(&(m->notice)); |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | char *owl_message_get_hostname(owl_message *m) { |
---|
| 279 | return(m->hostname); |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | |
---|
| 283 | void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color) { |
---|
| 284 | owl_fmtext a, b; |
---|
| 285 | |
---|
[af2ca19] | 286 | owl_fmtext_init_null(&a); |
---|
| 287 | owl_fmtext_init_null(&b); |
---|
| 288 | |
---|
[4b464a4] | 289 | owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a); |
---|
| 290 | owl_fmtext_truncate_cols(&a, acol, bcol, &b); |
---|
| 291 | if (color!=OWL_COLOR_DEFAULT) { |
---|
| 292 | owl_fmtext_colorize(&b, color); |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | if (owl_global_is_search_active(&g)) { |
---|
| 296 | owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g)); |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | owl_fmtext_curs_waddstr(&b, win); |
---|
| 300 | |
---|
| 301 | owl_fmtext_free(&a); |
---|
| 302 | owl_fmtext_free(&b); |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | int owl_message_is_personal(owl_message *m) { |
---|
| 306 | if (strcasecmp(owl_message_get_class(m), "message")) return(0); |
---|
| 307 | if (strcasecmp(owl_message_get_instance(m), "personal")) return(0); |
---|
[a2641cd9] | 308 | if (!strcasecmp(owl_message_get_recipient(m), ZGetSender()) || |
---|
| 309 | !strcasecmp(owl_message_get_sender(m), ZGetSender())) { |
---|
[4b464a4] | 310 | return(1); |
---|
| 311 | } |
---|
| 312 | return(0); |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | int owl_message_is_private(owl_message *m) { |
---|
[a2641cd9] | 316 | if (!strcasecmp(owl_message_get_recipient(m), ZGetSender())) return(1); |
---|
[4b464a4] | 317 | return(0); |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | int owl_message_is_mail(owl_message *m) { |
---|
| 321 | if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) { |
---|
| 322 | return(1); |
---|
| 323 | } |
---|
| 324 | return(0); |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | int owl_message_is_ping(owl_message *m) { |
---|
| 328 | if (!strcasecmp(owl_message_get_opcode(m), "ping")) return(1); |
---|
| 329 | return(0); |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | int owl_message_is_login(owl_message *m) { |
---|
| 333 | if (!strcasecmp(owl_message_get_class(m), "login")) return(1); |
---|
| 334 | return(0); |
---|
| 335 | /* is this good enough? */ |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | int owl_message_is_burningears(owl_message *m) { |
---|
| 339 | /* we should add a global to cache the short zsender */ |
---|
| 340 | char sender[LINE], *ptr; |
---|
| 341 | |
---|
| 342 | /* if the message is from us or to us, it doesn't count */ |
---|
| 343 | if (!strcasecmp(ZGetSender(), owl_message_get_sender(m))) return(0); |
---|
| 344 | if (!strcasecmp(ZGetSender(), owl_message_get_recipient(m))) return(0); |
---|
| 345 | |
---|
| 346 | strcpy(sender, ZGetSender()); |
---|
| 347 | ptr=strchr(sender, '@'); |
---|
| 348 | if (ptr) *ptr='\0'; |
---|
| 349 | |
---|
| 350 | if (stristr(owl_message_get_body(m), sender)) { |
---|
| 351 | return(1); |
---|
| 352 | } |
---|
| 353 | return(0); |
---|
| 354 | } |
---|
| 355 | |
---|
| 356 | /* caller must free return value. */ |
---|
| 357 | char *owl_message_get_cc(owl_message *m) { |
---|
| 358 | char *cur, *out, *end; |
---|
| 359 | |
---|
| 360 | cur = owl_message_get_body(m); |
---|
| 361 | while (*cur && *cur==' ') cur++; |
---|
[985f85b] | 362 | if (strncasecmp(cur, "cc:", 3)) return(NULL); |
---|
[4b464a4] | 363 | cur+=3; |
---|
| 364 | while (*cur && *cur==' ') cur++; |
---|
| 365 | out = owl_strdup(cur); |
---|
| 366 | end = strchr(out, '\n'); |
---|
| 367 | if (end) end[0] = '\0'; |
---|
| 368 | return(out); |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | int owl_message_get_id(owl_message *m) { |
---|
| 372 | return(m->id); |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | int owl_message_search(owl_message *m, char *string) { |
---|
| 376 | /* return 1 if the message contains "string", 0 otherwise. This is |
---|
| 377 | * case insensitive because the functions it uses are */ |
---|
| 378 | |
---|
| 379 | return (owl_fmtext_search(&(m->fmtext), string)); |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | void owl_message_create(owl_message *m, char *header, char *text) { |
---|
| 383 | char *indent; |
---|
| 384 | |
---|
[d0d65df] | 385 | owl_message_init(m); |
---|
[4b464a4] | 386 | |
---|
[d0d65df] | 387 | owl_message_set_body(m, text); |
---|
[4b464a4] | 388 | |
---|
| 389 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
| 390 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
| 391 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 392 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 393 | owl_fmtext_append_ztext(&(m->fmtext), header); |
---|
| 394 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 395 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 396 | if (text[strlen(text)-1]!='\n') { |
---|
| 397 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | owl_free(indent); |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | void owl_message_create_admin(owl_message *m, char *header, char *text) { |
---|
| 404 | char *indent; |
---|
| 405 | |
---|
[d0d65df] | 406 | owl_message_init(m); |
---|
[4b464a4] | 407 | owl_message_set_type_admin(m); |
---|
[7d4fbcd] | 408 | |
---|
[d0d65df] | 409 | owl_message_set_body(m, text); |
---|
[7d4fbcd] | 410 | |
---|
| 411 | /* do something to make it clear the notice shouldn't be used for now */ |
---|
| 412 | |
---|
| 413 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
| 414 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
| 415 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 416 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 417 | owl_fmtext_append_bold(&(m->fmtext), "OWL ADMIN "); |
---|
| 418 | owl_fmtext_append_ztext(&(m->fmtext), header); |
---|
| 419 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 420 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 421 | if (text[strlen(text)-1]!='\n') { |
---|
| 422 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | owl_free(indent); |
---|
| 426 | } |
---|
| 427 | |
---|
[b45293f] | 428 | void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n) { |
---|
[7d4fbcd] | 429 | struct hostent *hent; |
---|
[a15a84f] | 430 | int k, ret; |
---|
[d0d65df] | 431 | char *ptr, *tmp, *tmp2; |
---|
[7d4fbcd] | 432 | |
---|
[d0d65df] | 433 | owl_message_init(m); |
---|
| 434 | |
---|
[4b464a4] | 435 | owl_message_set_type_zephyr(m); |
---|
| 436 | owl_message_set_direction_in(m); |
---|
[7d4fbcd] | 437 | |
---|
| 438 | /* first save the full notice */ |
---|
| 439 | memcpy(&(m->notice), n, sizeof(ZNotice_t)); |
---|
| 440 | |
---|
| 441 | /* a little gross, we'll reaplace \r's with ' ' for now */ |
---|
| 442 | owl_zephyr_hackaway_cr(&(m->notice)); |
---|
| 443 | |
---|
| 444 | m->delete=0; |
---|
| 445 | |
---|
| 446 | /* set other info */ |
---|
[d0d65df] | 447 | owl_message_set_sender(m, n->z_sender); |
---|
| 448 | owl_message_set_class(m, n->z_class); |
---|
| 449 | owl_message_set_instance(m, n->z_class_inst); |
---|
| 450 | owl_message_set_recipient(m, n->z_recipient); |
---|
[7d4fbcd] | 451 | if (n->z_opcode) { |
---|
[d0d65df] | 452 | owl_message_set_opcode(m, n->z_opcode); |
---|
[7d4fbcd] | 453 | } else { |
---|
[d0d65df] | 454 | owl_message_set_opcode(m, ""); |
---|
[7d4fbcd] | 455 | } |
---|
[d0d65df] | 456 | owl_message_set_zsig(m, n->z_message); |
---|
[7d4fbcd] | 457 | |
---|
| 458 | if ((ptr=strchr(n->z_recipient, '@'))!=NULL) { |
---|
[d0d65df] | 459 | owl_message_set_realm(m, ptr+1); |
---|
[7d4fbcd] | 460 | } else { |
---|
[d0d65df] | 461 | owl_message_set_realm(m, ZGetRealm()); |
---|
[7d4fbcd] | 462 | } |
---|
| 463 | |
---|
| 464 | m->zwriteline=strdup(""); |
---|
| 465 | |
---|
[b45293f] | 466 | /* set the body */ |
---|
[7d4fbcd] | 467 | ptr=owl_zephyr_get_message(n, &k); |
---|
[7e3e00a] | 468 | tmp=owl_malloc(k+10); |
---|
| 469 | memcpy(tmp, ptr, k); |
---|
| 470 | tmp[k]='\0'; |
---|
| 471 | if (owl_global_is_newlinestrip(&g)) { |
---|
[d0d65df] | 472 | tmp2=owl_util_stripnewlines(tmp); |
---|
| 473 | owl_message_set_body(m, tmp2); |
---|
[7e3e00a] | 474 | owl_free(tmp); |
---|
[d0d65df] | 475 | owl_free(tmp2); |
---|
[7e3e00a] | 476 | } else { |
---|
[d0d65df] | 477 | owl_message_set_body(m, tmp); |
---|
[7e3e00a] | 478 | } |
---|
[7d4fbcd] | 479 | |
---|
[d309eb3] | 480 | /* if zcrypt is enabled try to decrypt the message */ |
---|
| 481 | if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) { |
---|
| 482 | char *out; |
---|
| 483 | |
---|
[d0d65df] | 484 | out=owl_malloc(strlen(owl_message_get_body(m))*16+20); |
---|
| 485 | ret=zcrypt_decrypt(out, owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m)); |
---|
[a15a84f] | 486 | if (ret==0) { |
---|
[d0d65df] | 487 | owl_message_set_body(m, out); |
---|
[a15a84f] | 488 | } else { |
---|
| 489 | owl_free(out); |
---|
| 490 | } |
---|
[d309eb3] | 491 | } |
---|
| 492 | |
---|
[7d4fbcd] | 493 | /* save the hostname */ |
---|
[3a2daac] | 494 | owl_function_debugmsg("About to do gethostbyaddr"); |
---|
[7d4fbcd] | 495 | hent=gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET); |
---|
| 496 | if (hent && hent->h_name) { |
---|
| 497 | strcpy(m->hostname, hent->h_name); |
---|
| 498 | } else { |
---|
| 499 | strcpy(m->hostname, inet_ntoa(n->z_sender_addr)); |
---|
| 500 | } |
---|
| 501 | |
---|
| 502 | /* save the time */ |
---|
| 503 | m->time=owl_strdup(ctime((time_t *) &n->z_time.tv_sec)); |
---|
| 504 | m->time[strlen(m->time)-1]='\0'; |
---|
| 505 | |
---|
| 506 | /* create the formatted message */ |
---|
| 507 | if (owl_global_is_config_format(&g)) { |
---|
| 508 | _owl_message_make_text_from_config(m); |
---|
| 509 | } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 510 | _owl_message_make_text_from_notice_standard(m); |
---|
| 511 | } else { |
---|
| 512 | _owl_message_make_text_from_notice_simple(m); |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | } |
---|
| 516 | |
---|
[b45293f] | 517 | void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig) { |
---|
| 518 | owl_zwrite z; |
---|
| 519 | int ret; |
---|
| 520 | |
---|
[d0d65df] | 521 | owl_message_init(m); |
---|
[b45293f] | 522 | |
---|
| 523 | /* create a zwrite for the purpose of filling in other message fields */ |
---|
| 524 | owl_zwrite_create_from_line(&z, line); |
---|
| 525 | |
---|
| 526 | /* set things */ |
---|
| 527 | owl_message_set_direction_out(m); |
---|
| 528 | owl_message_set_type_zephyr(m); |
---|
[8fec514] | 529 | owl_message_set_sender(m, ZGetSender()); |
---|
| 530 | owl_message_set_class(m, owl_zwrite_get_class(&z)); |
---|
| 531 | owl_message_set_instance(m, owl_zwrite_get_instance(&z)); |
---|
[d0d65df] | 532 | owl_message_set_recipient(m, |
---|
| 533 | long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */ |
---|
[8fec514] | 534 | owl_message_set_opcode(m, owl_zwrite_get_opcode(&z)); |
---|
[d0d65df] | 535 | owl_message_set_realm(m, owl_zwrite_get_realm(&z)); /* also a hack, but not here */ |
---|
[b45293f] | 536 | m->zwriteline=owl_strdup(line); |
---|
[d0d65df] | 537 | owl_message_set_body(m, body); |
---|
[8fec514] | 538 | owl_message_set_zsig(m, zsig); |
---|
[b45293f] | 539 | |
---|
| 540 | /* save the hostname */ |
---|
| 541 | ret=gethostname(m->hostname, MAXHOSTNAMELEN); |
---|
| 542 | if (ret) { |
---|
| 543 | strcpy(m->hostname, "localhost"); |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | /* create the formatted message */ |
---|
| 547 | if (owl_global_is_config_format(&g)) { |
---|
| 548 | _owl_message_make_text_from_config(m); |
---|
| 549 | } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 550 | _owl_message_make_text_from_zwriteline_standard(m); |
---|
| 551 | } else { |
---|
| 552 | _owl_message_make_text_from_zwriteline_simple(m); |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | owl_zwrite_free(&z); |
---|
| 556 | } |
---|
[7d4fbcd] | 557 | |
---|
| 558 | void _owl_message_make_text_from_config(owl_message *m) { |
---|
| 559 | char *body, *indent; |
---|
[d0d65df] | 560 | |
---|
[7d4fbcd] | 561 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 562 | |
---|
| 563 | /* get body from the config */ |
---|
| 564 | body=owl_config_getmsg(m, 1); |
---|
| 565 | |
---|
| 566 | /* indent */ |
---|
| 567 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_TAB+10); |
---|
| 568 | owl_text_indent(indent, body, OWL_TAB); |
---|
| 569 | |
---|
| 570 | /* fmtext_append. This needs to change */ |
---|
| 571 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 572 | |
---|
| 573 | owl_free(indent); |
---|
| 574 | owl_free(body); |
---|
| 575 | } |
---|
| 576 | |
---|
[b45293f] | 577 | void _owl_message_make_text_from_zwriteline_standard(owl_message *m) { |
---|
[be97670] | 578 | char *indent, *text, *zsigbuff, *foo; |
---|
[b45293f] | 579 | |
---|
| 580 | text=owl_message_get_body(m); |
---|
| 581 | |
---|
| 582 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
| 583 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
| 584 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 585 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 586 | owl_fmtext_append_normal(&(m->fmtext), "Zephyr sent to "); |
---|
[be97670] | 587 | foo=short_zuser(owl_message_get_recipient(m)); |
---|
| 588 | owl_fmtext_append_normal(&(m->fmtext), foo); |
---|
| 589 | owl_free(foo); |
---|
[b45293f] | 590 | owl_fmtext_append_normal(&(m->fmtext), " (Zsig: "); |
---|
| 591 | |
---|
[8fec514] | 592 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b45293f] | 593 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 594 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 595 | owl_free(zsigbuff); |
---|
| 596 | |
---|
| 597 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
| 598 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 599 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 600 | if (text[strlen(text)-1]!='\n') { |
---|
| 601 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | owl_free(indent); |
---|
| 605 | } |
---|
| 606 | |
---|
| 607 | void _owl_message_make_text_from_zwriteline_simple(owl_message *m) { |
---|
[b12c219] | 608 | char *indent, *text, *zsigbuff, *foo; |
---|
| 609 | |
---|
| 610 | text=owl_message_get_body(m); |
---|
| 611 | |
---|
| 612 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
| 613 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
| 614 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 615 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 616 | owl_fmtext_append_normal(&(m->fmtext), "To: "); |
---|
| 617 | foo=short_zuser(owl_message_get_recipient(m)); |
---|
| 618 | owl_fmtext_append_normal(&(m->fmtext), foo); |
---|
| 619 | owl_free(foo); |
---|
| 620 | owl_fmtext_append_normal(&(m->fmtext), " (Zsig: "); |
---|
| 621 | |
---|
[a3ba748] | 622 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b12c219] | 623 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 624 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 625 | owl_free(zsigbuff); |
---|
| 626 | |
---|
| 627 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
| 628 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 629 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 630 | if (text[strlen(text)-1]!='\n') { |
---|
| 631 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 632 | } |
---|
| 633 | |
---|
| 634 | owl_free(indent); |
---|
[b45293f] | 635 | } |
---|
| 636 | |
---|
[7d4fbcd] | 637 | void _owl_message_make_text_from_notice_standard(owl_message *m) { |
---|
[b45293f] | 638 | char *body, *indent, *ptr, *zsigbuff, frombuff[LINE]; |
---|
[7d4fbcd] | 639 | ZNotice_t *n; |
---|
| 640 | |
---|
| 641 | n=&(m->notice); |
---|
[d309eb3] | 642 | |
---|
| 643 | /* get the body */ |
---|
[d0d65df] | 644 | body=owl_malloc(strlen(owl_message_get_body(m))+30); |
---|
| 645 | strcpy(body, owl_message_get_body(m)); |
---|
[7d4fbcd] | 646 | |
---|
| 647 | /* add a newline if we need to */ |
---|
| 648 | if (body[0]!='\0' && body[strlen(body)-1]!='\n') { |
---|
| 649 | strcat(body, "\n"); |
---|
| 650 | } |
---|
| 651 | |
---|
| 652 | /* do the indenting into indent */ |
---|
| 653 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10); |
---|
| 654 | owl_text_indent(indent, body, OWL_MSGTAB); |
---|
| 655 | |
---|
| 656 | /* edit the from addr for printing */ |
---|
[d0d65df] | 657 | strcpy(frombuff, owl_message_get_sender(m)); |
---|
[7d4fbcd] | 658 | ptr=strchr(frombuff, '@'); |
---|
| 659 | if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) { |
---|
| 660 | *ptr='\0'; |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | /* set the message for printing */ |
---|
| 664 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 665 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 666 | |
---|
[d0d65df] | 667 | if (!strcasecmp(owl_message_get_opcode(m), "ping") && owl_message_is_private(m)) { |
---|
[7d4fbcd] | 668 | owl_fmtext_append_bold(&(m->fmtext), "PING"); |
---|
| 669 | owl_fmtext_append_normal(&(m->fmtext), " from "); |
---|
| 670 | owl_fmtext_append_bold(&(m->fmtext), frombuff); |
---|
| 671 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 672 | } else if (!strcasecmp(n->z_class, "login")) { |
---|
| 673 | char *ptr, host[LINE], tty[LINE]; |
---|
| 674 | int len; |
---|
| 675 | |
---|
| 676 | ptr=owl_zephyr_get_field(n, 1, &len); |
---|
| 677 | strncpy(host, ptr, len); |
---|
| 678 | host[len]='\0'; |
---|
| 679 | ptr=owl_zephyr_get_field(n, 3, &len); |
---|
| 680 | strncpy(tty, ptr, len); |
---|
| 681 | tty[len]='\0'; |
---|
| 682 | |
---|
| 683 | if (!strcasecmp(n->z_opcode, "user_login")) { |
---|
| 684 | owl_fmtext_append_bold(&(m->fmtext), "LOGIN"); |
---|
| 685 | } else if (!strcasecmp(n->z_opcode, "user_logout")) { |
---|
| 686 | owl_fmtext_append_bold(&(m->fmtext), "LOGOUT"); |
---|
| 687 | } |
---|
| 688 | owl_fmtext_append_normal(&(m->fmtext), " for "); |
---|
[4b464a4] | 689 | ptr=short_zuser(n->z_class_inst); |
---|
[7d4fbcd] | 690 | owl_fmtext_append_bold(&(m->fmtext), ptr); |
---|
| 691 | owl_free(ptr); |
---|
| 692 | owl_fmtext_append_normal(&(m->fmtext), " at "); |
---|
| 693 | owl_fmtext_append_normal(&(m->fmtext), host); |
---|
| 694 | owl_fmtext_append_normal(&(m->fmtext), " "); |
---|
| 695 | owl_fmtext_append_normal(&(m->fmtext), tty); |
---|
| 696 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 697 | } else { |
---|
[d0d65df] | 698 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m)); |
---|
[7d4fbcd] | 699 | owl_fmtext_append_normal(&(m->fmtext), " / "); |
---|
[d0d65df] | 700 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m)); |
---|
[7d4fbcd] | 701 | owl_fmtext_append_normal(&(m->fmtext), " / "); |
---|
| 702 | owl_fmtext_append_bold(&(m->fmtext), frombuff); |
---|
| 703 | if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) { |
---|
| 704 | owl_fmtext_append_normal(&(m->fmtext), " {"); |
---|
| 705 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m)); |
---|
| 706 | owl_fmtext_append_normal(&(m->fmtext), "} "); |
---|
| 707 | } |
---|
| 708 | if (n->z_opcode[0]!='\0') { |
---|
| 709 | owl_fmtext_append_normal(&(m->fmtext), " ["); |
---|
[d0d65df] | 710 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_opcode(m)); |
---|
[7d4fbcd] | 711 | owl_fmtext_append_normal(&(m->fmtext), "] "); |
---|
| 712 | } |
---|
| 713 | |
---|
| 714 | /* stick on the zsig */ |
---|
[a3ba748] | 715 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b45293f] | 716 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 717 | owl_fmtext_append_normal(&(m->fmtext), " ("); |
---|
| 718 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 719 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
[7d4fbcd] | 720 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
[b45293f] | 721 | owl_free(zsigbuff); |
---|
| 722 | |
---|
| 723 | /* then the indented message */ |
---|
[7d4fbcd] | 724 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 725 | |
---|
| 726 | /* make personal messages bold for smaat users */ |
---|
| 727 | if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 728 | if (owl_message_is_personal(m)) { |
---|
| 729 | owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD); |
---|
| 730 | } |
---|
| 731 | } |
---|
| 732 | } |
---|
| 733 | |
---|
| 734 | owl_free(body); |
---|
| 735 | owl_free(indent); |
---|
| 736 | } |
---|
| 737 | |
---|
| 738 | void _owl_message_make_text_from_notice_simple(owl_message *m) { |
---|
[b45293f] | 739 | char *body, *indent, *ptr, *zsigbuff, frombuff[LINE]; |
---|
[7d4fbcd] | 740 | ZNotice_t *n; |
---|
| 741 | |
---|
| 742 | n=&(m->notice); |
---|
[d309eb3] | 743 | |
---|
| 744 | /* get the body */ |
---|
[d0d65df] | 745 | body=owl_malloc(strlen(owl_message_get_body(m)+30)); |
---|
| 746 | strcpy(body, owl_message_get_body(m)); |
---|
[7d4fbcd] | 747 | |
---|
| 748 | /* add a newline if we need to */ |
---|
| 749 | if (body[0]!='\0' && body[strlen(body)-1]!='\n') { |
---|
| 750 | strcat(body, "\n"); |
---|
| 751 | } |
---|
| 752 | |
---|
| 753 | /* do the indenting into indent */ |
---|
| 754 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10); |
---|
| 755 | owl_text_indent(indent, body, OWL_MSGTAB); |
---|
| 756 | |
---|
| 757 | /* edit the from addr for printing */ |
---|
[d0d65df] | 758 | strcpy(frombuff, owl_message_get_sender(m)); |
---|
[7d4fbcd] | 759 | ptr=strchr(frombuff, '@'); |
---|
| 760 | if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) { |
---|
| 761 | *ptr='\0'; |
---|
| 762 | } |
---|
| 763 | |
---|
| 764 | /* set the message for printing */ |
---|
| 765 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 766 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 767 | |
---|
[d0d65df] | 768 | if (!strcasecmp(owl_message_get_opcode(m), "ping")) { |
---|
[7d4fbcd] | 769 | owl_fmtext_append_bold(&(m->fmtext), "PING"); |
---|
| 770 | owl_fmtext_append_normal(&(m->fmtext), " from "); |
---|
| 771 | owl_fmtext_append_bold(&(m->fmtext), frombuff); |
---|
| 772 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
[d0d65df] | 773 | } else if (!strcasecmp(owl_message_get_class(m), "login")) { |
---|
[7d4fbcd] | 774 | char *ptr, host[LINE], tty[LINE]; |
---|
| 775 | int len; |
---|
| 776 | |
---|
| 777 | ptr=owl_zephyr_get_field(n, 1, &len); |
---|
| 778 | strncpy(host, ptr, len); |
---|
| 779 | host[len]='\0'; |
---|
| 780 | ptr=owl_zephyr_get_field(n, 3, &len); |
---|
| 781 | strncpy(tty, ptr, len); |
---|
| 782 | tty[len]='\0'; |
---|
| 783 | |
---|
[d0d65df] | 784 | if (!strcasecmp(owl_message_get_opcode(m), "user_login")) { |
---|
[7d4fbcd] | 785 | owl_fmtext_append_bold(&(m->fmtext), "LOGIN"); |
---|
[d0d65df] | 786 | } else if (!strcasecmp(owl_message_get_opcode(m), "user_logout")) { |
---|
[7d4fbcd] | 787 | owl_fmtext_append_bold(&(m->fmtext), "LOGOUT"); |
---|
| 788 | } |
---|
| 789 | owl_fmtext_append_normal(&(m->fmtext), " for "); |
---|
[d0d65df] | 790 | ptr=short_zuser(owl_message_get_instance(m)); |
---|
[7d4fbcd] | 791 | owl_fmtext_append_bold(&(m->fmtext), ptr); |
---|
| 792 | owl_free(ptr); |
---|
| 793 | owl_fmtext_append_normal(&(m->fmtext), " at "); |
---|
| 794 | owl_fmtext_append_normal(&(m->fmtext), host); |
---|
| 795 | owl_fmtext_append_normal(&(m->fmtext), " "); |
---|
| 796 | owl_fmtext_append_normal(&(m->fmtext), tty); |
---|
| 797 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 798 | } else { |
---|
| 799 | owl_fmtext_append_normal(&(m->fmtext), "From: "); |
---|
[d0d65df] | 800 | if (strcasecmp(owl_message_get_class(m), "message")) { |
---|
[7d4fbcd] | 801 | owl_fmtext_append_normal(&(m->fmtext), "Class "); |
---|
[d0d65df] | 802 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m)); |
---|
[7d4fbcd] | 803 | owl_fmtext_append_normal(&(m->fmtext), " / Instance "); |
---|
[d0d65df] | 804 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m)); |
---|
[7d4fbcd] | 805 | owl_fmtext_append_normal(&(m->fmtext), " / "); |
---|
| 806 | } |
---|
| 807 | owl_fmtext_append_normal(&(m->fmtext), frombuff); |
---|
| 808 | if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) { |
---|
| 809 | owl_fmtext_append_normal(&(m->fmtext), " {"); |
---|
| 810 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m)); |
---|
| 811 | owl_fmtext_append_normal(&(m->fmtext), "} "); |
---|
| 812 | } |
---|
| 813 | |
---|
| 814 | /* stick on the zsig */ |
---|
[a3ba748] | 815 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b45293f] | 816 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 817 | owl_fmtext_append_normal(&(m->fmtext), " ("); |
---|
| 818 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 819 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
[7d4fbcd] | 820 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
[b45293f] | 821 | owl_free(zsigbuff); |
---|
| 822 | |
---|
| 823 | /* then the indented message */ |
---|
[7d4fbcd] | 824 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 825 | |
---|
| 826 | /* make personal messages bold for smaat users */ |
---|
| 827 | if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 828 | if (owl_message_is_personal(m)) { |
---|
| 829 | owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD); |
---|
| 830 | } |
---|
| 831 | } |
---|
| 832 | } |
---|
| 833 | |
---|
| 834 | owl_free(body); |
---|
| 835 | owl_free(indent); |
---|
| 836 | } |
---|
| 837 | |
---|
[b45293f] | 838 | void owl_message_pretty_zsig(owl_message *m, char *buff) { |
---|
| 839 | /* stick a one line version of the zsig in buff */ |
---|
[7d4fbcd] | 840 | char *ptr; |
---|
| 841 | |
---|
[d0d65df] | 842 | strcpy(buff, owl_message_get_zsig(m)); |
---|
[b45293f] | 843 | ptr=strchr(buff, '\n'); |
---|
| 844 | if (ptr) ptr[0]='\0'; |
---|
[7d4fbcd] | 845 | } |
---|
| 846 | |
---|
| 847 | void owl_message_free(owl_message *m) { |
---|
[d0d65df] | 848 | int i, j; |
---|
| 849 | owl_pair *p; |
---|
| 850 | |
---|
[4b464a4] | 851 | if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) { |
---|
[7d4fbcd] | 852 | ZFreeNotice(&(m->notice)); |
---|
| 853 | } |
---|
| 854 | if (m->time) owl_free(m->time); |
---|
| 855 | if (m->zwriteline) owl_free(m->zwriteline); |
---|
[d0d65df] | 856 | |
---|
| 857 | /* free all the attributes */ |
---|
| 858 | j=owl_list_get_size(&(m->attributes)); |
---|
| 859 | for (i=0; i<j; i++) { |
---|
| 860 | p=owl_list_get_element(&(m->attributes), i); |
---|
| 861 | owl_free(owl_pair_get_key(p)); |
---|
| 862 | owl_free(owl_pair_get_value(p)); |
---|
| 863 | owl_free(p); |
---|
| 864 | } |
---|
| 865 | |
---|
| 866 | owl_list_free_simple(&(m->attributes)); |
---|
[7d4fbcd] | 867 | |
---|
| 868 | owl_fmtext_free(&(m->fmtext)); |
---|
| 869 | } |
---|
| 870 | |
---|