CamelMimePart * mail_tool_make_message_attachment (CamelMimeMessage *message) { CamelMimePart *part; const char *subject; struct _camel_header_raw *xev; char *desc; subject = camel_mime_message_get_subject (message); if (subject) desc = g_strdup_printf (_("Forwarded message - %s"), subject); else desc = g_strdup (_("Forwarded message")); /* rip off the X-Evolution headers */ xev = mail_tool_remove_xevolution_headers (message); camel_header_raw_clear(&xev); /* remove Bcc headers */ camel_medium_remove_header (CAMEL_MEDIUM (message), "Bcc"); part = camel_mime_part_new (); camel_mime_part_set_disposition (part, "inline"); camel_mime_part_set_description (part, desc); camel_medium_set_content_object (CAMEL_MEDIUM (part), CAMEL_DATA_WRAPPER (message)); camel_mime_part_set_content_type (part, "message/rfc822"); g_free (desc); return part; }
ESource * em_utils_guess_mail_account (ESourceRegistry *registry, CamelMimeMessage *message, CamelFolder *folder, const gchar *message_uid) { ESource *source = NULL; const gchar *newsgroups; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL); g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL); if (folder != NULL) g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL); /* check for newsgroup header */ newsgroups = camel_medium_get_header ( CAMEL_MEDIUM (message), "Newsgroups"); if (folder != NULL && newsgroups != NULL) source = guess_mail_account_from_folder (registry, folder, message_uid); /* check for source folder */ if (source == NULL && folder != NULL) source = guess_mail_account_from_folder (registry, folder, message_uid); /* then message source */ if (source == NULL) source = guess_mail_account_from_message (registry, message); return source; }
static CamelSExpResult * header_regex (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms) { CamelSExpResult *r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL); CamelMimeMessage *message; regex_t pattern; gchar *contents = NULL; message = camel_filter_search_get_message (fms, f); if (argc > 1 && argv[0]->type == CAMEL_SEXP_RES_STRING && (contents = camel_search_get_header_decoded (argv[0]->value.string, camel_medium_get_header (CAMEL_MEDIUM (message), argv[0]->value.string), camel_search_get_default_charset_from_message (message))) && camel_search_build_match_regex (&pattern, CAMEL_SEARCH_MATCH_REGEX | CAMEL_SEARCH_MATCH_ICASE, argc - 1, argv + 1, fms->error) == 0) { r->value.boolean = regexec (&pattern, contents, 0, NULL, 0) == 0; regfree (&pattern); } else r->value.boolean = FALSE; g_free (contents); return r; }
/* Helper for e_mail_session_ref_transport_for_message() */ static CamelService * mail_session_ref_transport_from_x_identity (EMailSession *session, CamelMimeMessage *message) { ESource *source; ESourceRegistry *registry; CamelMedium *medium; CamelService *transport; const gchar *header_name; const gchar *header_value; gchar *uid; medium = CAMEL_MEDIUM (message); header_name = "X-Evolution-Identity"; header_value = camel_medium_get_header (medium, header_name); if (header_value == NULL) return NULL; uid = g_strstrip (g_strdup (header_value)); registry = e_mail_session_get_registry (session); source = e_source_registry_ref_source (registry, uid); transport = mail_session_ref_transport_for_identity (session, source); g_clear_object (&source); g_free (uid); return transport; }
/* there is also an identical copy of this in camel-filter-search.c */ gboolean camel_search_message_body_contains (CamelDataWrapper *object, regex_t *pattern) { CamelDataWrapper *containee; int truth = FALSE; int parts, i; containee = camel_medium_get_content_object (CAMEL_MEDIUM (object)); if (containee == NULL) return FALSE; /* using the object types is more accurate than using the mime/types */ if (CAMEL_IS_MULTIPART (containee)) { parts = camel_multipart_get_number (CAMEL_MULTIPART (containee)); for (i = 0; i < parts && truth == FALSE; i++) { CamelDataWrapper *part = (CamelDataWrapper *)camel_multipart_get_part (CAMEL_MULTIPART (containee), i); if (part) truth = camel_search_message_body_contains (part, pattern); } } else if (CAMEL_IS_MIME_MESSAGE (containee)) { /* for messages we only look at its contents */ truth = camel_search_message_body_contains ((CamelDataWrapper *)containee, pattern); } else if (camel_content_type_is(CAMEL_DATA_WRAPPER (containee)->mime_type, "text", "*")) { /* for all other text parts, we look inside, otherwise we dont care */ CamelStreamMem *mem = (CamelStreamMem *)camel_stream_mem_new (); camel_data_wrapper_write_to_stream (containee, CAMEL_STREAM (mem)); camel_stream_write (CAMEL_STREAM (mem), "", 1); truth = regexec (pattern, (char *) mem->buffer->data, 0, NULL, 0) == 0; camel_object_unref (mem); } return truth; }
static void import_mbox_add_message (CamelFolder *folder, CamelMimeMessage *msg, GCancellable *cancellable, GError **error) { CamelMessageInfo *info; CamelMedium *medium; guint32 flags = 0; const gchar *tmp; g_return_if_fail (CAMEL_IS_FOLDER (folder)); g_return_if_fail (CAMEL_IS_MIME_MESSAGE (msg)); medium = CAMEL_MEDIUM (msg); tmp = camel_medium_get_header (medium, "X-Mozilla-Status"); if (tmp) flags |= decode_mozilla_status (tmp); tmp = camel_medium_get_header (medium, "Status"); if (tmp) flags |= decode_status (tmp); tmp = camel_medium_get_header (medium, "X-Status"); if (tmp) flags |= decode_status (tmp); info = camel_message_info_new (NULL); camel_message_info_set_flags (info, flags, ~0); camel_folder_append_message_sync ( folder, msg, info, NULL, cancellable, error); camel_message_info_unref (info); }
/* Helper for e_mail_session_ref_transport_for_message() */ static CamelService * mail_session_ref_transport_from_x_transport (EMailSession *session, CamelMimeMessage *message) { CamelMedium *medium; CamelService *transport; const gchar *header_name; const gchar *header_value; gchar *uid; medium = CAMEL_MEDIUM (message); header_name = "X-Evolution-Transport"; header_value = camel_medium_get_header (medium, header_name); if (header_value == NULL) return NULL; uid = g_strstrip (g_strdup (header_value)); transport = e_mail_session_ref_transport (session, uid); g_free (uid); return transport; }
static char * save_attachment (CamelMimePart * part, const char *uid, const char *attachment_store) { CamelDataWrapper *content; CamelStream *stream = NULL; CamelStreamFs *stream_fs; char *attach_file = NULL; char *file_url = NULL; const char *mime_filename; content = camel_medium_get_content_object (CAMEL_MEDIUM (part)); mime_filename = camel_mime_part_get_filename (part); attach_file = g_strdup_printf ("%s/%s-%s", attachment_store, uid, mime_filename); stream = camel_stream_fs_new_with_name (attach_file, O_RDWR | O_CREAT | O_TRUNC, 0600); if (stream == NULL) goto end; stream_fs = (CamelStreamFs *) stream; camel_data_wrapper_decode_to_stream (content, stream); file_url = g_strdup_printf ("file://%s", attach_file); end: g_free (attach_file); camel_object_unref (stream); return file_url; }
/** * * "util_get_msg_body" is based on mail-to-task eplugin's get_description function. * which is GPL licensed. * */ static gchar * util_get_msg_body(CamelMimeMessage *message, gchar **text) { CamelDataWrapper *content; CamelStream *mem; CamelContentType *type; CamelMimePart *mime_part = CAMEL_MIME_PART(message); GSList sl; gchar *str, *convert_str = NULL; gsize bytes_read, bytes_written; gint count = 2; content = camel_medium_get_content_object((CamelMedium *) message); if (!content) return; /* * Get non-multipart content from multipart message. */ while (CAMEL_IS_MULTIPART(content) && count > 0) { mime_part = camel_multipart_get_part(CAMEL_MULTIPART(content), 0); content = camel_medium_get_content_object(CAMEL_MEDIUM(mime_part)); count--; } if (!mime_part) return; type = camel_mime_part_get_content_type(mime_part); if (!camel_content_type_is(type, "text", "plain")) return; mem = camel_stream_mem_new(); camel_data_wrapper_decode_to_stream(content, mem); str = g_strndup((const gchar *) ((CamelStreamMem *) mem)->buffer->data, ((CamelStreamMem *) mem)->buffer->len); camel_object_unref(mem); /* convert to UTF-8 string */ if (str && content->mime_type->params && content->mime_type->params->value) { convert_str = g_convert(str, strlen(str), "UTF-8", content->mime_type->params->value, &bytes_read, &bytes_written, NULL); } if (convert_str) *text = convert_str; else *text = str; /*g_free (str); if (convert_str) g_free (convert_str); */ }
static gboolean emfe_error_format (EMailFormatterExtension *extension, EMailFormatter *formatter, EMailFormatterContext *context, EMailPart *part, GOutputStream *stream, GCancellable *cancellable) { GOutputStream *filtered_stream; CamelMimeFilter *filter; CamelMimePart *mime_part; CamelDataWrapper *dw; const gchar *string; gchar *html; mime_part = e_mail_part_ref_mime_part (part); dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part)); html = g_strdup_printf ( "<div class=\"part-container -e-mail-formatter-frame-color " "-e-mail-formatter-body-color -e-web-view-text-color\">" "<div class=\"part-container-inner-margin pre\">\n" "<table border=\"0\" cellspacing=\"10\" " "cellpadding=\"0\" width=\"100%%\">\n" "<tr valign=\"top\"><td width=50>" "<img src=\"gtk-stock://%s/?size=%d\" /></td>\n" "<td style=\"color: red;\">", "dialog-error", GTK_ICON_SIZE_DIALOG); g_output_stream_write_all ( stream, html, strlen (html), NULL, cancellable, NULL); g_free (html); filter = camel_mime_filter_tohtml_new ( CAMEL_MIME_FILTER_TOHTML_CONVERT_NL | CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0); filtered_stream = camel_filter_output_stream_new (stream, filter); g_object_unref (filter); camel_data_wrapper_decode_to_output_stream_sync ( dw, filtered_stream, cancellable, NULL); g_output_stream_flush (filtered_stream, cancellable, NULL); g_object_unref (filtered_stream); string = "</td></tr></table></div></div>"; g_output_stream_write_all ( stream, string, strlen (string), NULL, cancellable, NULL); g_object_unref (mime_part); return TRUE; }
void mail_tool_restore_xevolution_headers (CamelMimeMessage *message, struct _camel_header_raw *xev) { CamelMedium *medium; medium = CAMEL_MEDIUM (message); for (; xev; xev = xev->next) camel_medium_add_header (medium, xev->name, xev->value); }
static gboolean set_ical_from_mime_part (CamelMimePart * part, ScalixObject * object) { CamelDataWrapper *content; CamelStream *stream; GByteArray *data; icalcomponent *icomp = NULL; icalcomponent *subcomp = NULL; ScalixAppointmentPrivate *priv; priv = SCALIX_APPOINTMENT_GET_PRIVATE (SCALIX_APPOINTMENT (object)); content = camel_medium_get_content_object (CAMEL_MEDIUM (part)); data = g_byte_array_new (); stream = camel_stream_mem_new_with_byte_array (data); camel_data_wrapper_decode_to_stream (content, stream); if (data == NULL || data->data == NULL) { g_print ("Found corrupt ical data\n"); return FALSE; } icomp = icalparser_parse_string ((const char *) data->data); if (icalcomponent_isa (icomp) != ICAL_VCALENDAR_COMPONENT) { icalcomponent_free (icomp); return FALSE; } /* Grab the timezone if any */ subcomp = icalcomponent_get_first_component (icomp, ICAL_VTIMEZONE_COMPONENT); if (subcomp != NULL) { icaltimezone *zone; zone = icaltimezone_new (); icaltimezone_set_component (zone, subcomp); priv->timezone = zone; } /* Grab the main VEVENT */ subcomp = icalcomponent_get_first_component (icomp, ICAL_VEVENT_COMPONENT); e_cal_component_set_icalcomponent (E_CAL_COMPONENT (object), subcomp); return TRUE; }
gboolean e_mail_session_handle_draft_headers_sync (EMailSession *session, CamelMimeMessage *message, GCancellable *cancellable, GError **error) { CamelFolder *folder; CamelMedium *medium; const gchar *folder_uri; const gchar *message_uid; const gchar *header_name; gboolean success; g_return_val_if_fail (E_IS_MAIL_SESSION (session), FALSE); g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE); medium = CAMEL_MEDIUM (message); header_name = "X-Evolution-Draft-Folder"; folder_uri = camel_medium_get_header (medium, header_name); header_name = "X-Evolution-Draft-Message"; message_uid = camel_medium_get_header (medium, header_name); /* Don't report errors about missing X-Evolution-Draft * headers. These headers are optional, so their absence * is handled by doing nothing. */ if (folder_uri == NULL || message_uid == NULL) return TRUE; folder = e_mail_session_uri_to_folder_sync ( session, folder_uri, 0, cancellable, error); if (folder == NULL) return FALSE; camel_folder_set_message_flags ( folder, message_uid, CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_SEEN); success = camel_folder_synchronize_message_sync ( folder, message_uid, cancellable, error); g_object_unref (folder); return success; }
static void set_priority (ECalComponent *comp, CamelMimePart *part) { const gchar *prio; g_return_if_fail (comp != NULL); g_return_if_fail (part != NULL); prio = camel_medium_get_header (CAMEL_MEDIUM (part), "X-Priority"); if (prio && atoi (prio) > 0) { gint priority = 1; e_cal_component_set_priority (comp, &priority); } }
/* Helper for e_mail_session_get_fcc_for_message_sync() */ static CamelFolder * mail_session_ref_origin_folder (EMailSession *session, CamelMimeMessage *message, GCancellable *cancellable, GError **error) { CamelMedium *medium; const gchar *header_name; const gchar *header_value; medium = CAMEL_MEDIUM (message); /* Check that a "X-Evolution-Source-Flags" header is present * and its value does not contain the substring "FORWARDED". */ header_name = "X-Evolution-Source-Flags"; header_value = camel_medium_get_header (medium, header_name); if (header_value == NULL) return NULL; if (strstr (header_value, "FORWARDED") != NULL) return NULL; /* Check that a "X-Evolution-Source-Message" header is present. */ header_name = "X-Evolution-Source-Message"; header_value = camel_medium_get_header (medium, header_name); if (header_value == NULL) return NULL; /* Check that a "X-Evolution-Source-Folder" header is present. * Its value specifies the origin folder as a folder URI. */ header_name = "X-Evolution-Source-Folder"; header_value = camel_medium_get_header (medium, header_name); if (header_value == NULL) return NULL; /* This may return NULL without setting a GError. */ return mail_session_try_uri_to_folder ( session, header_value, cancellable, error); }
static void message_dump_rec (CamelMimeMessage *msg, CamelMimePart *part, gint depth) { CamelDataWrapper *containee; gint parts, i; gchar *s; gchar *mime_type; s = alloca (depth + 1); memset (s, ' ', depth); s[depth] = 0; mime_type = camel_data_wrapper_get_mime_type ((CamelDataWrapper *) part); printf ("%sPart <%s>\n", s, G_OBJECT_TYPE_NAME (part)); printf ("%sContent-Type: %s\n", s, mime_type); g_free (mime_type); printf ("%s encoding: %s\n", s, camel_transfer_encoding_to_string (((CamelDataWrapper *)part)->encoding)); printf ("%s part encoding: %s\n", s, camel_transfer_encoding_to_string (camel_mime_part_get_encoding (part))); containee = camel_medium_get_content (CAMEL_MEDIUM (part)); if (containee == NULL) return; mime_type = camel_data_wrapper_get_mime_type (containee); printf ("%sContent <%s>\n", s, G_OBJECT_TYPE_NAME (containee)); printf ("%sContent-Type: %s\n", s, mime_type); g_free (mime_type); printf ("%s encoding: %s\n", s, camel_transfer_encoding_to_string (((CamelDataWrapper *)containee)->encoding)); /* using the object types is more accurate than using the mime/types */ if (CAMEL_IS_MULTIPART (containee)) { parts = camel_multipart_get_number (CAMEL_MULTIPART (containee)); for (i = 0; i < parts; i++) { CamelMimePart *part = camel_multipart_get_part (CAMEL_MULTIPART (containee), i); message_dump_rec (msg, part, depth + 1); } } else if (CAMEL_IS_MIME_MESSAGE (containee)) { message_dump_rec (msg, (CamelMimePart *) containee, depth + 1); } }
static void mail_attachment_handler_update_actions (EAttachmentView *view, EAttachmentHandler *handler) { EAttachment *attachment; CamelMimePart *mime_part; GtkActionGroup *action_group; GList *selected; gboolean visible = FALSE; selected = e_attachment_view_get_selected_attachments (view); if (g_list_length (selected) != 1) goto exit; attachment = E_ATTACHMENT (selected->data); if (e_attachment_get_loading (attachment) || e_attachment_get_saving (attachment)) goto exit; mime_part = e_attachment_ref_mime_part (attachment); if (mime_part != NULL) { CamelMedium *medium; CamelDataWrapper *content; medium = CAMEL_MEDIUM (mime_part); content = camel_medium_get_content (medium); visible = CAMEL_IS_MIME_MESSAGE (content); g_object_unref (mime_part); } exit: action_group = e_attachment_view_get_action_group (view, "mail"); gtk_action_group_set_visible (action_group, visible); g_list_foreach (selected, (GFunc) g_object_unref, NULL); g_list_free (selected); }
/* Helper for e_mail_session_get_fcc_for_message_sync() */ static CamelFolder * mail_session_ref_fcc_from_x_fcc (EMailSession *session, CamelMimeMessage *message, GCancellable *cancellable, GError **error) { CamelMedium *medium; const gchar *header_name; const gchar *header_value; medium = CAMEL_MEDIUM (message); header_name = "X-Evolution-Fcc"; header_value = camel_medium_get_header (medium, header_name); if (header_value == NULL) return NULL; /* This may return NULL without setting a GError. */ return mail_session_try_uri_to_folder ( session, header_value, cancellable, error); }
/* there is also an identical copy of this in camel-filter-search.c */ gboolean camel_search_message_body_contains (CamelDataWrapper *object, regex_t *pattern) { CamelDataWrapper *containee; gint truth = FALSE; gint parts, i; containee = camel_medium_get_content (CAMEL_MEDIUM (object)); if (containee == NULL) return FALSE; /* using the object types is more accurate than using the mime/types */ if (CAMEL_IS_MULTIPART (containee)) { parts = camel_multipart_get_number (CAMEL_MULTIPART (containee)); for (i = 0; i < parts && truth == FALSE; i++) { CamelDataWrapper *part = (CamelDataWrapper *)camel_multipart_get_part (CAMEL_MULTIPART (containee), i); if (part) truth = camel_search_message_body_contains (part, pattern); } } else if (CAMEL_IS_MIME_MESSAGE (containee)) { /* for messages we only look at its contents */ truth = camel_search_message_body_contains ((CamelDataWrapper *)containee, pattern); } else if (camel_content_type_is(CAMEL_DATA_WRAPPER (containee)->mime_type, "text", "*") || camel_content_type_is(CAMEL_DATA_WRAPPER (containee)->mime_type, "x-evolution", "evolution-rss-feed")) { /* for all other text parts, we look inside, otherwise we dont care */ CamelStream *stream; GByteArray *byte_array; byte_array = g_byte_array_new (); stream = camel_stream_mem_new_with_byte_array (byte_array); camel_data_wrapper_write_to_stream_sync ( containee, stream, NULL, NULL); camel_stream_write (stream, "", 1, NULL, NULL); truth = regexec (pattern, (gchar *) byte_array->data, 0, NULL, 0) == 0; g_object_unref (stream); } return truth; }
static void mime_message_ensure_required_headers (CamelMimeMessage *message) { CamelMedium *medium = CAMEL_MEDIUM (message); if (message->from == NULL) { camel_medium_set_header (medium, "From", ""); } if (!camel_medium_get_header (medium, "Date")) camel_mime_message_set_date ( message, CAMEL_MESSAGE_DATE_CURRENT, 0); if (message->subject == NULL) camel_mime_message_set_subject (message, "No Subject"); if (message->message_id == NULL) camel_mime_message_set_message_id (message, NULL); /* FIXME: "To" header needs to be set explicitly as well ... */ if (!camel_medium_get_header (medium, "Mime-Version")) camel_medium_set_header (medium, "Mime-Version", "1.0"); }
static CamelSExpResult * header_exists (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms) { CamelMimeMessage *message; gboolean matched = FALSE; CamelSExpResult *r; gint i; message = camel_filter_search_get_message (fms, f); for (i = 0; i < argc && !matched; i++) { if (argv[i]->type == CAMEL_SEXP_RES_STRING) matched = camel_medium_get_header (CAMEL_MEDIUM (message), argv[i]->value.string) != NULL; } r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL); r->value.boolean = matched; return r; }
/* Helper for e_mail_session_get_fcc_for_message_sync() */ static CamelFolder * mail_session_ref_fcc_from_x_identity (EMailSession *session, CamelMimeMessage *message, GCancellable *cancellable, GError **error) { ESource *source; ESourceRegistry *registry; CamelFolder *folder; CamelMedium *medium; const gchar *header_name; const gchar *header_value; gchar *uid; medium = CAMEL_MEDIUM (message); header_name = "X-Evolution-Identity"; header_value = camel_medium_get_header (medium, header_name); if (header_value == NULL) return NULL; uid = g_strstrip (g_strdup (header_value)); registry = e_mail_session_get_registry (session); source = e_source_registry_ref_source (registry, uid); /* This may return NULL without setting a GError. */ folder = mail_session_ref_fcc_from_identity ( session, source, message, cancellable, error); g_clear_object (&source); g_free (uid); return folder; }
CamelMimeMessage * scalix_appointment_to_mime_message (ScalixObject * object) { CamelMimeMessage *message; CamelMultipart *multipart; CamelMimePart *part; CamelMedium *medium; CamelStream *stream; CamelDataWrapper *wrapper; ECalComponentDateTime dtstart, dtend; ECalComponent *comp; ECalComponentText text; icalcomponent_kind kind; icalcomponent *icalcomp, *toplevel_comp; icaltimezone *zone = NULL; GSList *attachment_list = NULL; GSList *attachment_list_new = NULL; GSList *siter = NULL; GList *part_list = NULL; GList *iter = NULL; char *msgid; char *str, *meeting_status; const char *ouid = NULL; char *file_contents = NULL; char *full_path, *filename, *mime_filename; char *cid; int size; g_object_get (SCALIX_APPOINTMENT (object), "timezone", &zone, NULL); comp = E_CAL_COMPONENT (scalix_object_clone (object)); message = camel_mime_message_new (); medium = CAMEL_MEDIUM (message); camel_medium_add_header (medium, "X-Scalix-Class", "IPM.Appointment"); /* Preserve msg id if there is already one */ if (scalix_appointment_get (SCALIX_APPOINTMENT (comp), X_SCALIX_MSG_ID, &msgid)) { scalix_appointment_unset (SCALIX_APPOINTMENT (comp), X_SCALIX_MSG_ID); } else { msgid = camel_header_msgid_generate (); } camel_mime_message_set_message_id (message, msgid); /* subject */ e_cal_component_get_summary (comp, &text); if (text.value != NULL) { camel_mime_message_set_subject (message, text.value); } /* start day */ e_cal_component_get_dtstart (comp, &dtstart); if (!icaltime_get_timezone (*dtstart.value)) icaltime_set_timezone (dtstart.value, icaltimezone_get_builtin_timezone_from_tzid (dtstart.tzid)); /* end day */ e_cal_component_get_dtend (comp, &dtend); if (!icaltime_get_timezone (*dtend.value)) icaltime_set_timezone (dtend.value, icaltimezone_get_builtin_timezone_from_tzid (dtend.tzid)); /* set From: and Sender: */ if (e_cal_component_has_organizer (comp)) { ECalComponentOrganizer organizer; e_cal_component_get_organizer (comp, &organizer); if (!strncasecmp (organizer.value, "MAILTO:", 7)) { camel_medium_add_header (medium, "Sender", organizer.value + 7); camel_medium_add_header (medium, "From", organizer.value + 7); } } /* set the appropriate recipient headers from the recipient table */ if (e_cal_component_has_attendees (comp) && e_cal_component_has_organizer (comp)) { GSList *iter, *attendees = NULL; CamelInternetAddress *recipients_to = NULL; CamelInternetAddress *recipients_cc = NULL; meeting_status = "1"; e_cal_component_get_attendee_list (comp, &attendees); for (iter = attendees; iter; iter = iter->next) { ECalComponentAttendee *attendee = iter->data; const char *mail = NULL; /* attendee entries must start with MAILTO: */ if (strncasecmp (attendee->value, "MAILTO:", 7)) { continue; } mail = attendee->value + 7; if (attendee->role == ICAL_ROLE_REQPARTICIPANT) { if (recipients_to == NULL) { recipients_to = camel_internet_address_new (); } camel_internet_address_add (recipients_to, attendee->cn, mail); } else if (attendee->role == ICAL_ROLE_OPTPARTICIPANT) { if (recipients_cc == NULL) { recipients_cc = camel_internet_address_new (); } camel_internet_address_add (recipients_cc, attendee->cn, mail); } else { continue; } } if (recipients_to != NULL) { camel_mime_message_set_recipients (message, "To", recipients_to); camel_object_unref (recipients_to); } if (recipients_cc != NULL) { camel_mime_message_set_recipients (message, "Cc", recipients_cc); camel_object_unref (recipients_cc); } } else { meeting_status = "0"; } /* Clear properties */ scalix_appointment_unset (SCALIX_APPOINTMENT (comp), X_SCALIX_IMAP_UID); /* Render the text/calendar */ e_cal_component_commit_sequence (comp); icalcomp = e_cal_component_get_icalcomponent (comp); kind = icalcomponent_isa (icalcomp); if (kind != ICAL_VCALENDAR_COMPONENT) { /* If its not a VCALENDAR, make it one to simplify below */ toplevel_comp = e_cal_util_new_top_level (); icalcomponent_add_component (toplevel_comp, icalcomp); icalcomp = toplevel_comp; } /* set METHOD to PUSBLISH */ icalcomponent_set_method (icalcomp, ICAL_METHOD_PUBLISH); /* Add the VTIMEZONE components for start- and/or end-times */ if (zone) { icalcomponent_add_component (icalcomp, icaltimezone_get_component (zone)); } else if (dtstart.tzid) { icalcomponent_add_component (icalcomp, icaltimezone_get_component (icaltimezone_get_builtin_timezone_from_tzid (dtstart.tzid))); } if (dtstart.tzid && dtend.tzid && strcmp (dtstart.tzid, dtend.tzid) != 0) { icalcomponent_add_component (icalcomp, icaltimezone_get_component (icaltimezone_get_builtin_timezone_from_tzid (dtend.tzid))); } /* FIXME: do we leek icalcomponents here? */ if (e_cal_component_has_attachments (comp)) { multipart = camel_multipart_new (); camel_multipart_set_boundary (multipart, NULL); e_cal_component_get_uid (comp, &ouid); e_cal_component_get_attachment_list (comp, &attachment_list); for (siter = attachment_list; siter; siter = siter->next) { if (siter->data == NULL) continue; if (strstr (siter->data, "file://") != siter->data) continue; full_path = ((char *) siter->data) + strlen ("file://"); filename = g_strrstr (full_path, "/") + 1; mime_filename = filename + strlen (ouid) + 1; size = 0; file_contents = get_file_contents (full_path, &size); if (file_contents == NULL) continue; stream = camel_stream_mem_new_with_buffer (file_contents, size); wrapper = camel_data_wrapper_new (); camel_data_wrapper_construct_from_stream (wrapper, stream); camel_object_unref (stream); part = camel_mime_part_new (); camel_medium_set_content_object (CAMEL_MEDIUM (part), wrapper); camel_mime_part_set_filename (part, mime_filename); camel_mime_part_set_encoding (part, CAMEL_TRANSFER_ENCODING_BASE64); cid = camel_header_msgid_generate (); camel_mime_part_set_content_id (part, cid); camel_mime_part_set_description (part, mime_filename); camel_mime_part_set_disposition (part, "attachment"); part_list = g_list_append (part_list, part); attachment_list_new = g_slist_append (attachment_list_new, g_strdup_printf ("CID:%s", cid)); g_free (cid); } e_cal_component_set_attachment_list (comp, attachment_list_new); str = icalcomponent_as_ical_string (icalcomp); part = camel_mime_part_new (); camel_mime_part_set_content (part, str, strlen (str), "text/calendar; method=PUBLISH; charset=UTF-8"); part_list = g_list_prepend (part_list, part); for (iter = part_list; iter; iter = iter->next) { part = (CamelMimePart *) iter->data; camel_multipart_add_part (multipart, part); camel_object_unref (part); } camel_medium_set_content_object (CAMEL_MEDIUM (message), CAMEL_DATA_WRAPPER (multipart)); camel_object_unref (multipart); g_slist_free (attachment_list); g_slist_free (attachment_list_new); g_list_free (part_list); } else { str = icalcomponent_as_ical_string (icalcomp); camel_mime_part_set_content (CAMEL_MIME_PART (message), str, strlen (str), "text/calendar; method=PUBLISH; charset=UTF-8"); } scalix_appointment_set (SCALIX_APPOINTMENT (object), X_SCALIX_MSG_ID, msgid); return message; }
static gboolean empe_mp_alternative_parse (EMailParserExtension *extension, EMailParser *parser, CamelMimePart *part, GString *part_id, GCancellable *cancellable, GQueue *out_mail_parts) { CamelMultipart *mp; gint i, nparts, bestid = 0; CamelMimePart *best = NULL; EMailExtensionRegistry *reg; reg = e_mail_parser_get_extension_registry (parser); mp = (CamelMultipart *) camel_medium_get_content ((CamelMedium *) part); if (!CAMEL_IS_MULTIPART (mp)) return e_mail_parser_parse_part_as ( parser, part, part_id, "application/vnd.evolution.source", cancellable, out_mail_parts); /* as per rfc, find the last part we know how to display */ nparts = camel_multipart_get_number (mp); for (i = 0; i < nparts; i++) { CamelMimePart *mpart; CamelDataWrapper *data_wrapper; CamelContentType *type; gchar *mime_type; gsize content_size; if (g_cancellable_is_cancelled (cancellable)) return TRUE; /* is it correct to use the passed in *part here? */ mpart = camel_multipart_get_part (mp, i); if (mpart == NULL) continue; /* This may block even though the stream does not. * XXX Pretty inefficient way to test if the MIME part * is empty. Surely there's a quicker way? */ data_wrapper = camel_medium_get_content (CAMEL_MEDIUM (mpart)); content_size = camel_data_wrapper_calculate_decoded_size_sync (data_wrapper, cancellable, NULL); if (content_size == 0) continue; type = camel_mime_part_get_content_type (mpart); mime_type = camel_content_type_simple (type); camel_strdown (mime_type); if (!e_mail_part_is_attachment (mpart) && ((camel_content_type_is (type, "multipart", "related") == 0) || !related_display_part_is_attachment (mpart)) && (e_mail_extension_registry_get_for_mime_type (reg, mime_type) || ((best == NULL) && (e_mail_extension_registry_get_fallback (reg, mime_type))))) { best = mpart; bestid = i; } g_free (mime_type); } if (best) { gint len = part_id->len; g_string_append_printf (part_id, ".alternative.%d", bestid); e_mail_parser_parse_part ( parser, best, part_id, cancellable, out_mail_parts); g_string_truncate (part_id, len); } else { e_mail_parser_parse_part_as ( parser, part, part_id, "multipart/mixed", cancellable, out_mail_parts); } return TRUE; }
gboolean scalix_appointment_init_from_mime_message (ScalixObject * object, CamelMimeMessage * msg) { const char *msgid; const char *attachment_store; const char *mime_type, *alternative_mime_type; const char *content_disposition; const char *mime_filename; const char *cid; const char *cuid; const char *attachment_file_url; GSList *attachments = NULL; GSList *attachments_new = NULL; GSList *siter = NULL; CamelMimePart *part, *alternative; CamelMultipart *multipart, *nested_multipart; CamelDataWrapper *content, *alternative_content; int i, j, num_parts, num_alternatives; gboolean found_ical = FALSE; attachment_store = g_object_get_data (G_OBJECT (object), "attachment-store"); part = CAMEL_MIME_PART (msg); content = camel_medium_get_content_object (CAMEL_MEDIUM (part)); if (content == NULL) { return FALSE; } mime_type = camel_content_type_simple (content->mime_type); if (CAMEL_IS_MULTIPART (content)) { multipart = (CamelMultipart *) content; num_parts = (int) camel_multipart_get_number (multipart); for (i = 0; i < num_parts; i++) { part = camel_multipart_get_part (multipart, i); content = camel_medium_get_content_object (CAMEL_MEDIUM (part)); mime_type = camel_content_type_simple (content->mime_type); mime_filename = camel_mime_part_get_filename (part); content_disposition = camel_mime_part_get_disposition (part); if (CAMEL_IS_MULTIPART (content)) { nested_multipart = (CamelMultipart *) content; num_alternatives = (int) camel_multipart_get_number (nested_multipart); for (j = 0; j < num_alternatives; j++) { alternative = camel_multipart_get_part (nested_multipart, j); alternative_content = camel_medium_get_content_object (CAMEL_MEDIUM (alternative)); alternative_mime_type = camel_content_type_simple (alternative_content-> mime_type); if (g_str_equal (alternative_mime_type, "text/calendar") && found_ical == FALSE) { if (set_ical_from_mime_part (alternative, object) == TRUE) { e_cal_component_get_uid (E_CAL_COMPONENT (object), &cuid); e_cal_component_get_attachment_list (E_CAL_COMPONENT (object), &attachments); /* we are only interested in the first ical body part */ found_ical = TRUE; } } } } else if (g_str_equal (mime_type, "text/calendar") && found_ical == FALSE) { if (set_ical_from_mime_part (part, object) == TRUE) { e_cal_component_get_uid (E_CAL_COMPONENT (object), &cuid); e_cal_component_get_attachment_list (E_CAL_COMPONENT (object), &attachments); /* we are only interested in the first ical body part */ found_ical = TRUE; } } else if (content_disposition && strcmp (content_disposition, "attachment") == 0) { cid = camel_mime_part_get_content_id (part); if (cid != NULL) { for (siter = attachments; siter; siter = siter->next) { if (strstr (siter->data, cid) == (char *) (siter->data) + 4) { attachment_file_url = save_attachment (part, cuid, attachment_store); if (attachment_file_url != NULL) { attachments_new = g_slist_append (attachments_new, g_strdup (attachment_file_url)); } } } } } else { g_print ("XXXXX Unhandled mime part: %s\n", mime_type); } } } else { /* just a simple ical message */ if (g_str_equal (mime_type, "text/calendar")) { set_ical_from_mime_part (part, object); } } if (attachments_new != NULL) { e_cal_component_set_attachment_list (E_CAL_COMPONENT (object), attachments_new); } msgid = camel_mime_message_get_message_id (msg); scalix_appointment_unset (SCALIX_APPOINTMENT (object), X_SCALIX_MSG_ID); scalix_appointment_set (SCALIX_APPOINTMENT (object), X_SCALIX_MSG_ID, msgid); return TRUE; }
static void set_description (ECalComponent *comp, CamelMimeMessage *message) { CamelDataWrapper *content; CamelStream *stream; CamelContentType *type; CamelMimePart *mime_part = CAMEL_MIME_PART (message); ECalComponentText *text = NULL; GByteArray *byte_array; GSList *sl = NULL; gchar *str, *convert_str = NULL; gsize bytes_read, bytes_written; gint count = 2; content = camel_medium_get_content ((CamelMedium *) message); if (!content) return; /* * Get non-multipart content from multipart message. */ while (CAMEL_IS_MULTIPART (content) && count > 0) { mime_part = camel_multipart_get_part (CAMEL_MULTIPART (content), 0); content = camel_medium_get_content (CAMEL_MEDIUM (mime_part)); count--; } if (!mime_part) return; type = camel_mime_part_get_content_type (mime_part); if (!camel_content_type_is (type, "text", "plain")) return; byte_array = g_byte_array_new (); stream = camel_stream_mem_new_with_byte_array (byte_array); camel_data_wrapper_decode_to_stream_sync (content, stream, NULL, NULL); str = g_strndup ((gchar *) byte_array->data, byte_array->len); g_object_unref (stream); /* convert to UTF-8 string */ if (str && content->mime_type->params && content->mime_type->params->value) { convert_str = g_convert ( str, strlen (str), "UTF-8", content->mime_type->params->value, &bytes_read, &bytes_written, NULL); } text = g_new0 (ECalComponentText, 1); if (convert_str) text->value = prepend_from (message, &convert_str); else text->value = prepend_from (message, &str); text->altrep = NULL; sl = g_slist_append (sl, text); e_cal_component_set_description_list (comp, sl); g_free (str); if (convert_str) g_free (convert_str); e_cal_component_free_text_list (sl); }
void e_mail_session_send_to (EMailSession *session, CamelMimeMessage *message, gint io_priority, GCancellable *cancellable, CamelFilterGetFolderFunc get_folder_func, gpointer get_folder_data, GAsyncReadyCallback callback, gpointer user_data) { GSimpleAsyncResult *simple; AsyncContext *context; CamelAddress *from; CamelAddress *recipients; CamelMedium *medium; CamelMessageInfo *info; EAccount *account = NULL; GPtrArray *post_to_uris; struct _camel_header_raw *xev; struct _camel_header_raw *header; const gchar *string; const gchar *resent_from; gchar *transport_uid = NULL; gchar *sent_folder_uri = NULL; GError *error = NULL; g_return_if_fail (E_IS_MAIL_SESSION (session)); g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message)); medium = CAMEL_MEDIUM (message); camel_medium_set_header (medium, "X-Mailer", X_MAILER); xev = mail_tool_remove_xevolution_headers (message); /* Extract directives from X-Evolution headers. */ string = camel_header_raw_find (&xev, "X-Evolution-Account", NULL); if (string != NULL) { gchar *account_uid; account_uid = g_strstrip (g_strdup (string)); account = e_get_account_by_uid (account_uid); g_free (account_uid); } if (account != NULL) { if (account->transport != NULL) { /* XXX Transport UIDs are kludgy right now. We * use the EAccount's regular UID and tack on * "-transport". Will be better soon. */ transport_uid = g_strconcat ( account->uid, "-transport", NULL); /* to reprompt password on sending if needed */ account->transport->get_password_canceled = FALSE; } sent_folder_uri = g_strdup (account->sent_folder_uri); } string = camel_header_raw_find (&xev, "X-Evolution-Fcc", NULL); if (sent_folder_uri == NULL && string != NULL) sent_folder_uri = g_strstrip (g_strdup (string)); string = camel_header_raw_find (&xev, "X-Evolution-Transport", NULL); if (transport_uid == NULL && string != NULL) transport_uid = g_strstrip (g_strdup (string)); post_to_uris = g_ptr_array_new (); for (header = xev; header != NULL; header = header->next) { gchar *folder_uri; if (g_strcmp0 (header->name, "X-Evolution-PostTo") != 0) continue; folder_uri = g_strstrip (g_strdup (header->value)); g_ptr_array_add (post_to_uris, folder_uri); } /* Collect sender and recipients from headers. */ from = (CamelAddress *) camel_internet_address_new (); recipients = (CamelAddress *) camel_internet_address_new (); resent_from = camel_medium_get_header (medium, "Resent-From"); if (resent_from != NULL) { const CamelInternetAddress *addr; const gchar *type; camel_address_decode (from, resent_from); type = CAMEL_RECIPIENT_TYPE_RESENT_TO; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); type = CAMEL_RECIPIENT_TYPE_RESENT_CC; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); type = CAMEL_RECIPIENT_TYPE_RESENT_BCC; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); } else { const CamelInternetAddress *addr; const gchar *type; addr = camel_mime_message_get_from (message); camel_address_copy (from, CAMEL_ADDRESS (addr)); type = CAMEL_RECIPIENT_TYPE_TO; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); type = CAMEL_RECIPIENT_TYPE_CC; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); type = CAMEL_RECIPIENT_TYPE_BCC; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); } /* Miscellaneous preparations. */ info = camel_message_info_new (NULL); camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN, ~0); /* The rest of the processing happens in a thread. */ context = g_slice_new0 (AsyncContext); context->message = g_object_ref (message); context->io_priority = io_priority; context->from = from; context->recipients = recipients; context->message = g_object_ref (message); context->info = info; context->xev = xev; context->post_to_uris = post_to_uris; context->transport_uid = transport_uid; context->sent_folder_uri = sent_folder_uri; if (G_IS_CANCELLABLE (cancellable)) context->cancellable = g_object_ref (cancellable); /* Failure here emits a runtime warning but is non-fatal. */ context->driver = camel_session_get_filter_driver ( CAMEL_SESSION (session), E_FILTER_SOURCE_OUTGOING, &error); if (context->driver != NULL && get_folder_func) camel_filter_driver_set_folder_func ( context->driver, get_folder_func, get_folder_data); if (error != NULL) { g_warn_if_fail (context->driver == NULL); g_warning ("%s", error->message); g_error_free (error); } /* This gets popped in async_context_free(). */ camel_operation_push_message ( context->cancellable, _("Sending message")); simple = g_simple_async_result_new ( G_OBJECT (session), callback, user_data, e_mail_session_send_to); g_simple_async_result_set_op_res_gpointer ( simple, context, (GDestroyNotify) async_context_free); g_simple_async_result_run_in_thread ( simple, (GSimpleAsyncThreadFunc) mail_session_send_to_thread, context->io_priority, context->cancellable); g_object_unref (simple); }
static void emfqe_format_header (EMailFormatter *formatter, EMailFormatterContext *context, GString *buffer, EMailPart *part, const gchar *header_name, const gchar *charset) { CamelMimePart *mime_part; EMailFormatterHeaderFlags flags; gchar *canon_name, *buf, *value = NULL; const gchar *txt, *label; gboolean addrspec = FALSE; gint is_html = FALSE; gint i; /* Skip Face header in prints, which includes also message forward */ if (context->mode == E_MAIL_FORMATTER_MODE_PRINTING && g_ascii_strcasecmp (header_name, "Face") == 0) return; flags = E_MAIL_FORMATTER_HEADER_FLAG_NOELIPSIZE; canon_name = g_alloca (strlen (header_name) + 1); strcpy (canon_name, header_name); e_mail_formatter_canon_header_name (canon_name); /* Never quote Bcc/Resent-Bcc headers. */ if (g_str_equal (canon_name, "Bcc")) return; if (g_str_equal (canon_name, "Resent-Bcc")) return; mime_part = e_mail_part_ref_mime_part (part); for (i = 0; addrspec_hdrs[i]; i++) { if (g_str_equal (canon_name, addrspec_hdrs[i])) { addrspec = TRUE; break; } } label = _(canon_name); if (addrspec) { CamelMedium *medium; struct _camel_header_address *addrs; GString *html; gchar *charset; medium = CAMEL_MEDIUM (mime_part); txt = camel_medium_get_header (medium, canon_name); if (txt == NULL) return; charset = e_mail_formatter_dup_charset (formatter); if (!charset) charset = e_mail_formatter_dup_default_charset (formatter); buf = camel_header_unfold (txt); addrs = camel_header_address_decode (txt, charset); g_free (charset); if (addrs == NULL) { g_free (buf); return; } g_free (buf); html = g_string_new (""); e_mail_formatter_format_address (formatter, html, addrs, canon_name, FALSE, FALSE); camel_header_address_unref (addrs); txt = value = html->str; g_string_free (html, FALSE); flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; is_html = TRUE; } else if (g_str_equal (canon_name, "Subject")) { CamelMimeMessage *message; message = CAMEL_MIME_MESSAGE (mime_part); txt = camel_mime_message_get_subject (message); label = _("Subject"); flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "X-Evolution-Mailer")) { CamelMedium *medium; medium = CAMEL_MEDIUM (mime_part); txt = camel_medium_get_header (medium, "x-mailer"); if (txt == NULL) txt = camel_medium_get_header (medium, "user-agent"); if (txt == NULL) txt = camel_medium_get_header (medium, "x-newsreader"); if (txt == NULL) txt = camel_medium_get_header (medium, "x-mimeole"); if (txt == NULL) return; txt = value = camel_header_format_ctext (txt, charset); label = _("Mailer"); flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "Date") || g_str_equal (canon_name, "Resent-Date")) { CamelMedium *medium; medium = CAMEL_MEDIUM (mime_part); txt = camel_medium_get_header (medium, canon_name); if (txt == NULL) return; flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else { CamelMedium *medium; medium = CAMEL_MEDIUM (mime_part); txt = camel_medium_get_header (medium, canon_name); buf = camel_header_unfold (txt); txt = value = camel_header_decode_string (txt, charset); g_free (buf); } emfqe_format_text_header (formatter, buffer, label, txt, flags, is_html); g_free (value); g_object_unref (mime_part); }
gboolean e_mail_session_handle_source_headers_sync (EMailSession *session, CamelMimeMessage *message, GCancellable *cancellable, GError **error) { CamelFolder *folder; CamelMedium *medium; CamelMessageFlags flags = 0; const gchar *folder_uri; const gchar *message_uid; const gchar *flag_string; const gchar *header_name; gboolean success; guint length, ii; gchar **tokens; gchar *string; g_return_val_if_fail (E_IS_MAIL_SESSION (session), FALSE); g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE); medium = CAMEL_MEDIUM (message); header_name = "X-Evolution-Source-Folder"; folder_uri = camel_medium_get_header (medium, header_name); header_name = "X-Evolution-Source-Message"; message_uid = camel_medium_get_header (medium, header_name); header_name = "X-Evolution-Source-Flags"; flag_string = camel_medium_get_header (medium, header_name); /* Don't report errors about missing X-Evolution-Source * headers. These headers are optional, so their absence * is handled by doing nothing. */ if (folder_uri == NULL || message_uid == NULL || flag_string == NULL) return TRUE; /* Convert the flag string to CamelMessageFlags. */ string = g_strstrip (g_strdup (flag_string)); tokens = g_strsplit (string, " ", 0); g_free (string); /* If tokens is NULL, a length of 0 will skip the loop. */ length = (tokens != NULL) ? g_strv_length (tokens) : 0; for (ii = 0; ii < length; ii++) { /* Note: We're only checking for flags known to * be used in X-Evolution-Source-Flags headers. * Add more as needed. */ if (g_strcmp0 (tokens[ii], "ANSWERED") == 0) flags |= CAMEL_MESSAGE_ANSWERED; else if (g_strcmp0 (tokens[ii], "ANSWERED_ALL") == 0) flags |= CAMEL_MESSAGE_ANSWERED_ALL; else if (g_strcmp0 (tokens[ii], "FORWARDED") == 0) flags |= CAMEL_MESSAGE_FORWARDED; else if (g_strcmp0 (tokens[ii], "SEEN") == 0) flags |= CAMEL_MESSAGE_SEEN; else g_warning ( "Unknown flag '%s' in %s", tokens[ii], header_name); } g_strfreev (tokens); folder = e_mail_session_uri_to_folder_sync ( session, folder_uri, 0, cancellable, error); if (folder == NULL) return FALSE; camel_folder_set_message_flags ( folder, message_uid, flags, flags); success = camel_folder_synchronize_message_sync ( folder, message_uid, cancellable, error); g_object_unref (folder); return success; }
void e_mail_session_send_to (EMailSession *session, CamelMimeMessage *message, gint io_priority, GCancellable *cancellable, CamelFilterGetFolderFunc get_folder_func, gpointer get_folder_data, GAsyncReadyCallback callback, gpointer user_data) { GSimpleAsyncResult *simple; AsyncContext *context; CamelAddress *from; CamelAddress *recipients; CamelMedium *medium; CamelMessageInfo *info; CamelService *transport; GPtrArray *post_to_uris; struct _camel_header_raw *xev; struct _camel_header_raw *header; const gchar *resent_from; GError *error = NULL; g_return_if_fail (E_IS_MAIL_SESSION (session)); g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message)); medium = CAMEL_MEDIUM (message); camel_medium_set_header (medium, "X-Mailer", X_MAILER); /* Do this before removing "X-Evolution" headers. */ transport = e_mail_session_ref_transport_for_message ( session, message); xev = mail_tool_remove_xevolution_headers (message); /* Extract directives from X-Evolution headers. */ post_to_uris = g_ptr_array_new (); for (header = xev; header != NULL; header = header->next) { gchar *folder_uri; if (g_strcmp0 (header->name, "X-Evolution-PostTo") != 0) continue; folder_uri = g_strstrip (g_strdup (header->value)); g_ptr_array_add (post_to_uris, folder_uri); } /* Collect sender and recipients from headers. */ from = (CamelAddress *) camel_internet_address_new (); recipients = (CamelAddress *) camel_internet_address_new (); resent_from = camel_medium_get_header (medium, "Resent-From"); if (resent_from != NULL) { const CamelInternetAddress *addr; const gchar *type; camel_address_decode (from, resent_from); type = CAMEL_RECIPIENT_TYPE_RESENT_TO; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); type = CAMEL_RECIPIENT_TYPE_RESENT_CC; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); type = CAMEL_RECIPIENT_TYPE_RESENT_BCC; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); } else { const CamelInternetAddress *addr; const gchar *type; addr = camel_mime_message_get_from (message); camel_address_copy (from, CAMEL_ADDRESS (addr)); type = CAMEL_RECIPIENT_TYPE_TO; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); type = CAMEL_RECIPIENT_TYPE_CC; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); type = CAMEL_RECIPIENT_TYPE_BCC; addr = camel_mime_message_get_recipients (message, type); camel_address_cat (recipients, CAMEL_ADDRESS (addr)); } /* Miscellaneous preparations. */ info = camel_message_info_new_from_header ( NULL, CAMEL_MIME_PART (message)->headers); ((CamelMessageInfoBase *) info)->size = get_message_size (message, cancellable); camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN, ~0); /* expand, or remove empty, group addresses */ em_utils_expand_groups (CAMEL_INTERNET_ADDRESS (recipients)); /* The rest of the processing happens in a thread. */ context = g_slice_new0 (AsyncContext); context->message = g_object_ref (message); context->io_priority = io_priority; context->from = from; context->recipients = recipients; context->info = info; context->xev = xev; context->post_to_uris = post_to_uris; context->transport = transport; if (G_IS_CANCELLABLE (cancellable)) context->cancellable = g_object_ref (cancellable); /* Failure here emits a runtime warning but is non-fatal. */ context->driver = camel_session_get_filter_driver ( CAMEL_SESSION (session), E_FILTER_SOURCE_OUTGOING, &error); if (context->driver != NULL && get_folder_func) camel_filter_driver_set_folder_func ( context->driver, get_folder_func, get_folder_data); if (error != NULL) { g_warn_if_fail (context->driver == NULL); g_warning ("%s", error->message); g_error_free (error); } /* This gets popped in async_context_free(). */ camel_operation_push_message ( context->cancellable, _("Sending message")); simple = g_simple_async_result_new ( G_OBJECT (session), callback, user_data, e_mail_session_send_to); g_simple_async_result_set_check_cancellable (simple, cancellable); g_simple_async_result_set_op_res_gpointer ( simple, context, (GDestroyNotify) async_context_free); g_simple_async_result_run_in_thread ( simple, (GSimpleAsyncThreadFunc) mail_session_send_to_thread, context->io_priority, context->cancellable); g_object_unref (simple); }