diff options
Diffstat (limited to 'em-format')
-rw-r--r-- | em-format/Makefile.am | 4 | ||||
-rw-r--r-- | em-format/e-mail-formatter-audio.c | 155 | ||||
-rw-r--r-- | em-format/e-mail-formatter.c | 2 | ||||
-rw-r--r-- | em-format/e-mail-parser-audio.c | 111 | ||||
-rw-r--r-- | em-format/e-mail-parser.c | 2 | ||||
-rw-r--r-- | em-format/e-mail-part-audio.c | 85 | ||||
-rw-r--r-- | em-format/e-mail-part-audio.h | 65 |
7 files changed, 424 insertions, 0 deletions
diff --git a/em-format/Makefile.am b/em-format/Makefile.am index 2983eb0ecf..69da12db0c 100644 --- a/em-format/Makefile.am +++ b/em-format/Makefile.am @@ -35,6 +35,7 @@ evolution_mail_formatter_include_HEADERS = \ e-mail-part.h \ e-mail-part-attachment.h \ e-mail-part-attachment-bar.h \ + e-mail-part-audio.h \ e-mail-part-headers.h \ e-mail-part-image.h \ e-mail-part-list.h \ @@ -68,6 +69,7 @@ libevolution_mail_formatter_la_SOURCES = \ e-mail-formatter-utils.c \ e-mail-formatter-attachment.c \ e-mail-formatter-attachment-bar.c \ + e-mail-formatter-audio.c \ e-mail-formatter-enumtypes.c \ e-mail-formatter-error.c \ e-mail-formatter-extension.c \ @@ -90,6 +92,7 @@ libevolution_mail_formatter_la_SOURCES = \ e-mail-parser.c \ e-mail-parser-application-mbox.c \ e-mail-parser-attachment-bar.c \ + e-mail-parser-audio.c \ e-mail-parser-headers.c \ e-mail-parser-image.c \ e-mail-parser-inlinepgp-encrypted.c \ @@ -113,6 +116,7 @@ libevolution_mail_formatter_la_SOURCES = \ e-mail-part.c \ e-mail-part-attachment.c \ e-mail-part-attachment-bar.c \ + e-mail-part-audio.c \ e-mail-part-headers.c \ e-mail-part-image.c \ e-mail-part-list.c \ diff --git a/em-format/e-mail-formatter-audio.c b/em-format/e-mail-formatter-audio.c new file mode 100644 index 0000000000..e36cc06ff1 --- /dev/null +++ b/em-format/e-mail-formatter-audio.c @@ -0,0 +1,155 @@ +/* + * e-mail-formatter-audio.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <glib/gi18n-lib.h> + +#include <camel/camel.h> + +#include "e-mail-formatter-extension.h" +#include "e-mail-formatter.h" +#include "e-mail-part-audio.h" + +#define d(x) + +typedef EMailFormatterExtension EMailFormatterAudio; +typedef EMailFormatterExtensionClass EMailFormatterAudioClass; + +GType e_mail_formatter_audio_get_type (void); + +G_DEFINE_TYPE ( + EMailFormatterAudio, + e_mail_formatter_audio, + E_TYPE_MAIL_FORMATTER_EXTENSION) + +static const gchar *formatter_mime_types[] = { + "application/vnd.evolution.widget.audio", + "audio/ac3", + "audio/x-ac3", + "audio/basic", + "audio/mpeg", + "audio/x-mpeg", + "audio/mpeg3", + "audio/x-mpeg3", + "audio/mp3", + "audio/x-mp3", + "audio/mp4", + "audio/flac", + "audio/x-flac", + "audio/mod", + "audio/x-mod", + "audio/x-wav", + "audio/microsoft-wav", + "audio/x-wma", + "audio/x-ms-wma", + "audio/ogg", + "audio/x-vorbis+ogg", + "application/ogg", + "application/x-ogg", + NULL +}; + +static gboolean +mail_formatter_audio_format (EMailFormatterExtension *extension, + EMailFormatter *formatter, + EMailFormatterContext *context, + EMailPart *part, + CamelStream *stream, + GCancellable *cancellable) +{ + CamelMimePart *mime_part; + CamelDataWrapper *content; + CamelTransferEncoding encoding; + CamelStream *mem_stream; + GByteArray *byte_array; + const gchar *mime_type; + gchar *html; + GError *local_error = NULL; + + mime_part = e_mail_part_ref_mime_part (part); + encoding = camel_mime_part_get_encoding (mime_part); + content = camel_medium_get_content (CAMEL_MEDIUM (mime_part)); + + mime_type = e_mail_part_get_mime_type (part); + if (mime_type == NULL) + mime_type = "audio/*"; + + mem_stream = camel_stream_mem_new (); + byte_array = camel_stream_mem_get_byte_array ( + CAMEL_STREAM_MEM (mem_stream)); + + if (encoding == CAMEL_TRANSFER_ENCODING_BASE64) { + camel_data_wrapper_write_to_stream_sync ( + content, mem_stream, cancellable, &local_error); + + html = g_strdup_printf ( + "<audio controls>" + "<source src=\"data:%s;base64,%s\"/>" + "</audio>", + mime_type, (gchar *) byte_array->data); + + } else { + gchar *base64; + + camel_data_wrapper_decode_to_stream_sync ( + content, mem_stream, cancellable, &local_error); + + base64 = g_base64_encode ( + (guchar *) byte_array->data, byte_array->len); + html = g_strdup_printf ( + "<audio controls>" + "<source src=\"data:%s;base64,%s\"/>" + "</audio>", + mime_type, base64); + g_free (base64); + } + + /* XXX Should show the error message in the UI somehow. */ + if (local_error != NULL) { + g_warning ("%s: %s", G_STRFUNC, local_error->message); + g_error_free (local_error); + } + + camel_stream_write_string (stream, html, NULL, NULL); + + g_free (html); + + g_object_unref (mime_part); + g_object_unref (mem_stream); + + return TRUE; +} + +static void +e_mail_formatter_audio_class_init (EMailFormatterExtensionClass *class) +{ + class->display_name = _("Audio Player"); + class->description = _("Play the attachment in embedded audio player"); + class->mime_types = formatter_mime_types; + class->priority = G_PRIORITY_LOW; + class->format = mail_formatter_audio_format; +} + +static void +e_mail_formatter_audio_init (EMailFormatterExtension *extension) +{ +} + diff --git a/em-format/e-mail-formatter.c b/em-format/e-mail-formatter.c index 2f201dd07e..41bd7fdf31 100644 --- a/em-format/e-mail-formatter.c +++ b/em-format/e-mail-formatter.c @@ -62,6 +62,7 @@ struct _AsyncContext { /* internal formatter extensions */ GType e_mail_formatter_attachment_get_type (void); GType e_mail_formatter_attachment_bar_get_type (void); +GType e_mail_formatter_audio_get_type (void); GType e_mail_formatter_error_get_type (void); GType e_mail_formatter_headers_get_type (void); GType e_mail_formatter_image_get_type (void); @@ -534,6 +535,7 @@ e_mail_formatter_base_init (EMailFormatterClass *class) /* Register internal extensions. */ g_type_ensure (e_mail_formatter_attachment_get_type ()); g_type_ensure (e_mail_formatter_attachment_bar_get_type ()); + g_type_ensure (e_mail_formatter_audio_get_type ()); g_type_ensure (e_mail_formatter_error_get_type ()); g_type_ensure (e_mail_formatter_headers_get_type ()); g_type_ensure (e_mail_formatter_image_get_type ()); diff --git a/em-format/e-mail-parser-audio.c b/em-format/e-mail-parser-audio.c new file mode 100644 index 0000000000..c5e351ee76 --- /dev/null +++ b/em-format/e-mail-parser-audio.c @@ -0,0 +1,111 @@ +/* + * e-mail-parser-audio.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> +#include <glib/gi18n-lib.h> + +#include <camel/camel.h> + +#include "e-mail-extension-registry.h" +#include "e-mail-parser-extension.h" +#include "e-mail-part-audio.h" +#include "e-mail-part.h" + +typedef EMailParserExtension EMailParserAudio; +typedef EMailParserExtensionClass EMailParserAudioClass; + +GType e_mail_parser_audio_get_type (void); + +G_DEFINE_TYPE ( + EMailParserAudio, + e_mail_parser_audio, + E_TYPE_MAIL_PARSER_EXTENSION) + +static const gchar *parser_mime_types[] = { + "audio/ac3", + "audio/x-ac3", + "audio/basic", + "audio/mpeg", + "audio/x-mpeg", + "audio/mpeg3", + "audio/x-mpeg3", + "audio/mp3", + "audio/x-mp3", + "audio/mp4", + "audio/flac", + "audio/x-flac", + "audio/mod", + "audio/x-mod", + "audio/x-wav", + "audio/microsoft-wav", + "audio/x-wma", + "audio/x-ms-wma", + "audio/ogg", + "audio/x-vorbis+ogg", + "application/ogg", + "application/x-ogg", + NULL +}; + +static gboolean +mail_parser_audio_parse (EMailParserExtension *extension, + EMailParser *parser, + CamelMimePart *part, + GString *part_id, + GCancellable *cancellable, + GQueue *out_mail_queue) +{ + EMailPart *mail_part; + GQueue work_queue = G_QUEUE_INIT; + gint len; + + len = part_id->len; + g_string_append (part_id, ".audio"); + + camel_mime_part_set_disposition (part, "inline"); + + mail_part = e_mail_part_audio_new (part, part_id->str); + + g_string_truncate (part_id, len); + + g_queue_push_tail (&work_queue, mail_part); + + e_mail_parser_wrap_as_attachment ( + parser, part, part_id, &work_queue); + + e_queue_transfer (&work_queue, out_mail_queue); + + return TRUE; +} + +static void +e_mail_parser_audio_class_init (EMailParserExtensionClass *class) +{ + class->mime_types = parser_mime_types; + class->priority = G_PRIORITY_LOW; + class->flags = E_MAIL_PARSER_EXTENSION_INLINE_DISPOSITION; + class->parse = mail_parser_audio_parse; +} + +static void +e_mail_parser_audio_init (EMailParserExtension *extension) +{ +} diff --git a/em-format/e-mail-parser.c b/em-format/e-mail-parser.c index 57c362e286..f90f4d328e 100644 --- a/em-format/e-mail-parser.c +++ b/em-format/e-mail-parser.c @@ -51,6 +51,7 @@ enum { /* internal parser extensions */ GType e_mail_parser_application_mbox_get_type (void); GType e_mail_parser_attachment_bar_get_type (void); +GType e_mail_parser_audio_get_type (void); GType e_mail_parser_headers_get_type (void); GType e_mail_parser_message_get_type (void); GType e_mail_parser_secure_button_get_type (void); @@ -206,6 +207,7 @@ e_mail_parser_base_init (EMailParserClass *class) /* Register internal extensions. */ g_type_ensure (e_mail_parser_application_mbox_get_type ()); g_type_ensure (e_mail_parser_attachment_bar_get_type ()); + g_type_ensure (e_mail_parser_audio_get_type ()); g_type_ensure (e_mail_parser_headers_get_type ()); g_type_ensure (e_mail_parser_message_get_type ()); g_type_ensure (e_mail_parser_secure_button_get_type ()); diff --git a/em-format/e-mail-part-audio.c b/em-format/e-mail-part-audio.c new file mode 100644 index 0000000000..f8ba9ab428 --- /dev/null +++ b/em-format/e-mail-part-audio.c @@ -0,0 +1,85 @@ +/* + * e-mail-part-audio.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#include "e-mail-part-audio.h" + +#define E_MAIL_PART_AUDIO_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_MAIL_PART_AUDIO, EMailPartAudioPrivate)) + +G_DEFINE_TYPE ( + EMailPartAudio, + e_mail_part_audio, + E_TYPE_MAIL_PART) + +static void +mail_part_audio_constructed (GObject *object) +{ + EMailPart *part; + CamelMimePart *mime_part; + CamelContentType *content_type; + + part = E_MAIL_PART (object); + + /* Chain up to parent's constructed() method. */ + G_OBJECT_CLASS (e_mail_part_audio_parent_class)->constructed (object); + + e_mail_part_set_is_attachment (part, TRUE); + + mime_part = e_mail_part_ref_mime_part (part); + + content_type = camel_mime_part_get_content_type (mime_part); + + if (content_type != NULL) { + gchar *mime_type; + + mime_type = camel_content_type_simple (content_type); + e_mail_part_set_mime_type (part, mime_type); + g_free (mime_type); + } else { + e_mail_part_set_mime_type (part, "audio/*"); + } + + g_object_unref (mime_part); +} + +static void +e_mail_part_audio_class_init (EMailPartAudioClass *class) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (class); + object_class->constructed = mail_part_audio_constructed; +} + +static void +e_mail_part_audio_init (EMailPartAudio *part) +{ +} + +EMailPart * +e_mail_part_audio_new (CamelMimePart *mime_part, + const gchar *id) +{ + g_return_val_if_fail (id != NULL, NULL); + + return g_object_new ( + E_TYPE_MAIL_PART_AUDIO, + "id", id, "mime-part", mime_part, NULL); +} + diff --git a/em-format/e-mail-part-audio.h b/em-format/e-mail-part-audio.h new file mode 100644 index 0000000000..4aeea05b4a --- /dev/null +++ b/em-format/e-mail-part-audio.h @@ -0,0 +1,65 @@ +/* + * e-mail-part-audio.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#ifndef E_MAIL_PART_AUDIO_H +#define E_MAIL_PART_AUDIO_H + +#include <em-format/e-mail-part.h> + +/* Standard GObject macros */ +#define E_TYPE_MAIL_PART_AUDIO \ + (e_mail_part_audio_get_type ()) +#define E_MAIL_PART_AUDIO(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_MAIL_PART_AUDIO, EMailPartAudio)) +#define E_MAIL_PART_AUDIO_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_MAIL_PART_AUDIO, EMailPartAudioClass)) +#define E_IS_MAIL_PART_AUDIO(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_MAIL_PART_AUDIO)) +#define E_IS_MAIL_PART_AUDIO_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_MAIL_PART_AUDIO)) +#define E_MAIL_PART_AUDIO_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_MAIL_PART_AUDIO, EMailPartAudioClass)) + +G_BEGIN_DECLS + +typedef struct _EMailPartAudio EMailPartAudio; +typedef struct _EMailPartAudioClass EMailPartAudioClass; +typedef struct _EMailPartAudioPrivate EMailPartAudioPrivate; + +struct _EMailPartAudio { + EMailPart parent; + EMailPartAudioPrivate *priv; +}; + +struct _EMailPartAudioClass { + EMailPartClass parent_class; +}; + +GType e_mail_part_audio_get_type (void) G_GNUC_CONST; +EMailPart * e_mail_part_audio_new (CamelMimePart *mime_part, + const gchar *id); + +G_END_DECLS + +#endif /* E_MAIL_PART_AUDIO_H */ + |