Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

zipdownload.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. window.rcmail && rcmail.addEventListener('init', function(evt) {
  18. // register additional actions
  19. rcmail.register_command('download-eml', function() { rcmail_zipdownload('eml'); });
  20. rcmail.register_command('download-mbox', function() { rcmail_zipdownload('mbox'); });
  21. rcmail.register_command('download-maildir', function() { rcmail_zipdownload('maildir'); });
  22. // commands status
  23. rcmail.message_list && rcmail.message_list.addEventListener('select', function(list) {
  24. var selected = list.get_selection().length;
  25. rcmail.enable_command('download', selected > 0);
  26. rcmail.enable_command('download-eml', selected == 1);
  27. rcmail.enable_command('download-mbox', 'download-maildir', selected > 1);
  28. });
  29. // hook before default download action
  30. rcmail.addEventListener('beforedownload', rcmail_zipdownload_menu);
  31. // find and modify default download link/button
  32. $.each(rcmail.buttons['download'] || [], function() {
  33. var link = $('#' + this.id),
  34. span = $('span', link);
  35. if (!span.length) {
  36. span = $('<span>');
  37. link.html('').append(span);
  38. }
  39. span.text(rcmail.get_label('zipdownload.download'));
  40. rcmail.env.download_link = link;
  41. });
  42. });
  43. function rcmail_zipdownload(mode)
  44. {
  45. // default .eml download of single message
  46. if (mode == 'eml') {
  47. var uid = rcmail.get_single_uid();
  48. rcmail.goto_url('viewsource', rcmail.params_from_uid(uid, {_save: 1}), false, true);
  49. return;
  50. }
  51. // multi-message download, use hidden form to POST selection
  52. if (rcmail.message_list && rcmail.message_list.get_selection().length > 1) {
  53. var inputs = [], form = $('#zipdownload-form'),
  54. post = rcmail.selection_post_data();
  55. post._mode = mode;
  56. post._token = rcmail.env.request_token;
  57. $.each(post, function(k, v) {
  58. if (typeof v == 'object' && v.length > 1) {
  59. for (var j=0; j < v.length; j++)
  60. inputs.push($('<input>').attr({type: 'hidden', name: k+'[]', value: v[j]}));
  61. }
  62. else {
  63. inputs.push($('<input>').attr({type: 'hidden', name: k, value: v}));
  64. }
  65. });
  66. if (!form.length)
  67. form = $('<form>').attr({
  68. style: 'display: none',
  69. method: 'POST',
  70. action: '?_task=mail&_action=plugin.zipdownload.messages'
  71. })
  72. .appendTo('body');
  73. form.html('').append(inputs).submit();
  74. }
  75. }
  76. // display download options menu
  77. function rcmail_zipdownload_menu(e)
  78. {
  79. // show (sub)menu for download selection
  80. rcmail.command('menu-open', 'zipdownload-menu', e && e.target ? e.target : rcmail.env.download_link, e);
  81. // abort default download action
  82. return false;
  83. }