mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-06-08 20:09:44 +00:00
Download attachments of a message as a zip archive
This commit is contained in:
@@ -192,14 +192,21 @@
|
||||
},
|
||||
responseType: 'arraybuffer',
|
||||
cache: false,
|
||||
transformResponse: function (data, headers) {
|
||||
transformResponse: function (data, headers, status) {
|
||||
var fileName, result, blob = null;
|
||||
|
||||
if (status < 200 || status > 299) {
|
||||
throw new Error('Bad gateway');
|
||||
}
|
||||
if (data) {
|
||||
blob = new Blob([data], { type: type });
|
||||
}
|
||||
fileName = getFileNameFromHeader(headers('content-disposition'));
|
||||
|
||||
if (options && options.filename) {
|
||||
fileName = options.filename;
|
||||
}
|
||||
else {
|
||||
getFileNameFromHeader(headers('content-disposition'));
|
||||
}
|
||||
if (!saveAs) {
|
||||
throw new Error('To use Resource.download, FileSaver.js must be loaded.');
|
||||
}
|
||||
|
||||
@@ -659,7 +659,7 @@
|
||||
AddressBook.prototype.$deleteCards = function(cards) {
|
||||
var _this = this,
|
||||
ids = _.map(cards, 'id');
|
||||
|
||||
|
||||
return AddressBook.$$resource.post(this.id, 'batchDelete', {uids: ids}).then(function() {
|
||||
_this.$_deleteCards(ids);
|
||||
});
|
||||
@@ -713,14 +713,19 @@
|
||||
* @returns a promise of the HTTP operation
|
||||
*/
|
||||
AddressBook.prototype.exportCards = function(selectedOnly) {
|
||||
var selectedUIDs;
|
||||
var data = null, options, selectedCards;
|
||||
|
||||
options = {
|
||||
type: 'application/octet-stream',
|
||||
filename: this.name + '.ldif'
|
||||
};
|
||||
|
||||
if (selectedOnly) {
|
||||
var selectedCards = _.filter(this.$cards, function(card) { return card.selected; });
|
||||
selectedUIDs = _.map(selectedCards, 'id');
|
||||
selectedCards = _.filter(this.$cards, function(card) { return card.selected; });
|
||||
data = { uids: _.map(selectedCards, 'id') };
|
||||
}
|
||||
|
||||
return AddressBook.$$resource.download(this.id, 'export', (angular.isDefined(selectedUIDs) ? {uids: selectedUIDs} : null), {type: 'application/octet-stream'});
|
||||
return AddressBook.$$resource.download(this.id, 'export', data, options);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -269,11 +269,15 @@
|
||||
* @returns a promise of the HTTP operation
|
||||
*/
|
||||
Card.prototype.export = function() {
|
||||
var selectedIDs;
|
||||
var data, options;
|
||||
|
||||
selectedIDs = [ this.id ];
|
||||
data = { uids: [ this.id ] };
|
||||
options = {
|
||||
type: 'application/octet-stream',
|
||||
filename: this.$$fullname + '.ldif'
|
||||
};
|
||||
|
||||
return Card.$$resource.download(this.pid, 'export', {uids: selectedIDs}, {type: 'application/octet-stream'});
|
||||
return Card.$$resource.download(this.pid, 'export', data, options);
|
||||
};
|
||||
|
||||
Card.prototype.$fullname = function(options) {
|
||||
|
||||
@@ -598,10 +598,12 @@
|
||||
* @returns a promise of the HTTP operation
|
||||
*/
|
||||
Mailbox.prototype.saveSelectedMessages = function() {
|
||||
var selectedMessages, selectedUIDs;
|
||||
var data, options, selectedMessages, selectedUIDs;
|
||||
|
||||
selectedMessages = _.filter(this.$messages, function(message) { return message.selected; });
|
||||
selectedUIDs = _.map(selectedMessages, 'uid');
|
||||
data = { uids: selectedUIDs };
|
||||
options = { filename: l('Saved Messages.zip') };
|
||||
|
||||
return Mailbox.$$resource.download(this.id, 'saveMessages', {uids: selectedUIDs});
|
||||
};
|
||||
@@ -613,7 +615,11 @@
|
||||
* @returns a promise of the HTTP operation
|
||||
*/
|
||||
Mailbox.prototype.exportFolder = function() {
|
||||
return Mailbox.$$resource.download(this.id, 'exportFolder');
|
||||
var options;
|
||||
|
||||
options = { filename: this.name + '.zip' };
|
||||
|
||||
return Mailbox.$$resource.download(this.id, 'exportFolder', null, options);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -742,7 +748,7 @@
|
||||
return _this.$_deleteMessages(uids, messages);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @function $reset
|
||||
* @memberof Mailbox.prototype
|
||||
|
||||
@@ -444,9 +444,9 @@
|
||||
* @function $imipAction
|
||||
* @memberof Message.prototype
|
||||
* @desc Perform IMIP actions on the current message.
|
||||
* @param {string} path - the path of the IMIP calendar part
|
||||
* @param {string} path - the path of the IMIP calendar part
|
||||
* @param {string} action - the the IMIP action to perform
|
||||
* @param {object} data - the delegation info
|
||||
* @param {object} data - the delegation info
|
||||
*/
|
||||
Message.prototype.$imipAction = function(path, action, data) {
|
||||
var _this = this;
|
||||
@@ -657,7 +657,7 @@
|
||||
/**
|
||||
* @function $unwrap
|
||||
* @memberof Message.prototype
|
||||
* @desc Unwrap a promise.
|
||||
* @desc Unwrap a promise.
|
||||
* @param {promise} futureMessageData - a promise of some of the Message's data
|
||||
*/
|
||||
Message.prototype.$unwrap = function(futureMessageData) {
|
||||
@@ -708,17 +708,32 @@
|
||||
};
|
||||
|
||||
/**
|
||||
* @function saveMessage
|
||||
* @function download
|
||||
* @memberof Message.prototype
|
||||
* @desc Download the current message
|
||||
* @returns a promise of the HTTP operation
|
||||
*/
|
||||
Message.prototype.saveMessage = function() {
|
||||
var selectedUIDs;
|
||||
Message.prototype.download = function() {
|
||||
var data, options;
|
||||
|
||||
selectedUIDs = [ this.uid ];
|
||||
data = { uids: [this.uid] };
|
||||
options = { filename: this.subject + '.zip' };
|
||||
|
||||
return Message.$$resource.download(this.$mailbox.id, 'saveMessages', {uids: selectedUIDs});
|
||||
return Message.$$resource.download(this.$mailbox.id, 'saveMessages', data, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* @function downloadAttachments
|
||||
* @memberof Message.prototype
|
||||
* @desc Download an archive of all attachments
|
||||
* @returns a promise of the HTTP operation
|
||||
*/
|
||||
Message.prototype.downloadAttachments = function() {
|
||||
var options;
|
||||
|
||||
options = { filename: l('attachments') + "-" + this.uid + ".zip" };
|
||||
|
||||
return Message.$$resource.download(this.$absolutePath(), 'archiveAttachments', null, options);
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
@@ -530,7 +530,14 @@
|
||||
* @returns a promise of the HTTP operation
|
||||
*/
|
||||
Calendar.prototype.export = function() {
|
||||
return Calendar.$$resource.download(this.id + '.ics', 'export', null, {type: 'application/octet-stream'});
|
||||
var options;
|
||||
|
||||
options = {
|
||||
type: 'application/octet-stream',
|
||||
filename: this.name + '.ics'
|
||||
};
|
||||
|
||||
return Calendar.$$resource.download(this.id + '.ics', 'export', null, options);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user