[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; |
---|
[c269e22] | 430 | int k; |
---|
[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); |
---|
| 474 | owl_free(tmp2); |
---|
[7e3e00a] | 475 | } else { |
---|
[d0d65df] | 476 | owl_message_set_body(m, tmp); |
---|
[7e3e00a] | 477 | } |
---|
[ecd5dc5] | 478 | owl_free(tmp); |
---|
[7d4fbcd] | 479 | |
---|
[c269e22] | 480 | #ifdef OWL_HAVE_DES |
---|
[d309eb3] | 481 | /* if zcrypt is enabled try to decrypt the message */ |
---|
| 482 | if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) { |
---|
| 483 | char *out; |
---|
[c269e22] | 484 | int ret; |
---|
[d309eb3] | 485 | |
---|
[d0d65df] | 486 | out=owl_malloc(strlen(owl_message_get_body(m))*16+20); |
---|
| 487 | ret=zcrypt_decrypt(out, owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m)); |
---|
[a15a84f] | 488 | if (ret==0) { |
---|
[d0d65df] | 489 | owl_message_set_body(m, out); |
---|
[a15a84f] | 490 | } else { |
---|
| 491 | owl_free(out); |
---|
| 492 | } |
---|
[d309eb3] | 493 | } |
---|
[c269e22] | 494 | #endif |
---|
[d309eb3] | 495 | |
---|
[7d4fbcd] | 496 | /* save the hostname */ |
---|
[3a2daac] | 497 | owl_function_debugmsg("About to do gethostbyaddr"); |
---|
[7d4fbcd] | 498 | hent=gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET); |
---|
| 499 | if (hent && hent->h_name) { |
---|
| 500 | strcpy(m->hostname, hent->h_name); |
---|
| 501 | } else { |
---|
| 502 | strcpy(m->hostname, inet_ntoa(n->z_sender_addr)); |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | /* save the time */ |
---|
| 506 | m->time=owl_strdup(ctime((time_t *) &n->z_time.tv_sec)); |
---|
| 507 | m->time[strlen(m->time)-1]='\0'; |
---|
| 508 | |
---|
| 509 | /* create the formatted message */ |
---|
| 510 | if (owl_global_is_config_format(&g)) { |
---|
| 511 | _owl_message_make_text_from_config(m); |
---|
| 512 | } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 513 | _owl_message_make_text_from_notice_standard(m); |
---|
| 514 | } else { |
---|
| 515 | _owl_message_make_text_from_notice_simple(m); |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | } |
---|
| 519 | |
---|
[b45293f] | 520 | void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig) { |
---|
| 521 | owl_zwrite z; |
---|
| 522 | int ret; |
---|
| 523 | |
---|
[d0d65df] | 524 | owl_message_init(m); |
---|
[b45293f] | 525 | |
---|
| 526 | /* create a zwrite for the purpose of filling in other message fields */ |
---|
| 527 | owl_zwrite_create_from_line(&z, line); |
---|
| 528 | |
---|
| 529 | /* set things */ |
---|
| 530 | owl_message_set_direction_out(m); |
---|
| 531 | owl_message_set_type_zephyr(m); |
---|
[8fec514] | 532 | owl_message_set_sender(m, ZGetSender()); |
---|
| 533 | owl_message_set_class(m, owl_zwrite_get_class(&z)); |
---|
| 534 | owl_message_set_instance(m, owl_zwrite_get_instance(&z)); |
---|
[d0d65df] | 535 | owl_message_set_recipient(m, |
---|
| 536 | long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */ |
---|
[8fec514] | 537 | owl_message_set_opcode(m, owl_zwrite_get_opcode(&z)); |
---|
[d0d65df] | 538 | owl_message_set_realm(m, owl_zwrite_get_realm(&z)); /* also a hack, but not here */ |
---|
[b45293f] | 539 | m->zwriteline=owl_strdup(line); |
---|
[d0d65df] | 540 | owl_message_set_body(m, body); |
---|
[8fec514] | 541 | owl_message_set_zsig(m, zsig); |
---|
[b45293f] | 542 | |
---|
| 543 | /* save the hostname */ |
---|
| 544 | ret=gethostname(m->hostname, MAXHOSTNAMELEN); |
---|
| 545 | if (ret) { |
---|
| 546 | strcpy(m->hostname, "localhost"); |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | /* create the formatted message */ |
---|
| 550 | if (owl_global_is_config_format(&g)) { |
---|
| 551 | _owl_message_make_text_from_config(m); |
---|
| 552 | } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 553 | _owl_message_make_text_from_zwriteline_standard(m); |
---|
| 554 | } else { |
---|
| 555 | _owl_message_make_text_from_zwriteline_simple(m); |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | owl_zwrite_free(&z); |
---|
| 559 | } |
---|
[7d4fbcd] | 560 | |
---|
| 561 | void _owl_message_make_text_from_config(owl_message *m) { |
---|
| 562 | char *body, *indent; |
---|
[d0d65df] | 563 | |
---|
[7d4fbcd] | 564 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 565 | |
---|
| 566 | /* get body from the config */ |
---|
| 567 | body=owl_config_getmsg(m, 1); |
---|
| 568 | |
---|
| 569 | /* indent */ |
---|
| 570 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_TAB+10); |
---|
| 571 | owl_text_indent(indent, body, OWL_TAB); |
---|
| 572 | |
---|
| 573 | /* fmtext_append. This needs to change */ |
---|
| 574 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 575 | |
---|
| 576 | owl_free(indent); |
---|
| 577 | owl_free(body); |
---|
| 578 | } |
---|
| 579 | |
---|
[b45293f] | 580 | void _owl_message_make_text_from_zwriteline_standard(owl_message *m) { |
---|
[be97670] | 581 | char *indent, *text, *zsigbuff, *foo; |
---|
[b45293f] | 582 | |
---|
| 583 | text=owl_message_get_body(m); |
---|
| 584 | |
---|
| 585 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
| 586 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
| 587 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 588 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 589 | owl_fmtext_append_normal(&(m->fmtext), "Zephyr sent to "); |
---|
[be97670] | 590 | foo=short_zuser(owl_message_get_recipient(m)); |
---|
| 591 | owl_fmtext_append_normal(&(m->fmtext), foo); |
---|
| 592 | owl_free(foo); |
---|
[b45293f] | 593 | owl_fmtext_append_normal(&(m->fmtext), " (Zsig: "); |
---|
| 594 | |
---|
[8fec514] | 595 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b45293f] | 596 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 597 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 598 | owl_free(zsigbuff); |
---|
| 599 | |
---|
| 600 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
| 601 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 602 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 603 | if (text[strlen(text)-1]!='\n') { |
---|
| 604 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 605 | } |
---|
| 606 | |
---|
| 607 | owl_free(indent); |
---|
| 608 | } |
---|
| 609 | |
---|
| 610 | void _owl_message_make_text_from_zwriteline_simple(owl_message *m) { |
---|
[b12c219] | 611 | char *indent, *text, *zsigbuff, *foo; |
---|
| 612 | |
---|
| 613 | text=owl_message_get_body(m); |
---|
| 614 | |
---|
| 615 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
| 616 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
| 617 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 618 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 619 | owl_fmtext_append_normal(&(m->fmtext), "To: "); |
---|
| 620 | foo=short_zuser(owl_message_get_recipient(m)); |
---|
| 621 | owl_fmtext_append_normal(&(m->fmtext), foo); |
---|
| 622 | owl_free(foo); |
---|
| 623 | owl_fmtext_append_normal(&(m->fmtext), " (Zsig: "); |
---|
| 624 | |
---|
[a3ba748] | 625 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b12c219] | 626 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 627 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 628 | owl_free(zsigbuff); |
---|
| 629 | |
---|
| 630 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
| 631 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 632 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 633 | if (text[strlen(text)-1]!='\n') { |
---|
| 634 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 635 | } |
---|
| 636 | |
---|
| 637 | owl_free(indent); |
---|
[b45293f] | 638 | } |
---|
| 639 | |
---|
[7d4fbcd] | 640 | void _owl_message_make_text_from_notice_standard(owl_message *m) { |
---|
[b45293f] | 641 | char *body, *indent, *ptr, *zsigbuff, frombuff[LINE]; |
---|
[7d4fbcd] | 642 | ZNotice_t *n; |
---|
| 643 | |
---|
| 644 | n=&(m->notice); |
---|
[d309eb3] | 645 | |
---|
| 646 | /* get the body */ |
---|
[d0d65df] | 647 | body=owl_malloc(strlen(owl_message_get_body(m))+30); |
---|
| 648 | strcpy(body, owl_message_get_body(m)); |
---|
[7d4fbcd] | 649 | |
---|
| 650 | /* add a newline if we need to */ |
---|
| 651 | if (body[0]!='\0' && body[strlen(body)-1]!='\n') { |
---|
| 652 | strcat(body, "\n"); |
---|
| 653 | } |
---|
| 654 | |
---|
| 655 | /* do the indenting into indent */ |
---|
| 656 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10); |
---|
| 657 | owl_text_indent(indent, body, OWL_MSGTAB); |
---|
| 658 | |
---|
| 659 | /* edit the from addr for printing */ |
---|
[d0d65df] | 660 | strcpy(frombuff, owl_message_get_sender(m)); |
---|
[7d4fbcd] | 661 | ptr=strchr(frombuff, '@'); |
---|
| 662 | if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) { |
---|
| 663 | *ptr='\0'; |
---|
| 664 | } |
---|
| 665 | |
---|
| 666 | /* set the message for printing */ |
---|
| 667 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 668 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 669 | |
---|
[d0d65df] | 670 | if (!strcasecmp(owl_message_get_opcode(m), "ping") && owl_message_is_private(m)) { |
---|
[7d4fbcd] | 671 | owl_fmtext_append_bold(&(m->fmtext), "PING"); |
---|
| 672 | owl_fmtext_append_normal(&(m->fmtext), " from "); |
---|
| 673 | owl_fmtext_append_bold(&(m->fmtext), frombuff); |
---|
| 674 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 675 | } else if (!strcasecmp(n->z_class, "login")) { |
---|
| 676 | char *ptr, host[LINE], tty[LINE]; |
---|
| 677 | int len; |
---|
| 678 | |
---|
| 679 | ptr=owl_zephyr_get_field(n, 1, &len); |
---|
| 680 | strncpy(host, ptr, len); |
---|
| 681 | host[len]='\0'; |
---|
| 682 | ptr=owl_zephyr_get_field(n, 3, &len); |
---|
| 683 | strncpy(tty, ptr, len); |
---|
| 684 | tty[len]='\0'; |
---|
| 685 | |
---|
| 686 | if (!strcasecmp(n->z_opcode, "user_login")) { |
---|
| 687 | owl_fmtext_append_bold(&(m->fmtext), "LOGIN"); |
---|
| 688 | } else if (!strcasecmp(n->z_opcode, "user_logout")) { |
---|
| 689 | owl_fmtext_append_bold(&(m->fmtext), "LOGOUT"); |
---|
| 690 | } |
---|
| 691 | owl_fmtext_append_normal(&(m->fmtext), " for "); |
---|
[4b464a4] | 692 | ptr=short_zuser(n->z_class_inst); |
---|
[7d4fbcd] | 693 | owl_fmtext_append_bold(&(m->fmtext), ptr); |
---|
| 694 | owl_free(ptr); |
---|
| 695 | owl_fmtext_append_normal(&(m->fmtext), " at "); |
---|
| 696 | owl_fmtext_append_normal(&(m->fmtext), host); |
---|
| 697 | owl_fmtext_append_normal(&(m->fmtext), " "); |
---|
| 698 | owl_fmtext_append_normal(&(m->fmtext), tty); |
---|
| 699 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 700 | } else { |
---|
[d0d65df] | 701 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m)); |
---|
[7d4fbcd] | 702 | owl_fmtext_append_normal(&(m->fmtext), " / "); |
---|
[d0d65df] | 703 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m)); |
---|
[7d4fbcd] | 704 | owl_fmtext_append_normal(&(m->fmtext), " / "); |
---|
| 705 | owl_fmtext_append_bold(&(m->fmtext), frombuff); |
---|
| 706 | if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) { |
---|
| 707 | owl_fmtext_append_normal(&(m->fmtext), " {"); |
---|
| 708 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m)); |
---|
| 709 | owl_fmtext_append_normal(&(m->fmtext), "} "); |
---|
| 710 | } |
---|
| 711 | if (n->z_opcode[0]!='\0') { |
---|
| 712 | owl_fmtext_append_normal(&(m->fmtext), " ["); |
---|
[d0d65df] | 713 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_opcode(m)); |
---|
[7d4fbcd] | 714 | owl_fmtext_append_normal(&(m->fmtext), "] "); |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | /* stick on the zsig */ |
---|
[a3ba748] | 718 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b45293f] | 719 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 720 | owl_fmtext_append_normal(&(m->fmtext), " ("); |
---|
| 721 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 722 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
[7d4fbcd] | 723 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
[b45293f] | 724 | owl_free(zsigbuff); |
---|
| 725 | |
---|
| 726 | /* then the indented message */ |
---|
[7d4fbcd] | 727 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 728 | |
---|
| 729 | /* make personal messages bold for smaat users */ |
---|
| 730 | if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 731 | if (owl_message_is_personal(m)) { |
---|
| 732 | owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD); |
---|
| 733 | } |
---|
| 734 | } |
---|
| 735 | } |
---|
| 736 | |
---|
| 737 | owl_free(body); |
---|
| 738 | owl_free(indent); |
---|
| 739 | } |
---|
| 740 | |
---|
| 741 | void _owl_message_make_text_from_notice_simple(owl_message *m) { |
---|
[b45293f] | 742 | char *body, *indent, *ptr, *zsigbuff, frombuff[LINE]; |
---|
[7d4fbcd] | 743 | ZNotice_t *n; |
---|
| 744 | |
---|
| 745 | n=&(m->notice); |
---|
[d309eb3] | 746 | |
---|
| 747 | /* get the body */ |
---|
[ecd5dc5] | 748 | body=owl_strdup(owl_message_get_body(m)); |
---|
| 749 | body=realloc(body, strlen(body)+30); |
---|
[7d4fbcd] | 750 | |
---|
| 751 | /* add a newline if we need to */ |
---|
| 752 | if (body[0]!='\0' && body[strlen(body)-1]!='\n') { |
---|
| 753 | strcat(body, "\n"); |
---|
| 754 | } |
---|
| 755 | |
---|
| 756 | /* do the indenting into indent */ |
---|
| 757 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10); |
---|
| 758 | owl_text_indent(indent, body, OWL_MSGTAB); |
---|
| 759 | |
---|
| 760 | /* edit the from addr for printing */ |
---|
[d0d65df] | 761 | strcpy(frombuff, owl_message_get_sender(m)); |
---|
[7d4fbcd] | 762 | ptr=strchr(frombuff, '@'); |
---|
| 763 | if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) { |
---|
| 764 | *ptr='\0'; |
---|
| 765 | } |
---|
| 766 | |
---|
| 767 | /* set the message for printing */ |
---|
| 768 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 769 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 770 | |
---|
[d0d65df] | 771 | if (!strcasecmp(owl_message_get_opcode(m), "ping")) { |
---|
[7d4fbcd] | 772 | owl_fmtext_append_bold(&(m->fmtext), "PING"); |
---|
| 773 | owl_fmtext_append_normal(&(m->fmtext), " from "); |
---|
| 774 | owl_fmtext_append_bold(&(m->fmtext), frombuff); |
---|
| 775 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
[d0d65df] | 776 | } else if (!strcasecmp(owl_message_get_class(m), "login")) { |
---|
[7d4fbcd] | 777 | char *ptr, host[LINE], tty[LINE]; |
---|
| 778 | int len; |
---|
| 779 | |
---|
| 780 | ptr=owl_zephyr_get_field(n, 1, &len); |
---|
| 781 | strncpy(host, ptr, len); |
---|
| 782 | host[len]='\0'; |
---|
| 783 | ptr=owl_zephyr_get_field(n, 3, &len); |
---|
| 784 | strncpy(tty, ptr, len); |
---|
| 785 | tty[len]='\0'; |
---|
| 786 | |
---|
[d0d65df] | 787 | if (!strcasecmp(owl_message_get_opcode(m), "user_login")) { |
---|
[7d4fbcd] | 788 | owl_fmtext_append_bold(&(m->fmtext), "LOGIN"); |
---|
[d0d65df] | 789 | } else if (!strcasecmp(owl_message_get_opcode(m), "user_logout")) { |
---|
[7d4fbcd] | 790 | owl_fmtext_append_bold(&(m->fmtext), "LOGOUT"); |
---|
| 791 | } |
---|
| 792 | owl_fmtext_append_normal(&(m->fmtext), " for "); |
---|
[d0d65df] | 793 | ptr=short_zuser(owl_message_get_instance(m)); |
---|
[7d4fbcd] | 794 | owl_fmtext_append_bold(&(m->fmtext), ptr); |
---|
| 795 | owl_free(ptr); |
---|
| 796 | owl_fmtext_append_normal(&(m->fmtext), " at "); |
---|
| 797 | owl_fmtext_append_normal(&(m->fmtext), host); |
---|
| 798 | owl_fmtext_append_normal(&(m->fmtext), " "); |
---|
| 799 | owl_fmtext_append_normal(&(m->fmtext), tty); |
---|
| 800 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 801 | } else { |
---|
| 802 | owl_fmtext_append_normal(&(m->fmtext), "From: "); |
---|
[d0d65df] | 803 | if (strcasecmp(owl_message_get_class(m), "message")) { |
---|
[7d4fbcd] | 804 | owl_fmtext_append_normal(&(m->fmtext), "Class "); |
---|
[d0d65df] | 805 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m)); |
---|
[7d4fbcd] | 806 | owl_fmtext_append_normal(&(m->fmtext), " / Instance "); |
---|
[d0d65df] | 807 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m)); |
---|
[7d4fbcd] | 808 | owl_fmtext_append_normal(&(m->fmtext), " / "); |
---|
| 809 | } |
---|
| 810 | owl_fmtext_append_normal(&(m->fmtext), frombuff); |
---|
| 811 | if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) { |
---|
| 812 | owl_fmtext_append_normal(&(m->fmtext), " {"); |
---|
| 813 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m)); |
---|
| 814 | owl_fmtext_append_normal(&(m->fmtext), "} "); |
---|
| 815 | } |
---|
| 816 | |
---|
| 817 | /* stick on the zsig */ |
---|
[a3ba748] | 818 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b45293f] | 819 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 820 | owl_fmtext_append_normal(&(m->fmtext), " ("); |
---|
| 821 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 822 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
[7d4fbcd] | 823 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
[b45293f] | 824 | owl_free(zsigbuff); |
---|
| 825 | |
---|
| 826 | /* then the indented message */ |
---|
[7d4fbcd] | 827 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 828 | |
---|
| 829 | /* make personal messages bold for smaat users */ |
---|
| 830 | if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 831 | if (owl_message_is_personal(m)) { |
---|
| 832 | owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD); |
---|
| 833 | } |
---|
| 834 | } |
---|
| 835 | } |
---|
| 836 | |
---|
| 837 | owl_free(body); |
---|
| 838 | owl_free(indent); |
---|
| 839 | } |
---|
| 840 | |
---|
[b45293f] | 841 | void owl_message_pretty_zsig(owl_message *m, char *buff) { |
---|
| 842 | /* stick a one line version of the zsig in buff */ |
---|
[7d4fbcd] | 843 | char *ptr; |
---|
| 844 | |
---|
[d0d65df] | 845 | strcpy(buff, owl_message_get_zsig(m)); |
---|
[b45293f] | 846 | ptr=strchr(buff, '\n'); |
---|
| 847 | if (ptr) ptr[0]='\0'; |
---|
[7d4fbcd] | 848 | } |
---|
| 849 | |
---|
| 850 | void owl_message_free(owl_message *m) { |
---|
[d0d65df] | 851 | int i, j; |
---|
| 852 | owl_pair *p; |
---|
| 853 | |
---|
[4b464a4] | 854 | if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) { |
---|
[7d4fbcd] | 855 | ZFreeNotice(&(m->notice)); |
---|
| 856 | } |
---|
| 857 | if (m->time) owl_free(m->time); |
---|
| 858 | if (m->zwriteline) owl_free(m->zwriteline); |
---|
[d0d65df] | 859 | |
---|
| 860 | /* free all the attributes */ |
---|
| 861 | j=owl_list_get_size(&(m->attributes)); |
---|
| 862 | for (i=0; i<j; i++) { |
---|
| 863 | p=owl_list_get_element(&(m->attributes), i); |
---|
| 864 | owl_free(owl_pair_get_key(p)); |
---|
| 865 | owl_free(owl_pair_get_value(p)); |
---|
| 866 | owl_free(p); |
---|
| 867 | } |
---|
| 868 | |
---|
| 869 | owl_list_free_simple(&(m->attributes)); |
---|
[7d4fbcd] | 870 | |
---|
| 871 | owl_fmtext_free(&(m->fmtext)); |
---|
| 872 | } |
---|