Commit 1ff53d38 authored by Kyle Evans's avatar Kyle Evans
Browse files

Unpack the mms and save attachments



This also adds initial display support via uri link and deletes the
MMSD message.
Signed-off-by: Kyle Evans's avatarKyle Evans <kvans32@gmail.com>
parent ffd3f965
Pipeline #62189 passed with stages
in 4 minutes and 16 seconds
......@@ -720,6 +720,47 @@ pur_mm_delete_sms (PurSmsProps *sms_props)
}
}
static void
cb_pur_mmsd_delete_mms(GObject *interface,
GAsyncResult *result,
gpointer *user_data)
{
g_autoptr(GError) error = NULL;
if (g_dbus_proxy_call_finish(G_DBUS_PROXY(interface),
result,
&error)) {
g_debug ("MMS delete finished");
} else {
g_debug ("Couldn't delete MMS - error: %s", error ? error->message : "unknown");
}
}
static void
pur_mmsd_delete_mms(gchar *objectpath)
{
pur_mmsd_data_t *mmsd = pur_mmsd_get_data ();
GDBusProxy *message_proxy =
g_dbus_proxy_new_sync (mmsd->connection,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
NULL,
"org.ofono.mms",
objectpath,
"org.ofono.mms.Message",
NULL,
NULL);
g_dbus_proxy_call(message_proxy,
"Delete",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
(GAsyncReadyCallback)cb_pur_mmsd_delete_mms,
NULL);
}
static void
pur_mmsd_receive_message (GVariant *message_t)
......@@ -729,7 +770,7 @@ pur_mmsd_receive_message (GVariant *message_t)
GVariantIter iter;
gchar *objectpath, *date, *subject, *sender, *smil;
gchar *containerpath, *filename, *mimetype;
gchar *containerpath, *filenode, *filename, *mimetype;
guint data, size;
......@@ -756,20 +797,99 @@ pur_mmsd_receive_message (GVariant *message_t)
g_variant_iter_init (&iter, attachments);
serv_got_im (pc, sender, subject, PURPLE_MESSAGE_RECV,
time (NULL));
GFile *container = NULL;
GFile *savepath;
char *contents;
gsize length, written = 0;
gchar *tag;
g_autoptr(GError) error = NULL;
while ((attach = g_variant_iter_next_value (&iter))) {
g_variant_get (attach, "(ssstt)", &filename,
g_variant_get (attach, "(ssstt)", &filenode,
&mimetype,
&container,
&containerpath,
&data,
&size);
if (!container) {
container = g_file_new_for_path (containerpath);
g_file_load_contents (container,
NULL,
&contents,
&length,
NULL,
&error);
const gchar *home = g_get_home_dir ();
tag = g_strconcat (date, sender, NULL);
savepath = g_file_new_build_filename (home,
"mms",
tag,
NULL);
g_free(tag);
if (!g_file_make_directory_with_parents (savepath, NULL, &error)) {
g_warning ("%s", error->message);
serv_got_im (pc, sender, error->message, PURPLE_MESSAGE_SYSTEM,
time (NULL));
break;
} else {
serv_got_im (pc, sender, subject, PURPLE_MESSAGE_RECV,
time (NULL));
}
}
filename = g_strdup (filenode);
g_strdelimit (filename, "<>", ' ');
g_strstrip (filename);
GFile *new = g_file_get_child (savepath, filename);
GFileOutputStream *out = g_file_create (new, G_FILE_CREATE_PRIVATE, NULL, &error);
if (error) {
g_warning ("%s", error->message);
serv_got_im (pc, sender, error->message, PURPLE_MESSAGE_SYSTEM,
time (NULL));
break;
}
if (!g_output_stream_write_all (G_OUTPUT_STREAM(out),
contents + data,
size,
&written,
NULL,
&error)) {
g_warning ("attachment not saved!");
g_warning ("%s", error->message);
serv_got_im (pc, sender, error->message, PURPLE_MESSAGE_SYSTEM,
time (NULL));
}
g_output_stream_close (G_OUTPUT_STREAM(out), NULL, NULL);
char *uri = g_file_get_uri (new);
serv_got_im (pc, sender, mimetype, PURPLE_MESSAGE_RECV |
PURPLE_MESSAGE_RAW, time (NULL));
serv_got_im (pc, sender, uri , PURPLE_MESSAGE_RECV |
PURPLE_MESSAGE_RAW, time (NULL));
g_free (uri);
}
g_free(contents);
g_object_unref(container);
if (!error) {
pur_mmsd_delete_mms(objectpath);
} else {
}
}
static void
......@@ -805,8 +925,6 @@ pur_mmsd_get_all_mms_cb (GObject *service,
msg_pack = g_variant_get_child_value (ret, 0);
/*TODO: This list is all received MMS. If they are to be saved somewhere
* else then they will need to be removed from mmsd.*/
if ((num = g_variant_iter_init (&iter, msg_pack))) {
GVariant *message_t;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment