0
|
1 /**
|
|
2 * ZipDownload plugin script
|
|
3 *
|
|
4 * @licstart The following is the entire license notice for the
|
|
5 * JavaScript code in this file.
|
|
6 *
|
|
7 * Copyright (c) 2013-2014, The Roundcube Dev Team
|
|
8 *
|
|
9 * The JavaScript code in this page is free software: you can redistribute it
|
|
10 * and/or modify it under the terms of the GNU General Public License
|
|
11 * as published by the Free Software Foundation, either version 3 of
|
|
12 * the License, or (at your option) any later version.
|
|
13 *
|
|
14 * @licend The above is the entire license notice
|
|
15 * for the JavaScript code in this file.
|
|
16 */
|
|
17
|
|
18 window.rcmail && rcmail.addEventListener('init', function(evt) {
|
|
19 // register additional actions
|
|
20 rcmail.register_command('download-eml', function() { rcmail_zipdownload('eml'); });
|
|
21 rcmail.register_command('download-mbox', function() { rcmail_zipdownload('mbox'); });
|
|
22 rcmail.register_command('download-maildir', function() { rcmail_zipdownload('maildir'); });
|
|
23
|
|
24 // commands status
|
|
25 rcmail.message_list && rcmail.message_list.addEventListener('select', function(list) {
|
|
26 var selected = list.get_selection().length;
|
|
27
|
|
28 rcmail.enable_command('download', selected > 0);
|
|
29 rcmail.enable_command('download-eml', selected == 1);
|
|
30 rcmail.enable_command('download-mbox', 'download-maildir', selected > 1);
|
|
31 });
|
|
32
|
|
33 // hook before default download action
|
|
34 rcmail.addEventListener('beforedownload', rcmail_zipdownload_menu);
|
|
35
|
|
36 // find and modify default download link/button
|
|
37 $.each(rcmail.buttons['download'] || [], function() {
|
|
38 var link = $('#' + this.id),
|
|
39 span = $('span', link);
|
|
40
|
|
41 if (!span.length) {
|
|
42 span = $('<span>');
|
|
43 link.html('').append(span);
|
|
44 }
|
|
45
|
|
46 span.text(rcmail.get_label('zipdownload.download'));
|
|
47 rcmail.env.download_link = link;
|
|
48 });
|
|
49 });
|
|
50
|
|
51
|
|
52 function rcmail_zipdownload(mode)
|
|
53 {
|
|
54 // default .eml download of single message
|
|
55 if (mode == 'eml') {
|
|
56 var uid = rcmail.get_single_uid();
|
|
57 rcmail.goto_url('viewsource', rcmail.params_from_uid(uid, {_save: 1}), false, true);
|
|
58 return;
|
|
59 }
|
|
60
|
|
61 // multi-message download, use hidden form to POST selection
|
|
62 if (rcmail.message_list && rcmail.message_list.get_selection().length > 1) {
|
|
63 var inputs = [], form = $('#zipdownload-form'),
|
|
64 post = rcmail.selection_post_data();
|
|
65
|
|
66 post._mode = mode;
|
|
67 post._token = rcmail.env.request_token;
|
|
68
|
|
69 $.each(post, function(k, v) {
|
|
70 if (typeof v == 'object' && v.length > 1) {
|
|
71 for (var j=0; j < v.length; j++)
|
|
72 inputs.push($('<input>').attr({type: 'hidden', name: k+'[]', value: v[j]}));
|
|
73 }
|
|
74 else {
|
|
75 inputs.push($('<input>').attr({type: 'hidden', name: k, value: v}));
|
|
76 }
|
|
77 });
|
|
78
|
|
79 if (!form.length)
|
|
80 form = $('<form>').attr({
|
|
81 style: 'display: none',
|
|
82 method: 'POST',
|
|
83 action: '?_task=mail&_action=plugin.zipdownload.messages'
|
|
84 })
|
|
85 .appendTo('body');
|
|
86
|
|
87 form.html('').append(inputs).submit();
|
|
88 }
|
|
89 }
|
|
90
|
|
91 // display download options menu
|
|
92 function rcmail_zipdownload_menu(e)
|
|
93 {
|
|
94 // show (sub)menu for download selection
|
|
95 rcmail.command('menu-open', 'zipdownload-menu', e && e.target ? e.target : rcmail.env.download_link, e);
|
|
96
|
|
97 // abort default download action
|
|
98 return false;
|
|
99 }
|