1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
|
/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
/* Balsa E-Mail Client
*
* Copyright (C) 1997-2002 Stuart Parmenter and others,
* See the file AUTHORS for a list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <glib.h>
#include <fcntl.h>
#include "libbalsa.h"
#include "misc.h"
#include "i18n.h"
LibBalsaMessageBody *
libbalsa_message_body_new(LibBalsaMessage * message)
{
LibBalsaMessageBody *body;
body = g_new0(LibBalsaMessageBody, 1);
body->message = message;
body->buffer = NULL;
body->embhdrs = NULL;
body->content_type = NULL;
body->filename = NULL;
body->temp_filename = NULL;
body->charset = NULL;
#ifdef HAVE_GPGME
body->was_encrypted = FALSE;
body->sig_info = NULL;
#endif
body->next = NULL;
body->parts = NULL;
body->mime_part = NULL;
return body;
}
void
libbalsa_message_body_free(LibBalsaMessageBody * body)
{
if (body == NULL)
return;
g_free(body->buffer);
libbalsa_message_headers_destroy(body->embhdrs);
g_free(body->content_type);
g_free(body->filename);
if (body->temp_filename)
unlink(body->temp_filename);
g_free(body->temp_filename);
g_free(body->charset);
#ifdef HAVE_GPGME
if (body->sig_info)
g_object_unref(G_OBJECT(body->sig_info));
#endif
libbalsa_message_body_free(body->next);
libbalsa_message_body_free(body->parts);
if (body->mime_part)
g_object_unref(body->mime_part);
g_free(body);
}
static LibBalsaMessageHeaders *
libbalsa_message_body_extract_embedded_headers(GMimeMessage* msg)
{
LibBalsaMessageHeaders *ehdr;
const char *subj;
int offset;
ehdr = g_new0(LibBalsaMessageHeaders, 1);
libbalsa_message_headers_from_gmime(ehdr, msg);
ehdr->user_hdrs = libbalsa_message_user_hdrs_from_gmime(msg);
subj = g_mime_message_get_subject(msg);
if (subj) {
ehdr->subject =
g_mime_utils_header_decode_text((const unsigned char *) subj);
libbalsa_utf8_sanitize(&ehdr->subject, TRUE, NULL);
} else
ehdr->subject = g_strdup(_("(No subject)"));
g_mime_message_get_date(msg, &ehdr->date, &offset);
return ehdr;
}
/* Create a LibBalsaMessageBody with structure matching the GMimeObject;
* the body may already have the necessary parts, so we check before
* allocating new ones; it may have too many, so we free any that are no
* longer needed.
*/
/* First some helpers. */
static void
libbalsa_message_body_set_filename(LibBalsaMessageBody * body)
{
if (GMIME_IS_PART(body->mime_part)) {
g_free(body->filename);
body->filename =
g_strdup(g_mime_part_get_filename(GMIME_PART(body->mime_part)));
}
}
static void
libbalsa_message_body_set_types(LibBalsaMessageBody * body)
{
const GMimeContentType *type;
type = g_mime_object_get_content_type(body->mime_part);
if (g_mime_content_type_is_type(type, "audio", "*"))
body->body_type = LIBBALSA_MESSAGE_BODY_TYPE_AUDIO;
else if (g_mime_content_type_is_type(type, "application", "*"))
body->body_type = LIBBALSA_MESSAGE_BODY_TYPE_APPLICATION;
else if (g_mime_content_type_is_type(type, "image", "*"))
body->body_type = LIBBALSA_MESSAGE_BODY_TYPE_IMAGE;
else if (g_mime_content_type_is_type(type, "message", "*"))
body->body_type = LIBBALSA_MESSAGE_BODY_TYPE_MESSAGE;
else if (g_mime_content_type_is_type(type, "model", "*"))
body->body_type = LIBBALSA_MESSAGE_BODY_TYPE_MODEL;
else if (g_mime_content_type_is_type(type, "multipart", "*"))
body->body_type = LIBBALSA_MESSAGE_BODY_TYPE_MULTIPART;
else if (g_mime_content_type_is_type(type, "text", "*"))
body->body_type = LIBBALSA_MESSAGE_BODY_TYPE_TEXT;
else if (g_mime_content_type_is_type(type, "video", "*"))
body->body_type = LIBBALSA_MESSAGE_BODY_TYPE_VIDEO;
else body->body_type = LIBBALSA_MESSAGE_BODY_TYPE_OTHER;
g_free(body->content_type);
body->content_type = g_mime_content_type_to_string(type);
}
static LibBalsaMessageBody **
libbalsa_message_body_set_message_part(LibBalsaMessageBody * body,
LibBalsaMessageBody ** next_part)
{
GMimeMessagePart *message_part;
GMimeMessage *embedded_message;
message_part = GMIME_MESSAGE_PART(body->mime_part);
embedded_message = g_mime_message_part_get_message(message_part);
libbalsa_message_headers_destroy(body->embhdrs);
body->embhdrs =
libbalsa_message_body_extract_embedded_headers(embedded_message);
if (!*next_part)
*next_part = libbalsa_message_body_new(body->message);
libbalsa_message_body_set_mime_body(*next_part,
embedded_message->mime_part);
g_object_unref(embedded_message);
return &(*next_part)->next;
}
static LibBalsaMessageBody **
libbalsa_message_body_set_multipart(LibBalsaMessageBody * body,
LibBalsaMessageBody ** next_part)
{
GList *child;
for (child = GMIME_MULTIPART(body->mime_part)->subparts; child;
child = child->next) {
if (!*next_part)
*next_part = libbalsa_message_body_new(body->message);
libbalsa_message_body_set_mime_body(*next_part, child->data);
next_part = &(*next_part)->next;
}
return next_part;
}
static void
libbalsa_message_body_set_parts(LibBalsaMessageBody * body)
{
LibBalsaMessageBody **next_part = &body->parts;
if (GMIME_IS_MESSAGE_PART(body->mime_part))
next_part = libbalsa_message_body_set_message_part(body, next_part);
else if (GMIME_IS_MULTIPART(body->mime_part))
next_part = libbalsa_message_body_set_multipart(body, next_part);
/* Free any parts that weren't used; the test isn't strictly
* necessary, but it should fail unless something really strange has
* happened, so it's worth including. */
if (*next_part) {
libbalsa_message_body_free(*next_part);
*next_part = NULL;
}
}
void
libbalsa_message_body_set_mime_body(LibBalsaMessageBody * body,
GMimeObject * mime_part)
{
g_return_if_fail(body != NULL);
g_return_if_fail(GMIME_IS_OBJECT(mime_part));
g_object_ref(mime_part);
if (body->mime_part)
g_object_unref(body->mime_part);
body->mime_part = mime_part;
libbalsa_message_body_set_filename(body);
libbalsa_message_body_set_types(body);
libbalsa_message_body_set_parts(body);
}
LibBalsaMessageBodyType
libbalsa_message_body_type(LibBalsaMessageBody * body)
{
/* FIXME: this could be a virtual function... OR not? */
return body->body_type;
}
gchar *
libbalsa_message_body_get_parameter(LibBalsaMessageBody * body,
const gchar * param)
{
gchar *res;
g_return_val_if_fail(body != NULL, NULL);
if (body->mime_part) {
const GMimeContentType *type =
g_mime_object_get_content_type(body->mime_part);
res = g_strdup(g_mime_content_type_get_parameter(type, param));
} else {
GMimeContentType *type =
g_mime_content_type_new_from_string(body->content_type);
res = g_strdup(g_mime_content_type_get_parameter(type, param));
g_mime_content_type_destroy(type);
}
return res;
}
/* libbalsa_message_body_save_temporary:
check if body has already its copy in temporary file and if not,
allocates a temporary file name and saves the body there.
*/
gboolean
libbalsa_message_body_save_temporary(LibBalsaMessageBody * body, GError **err)
{
if (body->temp_filename == NULL) {
gint count = 100; /* Magic number, same as in g_mkstemp. */
/* We want a temporary file with a name that ends with the same
* set of suffices as body->filename (for the benefit of helpers
* that depend on such things); however, g_file_open_tmp() works
* only with templates that end with "XXXXXX", so we fake it. */
do {
gint fd;
gchar *tmp_file_name;
gchar *dotpos = NULL;
fd = g_file_open_tmp("balsa-body-XXXXXX", &tmp_file_name,
err);
if (fd < 0)
return FALSE;
if (err && *err && /* We should have returned by now! */
(*err)->message) {
printf("libbalsa_message_body_save_temporary:\n %s\n",
(*err)->message);
g_clear_error(err);
}
close(fd);
unlink(tmp_file_name);
if (body->filename) {
gchar *seppos = strrchr(body->filename, G_DIR_SEPARATOR);
dotpos = strchr(seppos ? seppos : body->filename, '.');
}
g_free(body->temp_filename);
if (dotpos) {
body->temp_filename =
g_strdup_printf("%s%s", tmp_file_name, dotpos);
g_free(tmp_file_name);
} else
body->temp_filename = tmp_file_name;
fd = open(body->temp_filename, O_WRONLY | O_EXCL | O_CREAT,
LIBBALSA_MESSAGE_BODY_SAFE);
if (fd >= 0)
return libbalsa_message_body_save_fd(body, fd, FALSE, err);
} while (errno == EEXIST && --count > 0);
/* Either we hit a real error, or we used up 100 attempts. */
return FALSE;
} else {
/* the temporary name has been already allocated on previous
save_temporary action. We just check if the file is still there.
*/
struct stat s;
if (stat(body->temp_filename, &s) == 0 &&
S_ISREG(s.st_mode) &&
s.st_uid == getuid())
return TRUE;
else
return libbalsa_message_body_save(body, body->temp_filename,
LIBBALSA_MESSAGE_BODY_SAFE,
FALSE, err);
}
}
/* libbalsa_message_body_save:
NOTE: has to use libbalsa_safe_open to set the file access privileges
to safe.
*/
gboolean
libbalsa_message_body_save(LibBalsaMessageBody * body,
const gchar * filename, mode_t mode,
gboolean filter_crlf,
GError **err)
{
int fd;
int flags = O_CREAT | O_EXCL | O_WRONLY;
#ifdef O_NOFOLLOW
flags |= O_NOFOLLOW;
#endif
if ((fd=libbalsa_safe_open(filename, flags, mode)) < 0)
return FALSE;
return libbalsa_message_body_save_fd(body, fd, filter_crlf, err);
}
static GMimeStream *
libbalsa_message_body_stream_add_filter(GMimeStream * stream,
GMimeFilter * filter)
{
if (!GMIME_IS_STREAM_FILTER(stream)) {
GMimeStream *filtered_stream =
g_mime_stream_filter_new_with_stream(stream);
g_object_unref(stream);
stream = filtered_stream;
}
g_mime_stream_filter_add(GMIME_STREAM_FILTER(stream), filter);
g_object_unref(filter);
return stream;
}
GMimeStream *
libbalsa_message_body_get_stream(LibBalsaMessageBody * body, GError **err)
{
GMimeStream *stream;
GMimeFilter *filter;
gchar *mime_type = NULL;
const gchar *charset;
g_return_val_if_fail(body != NULL, NULL);
g_return_val_if_fail(body->message != NULL, NULL);
if (body->message->mailbox) {
GMimeDataWrapper *wrapper;
GMimePartEncodingType encoding;
if(!libbalsa_mailbox_get_message_part(body->message, body, err))
return NULL;
wrapper =
g_mime_part_get_content_object(GMIME_PART(body->mime_part));
stream = g_mime_data_wrapper_get_stream(wrapper);
encoding = g_mime_data_wrapper_get_encoding(wrapper);
g_object_unref(wrapper);
switch (encoding) {
case GMIME_PART_ENCODING_BASE64:
filter =
g_mime_filter_basic_new_type
(GMIME_FILTER_BASIC_BASE64_DEC);
stream =
libbalsa_message_body_stream_add_filter(stream, filter);
break;
case GMIME_PART_ENCODING_QUOTEDPRINTABLE:
filter =
g_mime_filter_basic_new_type(GMIME_FILTER_BASIC_QP_DEC);
stream =
libbalsa_message_body_stream_add_filter(stream, filter);
break;
case GMIME_PART_ENCODING_UUENCODE:
filter =
g_mime_filter_basic_new_type(GMIME_FILTER_BASIC_UU_DEC);
stream =
libbalsa_message_body_stream_add_filter(stream, filter);
break;
default:
break;
}
} else if (body->mime_part) {
/* Not a GMimePart... */
GMimeObject *object = body->mime_part;
if (GMIME_IS_MESSAGE_PART(object))
object = GMIME_OBJECT(g_mime_message_part_get_message
((GMimeMessagePart *) object));
else
g_object_ref(object);
stream = g_mime_stream_mem_new();
libbalsa_mailbox_lock_store(body->message->mailbox);
g_mime_object_write_to_stream(object, stream);
libbalsa_mailbox_unlock_store(body->message->mailbox);
g_object_unref(object);
} else {
g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_ACCESS_ERROR,
"Internal error in get_stream");
return NULL;
}
/* convert text bodies but HTML - gtkhtml does conversion on its own. */
if (libbalsa_message_body_type(body) == LIBBALSA_MESSAGE_BODY_TYPE_TEXT
&& strcmp(mime_type = libbalsa_message_body_get_mime_type(body),
"text/html") != 0
&& (charset = libbalsa_message_body_charset(body)) != NULL
&& g_ascii_strcasecmp(charset, "unknown-8bit") != 0) {
GMimeStream *stream_null;
GMimeStream *stream_filter;
GMimeFilter *filter_windows;
stream_null = g_mime_stream_null_new();
stream_filter = g_mime_stream_filter_new_with_stream(stream_null);
g_object_unref(stream_null);
filter_windows = g_mime_filter_windows_new(charset);
g_mime_stream_filter_add(GMIME_STREAM_FILTER(stream_filter),
filter_windows);
libbalsa_mailbox_lock_store(body->message->mailbox);
g_mime_stream_reset(stream);
g_mime_stream_write_to_stream(stream, stream_filter);
libbalsa_mailbox_unlock_store(body->message->mailbox);
g_object_unref(stream_filter);
charset = g_mime_filter_windows_real_charset(GMIME_FILTER_WINDOWS
(filter_windows));
if ((filter = g_mime_filter_charset_new(charset, "UTF-8"))) {
stream =
libbalsa_message_body_stream_add_filter(stream, filter);
g_free(body->charset);
body->charset = g_strdup(charset);
}
g_object_unref(filter_windows);
}
g_free(mime_type);
return stream;
}
gssize
libbalsa_message_body_get_content(LibBalsaMessageBody * body, gchar ** buf,
GError **err)
{
GMimeStream *stream, *stream_mem;
GByteArray *array;
gssize len;
g_return_val_if_fail(body != NULL, -1);
g_return_val_if_fail(body->message != NULL, -1);
g_return_val_if_fail(buf != NULL, -1);
*buf = NULL;
stream = libbalsa_message_body_get_stream(body, err);
if (!stream)
return -1;
array = g_byte_array_new();
stream_mem = g_mime_stream_mem_new_with_byte_array(array);
g_mime_stream_mem_set_owner(GMIME_STREAM_MEM(stream_mem), FALSE);
libbalsa_mailbox_lock_store(body->message->mailbox);
g_mime_stream_reset(stream);
len = g_mime_stream_write_to_stream(stream, stream_mem);
libbalsa_mailbox_unlock_store(body->message->mailbox);
g_object_unref(stream);
g_object_unref(stream_mem);
if (len >= 0) {
guint8 zero = 0;
len = array->len;
/* NULL-terminate, in case it is used as a string. */
g_byte_array_append(array, &zero, 1);
*buf = (gchar *) g_byte_array_free(array, FALSE);
} else
g_byte_array_free(array, TRUE);
return len;
}
GdkPixbuf *
libbalsa_message_body_get_pixbuf(LibBalsaMessageBody * body, GError ** err)
{
GdkPixbufLoader *loader;
GMimeStream *stream;
gssize count;
gboolean ok = TRUE;
gchar buf[4096];
GdkPixbuf *pixbuf = NULL;
stream = libbalsa_message_body_get_stream(body, err);
if (!stream)
return pixbuf;
libbalsa_mailbox_lock_store(body->message->mailbox);
g_mime_stream_reset(stream);
loader = gdk_pixbuf_loader_new();
while ((count = g_mime_stream_read(stream, buf, sizeof(buf))) > 0) {
if (!gdk_pixbuf_loader_write(loader, (guchar *) buf, count, err)) {
ok = FALSE;
break;
}
}
libbalsa_mailbox_unlock_store(body->message->mailbox);
g_object_unref(stream);
if (!gdk_pixbuf_loader_close(loader, ok ? err : NULL))
ok = FALSE;
if (ok) {
pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
g_object_ref(pixbuf);
}
g_object_unref(loader);
return pixbuf;
}
gboolean
libbalsa_message_body_save_fd(LibBalsaMessageBody * body, int fd,
gboolean filter_crlf, GError ** err)
{
GMimeStream *stream, *stream_fs;
ssize_t len;
stream = libbalsa_message_body_get_stream(body, err);
if (!body->mime_part)
return FALSE;
stream_fs = g_mime_stream_fs_new(fd);
libbalsa_mailbox_lock_store(body->message->mailbox);
if (stream) {
g_mime_stream_reset(stream);
if (filter_crlf) {
GMimeFilter *filter;
if (!GMIME_IS_STREAM_FILTER(stream)) {
GMimeStream *stream_filter =
g_mime_stream_filter_new_with_stream(stream);
g_object_unref(stream);
stream = stream_filter;
}
filter = g_mime_filter_crlf_new(GMIME_FILTER_CRLF_DECODE,
GMIME_FILTER_CRLF_MODE_CRLF_ONLY);
g_mime_stream_filter_add(GMIME_STREAM_FILTER(stream), filter);
g_object_unref(filter);
}
len = g_mime_stream_write_to_stream(stream, stream_fs);
g_object_unref(stream);
} else {
/* body->mime_part is not a GMimePart. */
GMimeObject *mime_part = body->mime_part;
if (GMIME_IS_MESSAGE_PART(mime_part))
/* The user probably wants the message without the part's
* mime headers. */
mime_part =
GMIME_OBJECT(GMIME_MESSAGE_PART(mime_part)->message);
len = g_mime_object_write_to_stream(mime_part, stream_fs);
}
libbalsa_mailbox_unlock_store(body->message->mailbox);
g_object_unref(stream_fs);
return len >= 0;
}
gchar *
libbalsa_message_body_get_mime_type(LibBalsaMessageBody * body)
{
gchar *res, *tmp;
g_return_val_if_fail(body != NULL, NULL);
if (!body->content_type)
return g_strdup("text/plain");
tmp = strchr(body->content_type, ';');
res = g_ascii_strdown(body->content_type,
tmp ? tmp-body->content_type : -1);
return res;
}
gboolean
libbalsa_message_body_is_multipart(LibBalsaMessageBody * body)
{
return body->mime_part ?
GMIME_IS_MULTIPART(body->mime_part) :
body->body_type == LIBBALSA_MESSAGE_BODY_TYPE_MULTIPART;
}
gboolean
libbalsa_message_body_is_inline(LibBalsaMessageBody * body)
{
const gchar *disposition;
g_return_val_if_fail(body->mime_part == NULL ||
GMIME_IS_OBJECT(body->mime_part), FALSE);
if (body->mime_part)
disposition = g_mime_object_get_header(body->mime_part,
"Content-Disposition");
else
disposition = body->content_dsp;
if (!disposition)
/* Default disposition is in-line for text/plain, and generally
* attachment for other content types. Default content type is
* text/plain except in multipart/digest, where it is
* message/rfc822; in either case, we want to in-line the part.
*/
return (body->content_type == NULL
|| g_ascii_strcasecmp(body->content_type,
"message/rfc822") == 0
|| g_ascii_strcasecmp(body->content_type,
"text/plain") == 0);
return g_ascii_strncasecmp(disposition,
GMIME_DISPOSITION_INLINE,
strlen(GMIME_DISPOSITION_INLINE)) == 0;
}
/* libbalsa_message_body_is_flowed:
* test whether a message body is format=flowed */
gboolean
libbalsa_message_body_is_flowed(LibBalsaMessageBody * body)
{
gchar *content_type;
gboolean flowed = FALSE;
content_type = libbalsa_message_body_get_mime_type(body);
if (g_ascii_strcasecmp(content_type, "text/plain") == 0) {
gchar *format =
libbalsa_message_body_get_parameter(body, "format");
if (format) {
flowed = (g_ascii_strcasecmp(format, "flowed") == 0);
g_free(format);
}
}
g_free(content_type);
return flowed;
}
gboolean
libbalsa_message_body_is_delsp(LibBalsaMessageBody * body)
{
gboolean delsp = FALSE;
if (libbalsa_message_body_is_flowed(body)) {
gchar *delsp_param =
libbalsa_message_body_get_parameter(body, "delsp");
if (delsp_param) {
delsp = (g_ascii_strcasecmp(delsp_param, "yes") == 0);
g_free(delsp_param);
}
}
return delsp;
}
LibBalsaMessageBody *
libbalsa_message_body_get_by_id(LibBalsaMessageBody * body,
const gchar * id)
{
LibBalsaMessageBody *res;
g_return_val_if_fail(id != NULL, NULL);
if (!body)
return NULL;
if (body->mime_part) {
const gchar *bodyid =
g_mime_object_get_content_id(body->mime_part);
if (bodyid && strcmp(id, bodyid) == 0)
return body;
} else {
if(body->content_id && strcmp(id, body->content_id) == 0)
return body;
}
if ((res = libbalsa_message_body_get_by_id(body->parts, id)) != NULL)
return res;
return libbalsa_message_body_get_by_id(body->next, id);
}
#ifdef HAVE_GPGME
LibBalsaMsgProtectState
libbalsa_message_body_protect_state(LibBalsaMessageBody *body)
{
if (!body || !body->sig_info ||
body->sig_info->status == GPG_ERR_NOT_SIGNED ||
body->sig_info->status == GPG_ERR_CANCELED)
return LIBBALSA_MSG_PROTECT_NONE;
if (body->sig_info->status == GPG_ERR_NO_ERROR) {
/* good signature, check if the validity and trust (OpenPGP only) are
at least marginal */
if (body->sig_info->validity >= GPGME_VALIDITY_MARGINAL &&
(body->sig_info->protocol == GPGME_PROTOCOL_CMS ||
body->sig_info->trust >= GPGME_VALIDITY_MARGINAL))
return LIBBALSA_MSG_PROTECT_SIGN_GOOD;
else
return LIBBALSA_MSG_PROTECT_SIGN_NOTRUST;
}
return LIBBALSA_MSG_PROTECT_SIGN_BAD;
}
#endif
|