Skip to content

Commit

Permalink
Merge pull request #2245 in OR/rse from ~DDOLCIMASCOLO/rse:INBOX-286 …
Browse files Browse the repository at this point in the history
…to master

* commit '78aaaf4c0534e79b18d915bef7b8b02aa5e659ed':
  INBOX-287 Fixed Inbox to accomodate Message.replyTo being an array in JMAP.
  • Loading branch information
Abdulkader BENCHI committed May 19, 2016
2 parents f757258 + 78aaaf4 commit 756cbe7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"char-api": "https://ci.open-paas.org/stash/scm/olibs/char-api.git",
"jquery.nicescroll": "3.6.8-fix",
"angular-nicescroll": "0.0.5",
"jmap-client": "0.0.13",
"jmap-client": "0.0.14",
"dynamic-directive": "2.0.0",
"iframe-resizer": "3.4.2",
"angularjs-naturalsort": "https://ci.open-paas.org/stash/scm/olibs/angularjs-naturalsort.git",
Expand Down
12 changes: 5 additions & 7 deletions modules/linagora.esn.unifiedinbox/frontend/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,10 @@ angular.module('linagora.esn.unifiedinbox')
}
}

function getReplyToField(email) {
if (email.replyTo && jmap.EMailer.unknown().email !== email.replyTo.email) {
return email.replyTo;
}
function getReplyToRecipients(email) {
var replyTo = _.reject(email.replyTo, { email: jmap.EMailer.unknown().email });

return email.from;
return replyTo.length > 0 ? replyTo : [email.from];
}

function getReplyAllRecipients(email, sender) {
Expand All @@ -285,7 +283,7 @@ angular.module('linagora.esn.unifiedinbox')
}

return {
to: _(email.to || []).concat(getReplyToField(email)).uniq('email').value().filter(notMe),
to: _(email.to || []).concat(getReplyToRecipients(email)).uniq('email').value().filter(notMe),
cc: (email.cc || []).filter(notMe),
bcc: email.bcc || []
};
Expand All @@ -297,7 +295,7 @@ angular.module('linagora.esn.unifiedinbox')
}

return {
to: [getReplyToField(email)],
to: getReplyToRecipients(email),
cc: [],
bcc: []
};
Expand Down
32 changes: 21 additions & 11 deletions modules/linagora.esn.unifiedinbox/test/unit-frontend/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,13 @@ describe('The Unified Inbox Angular module services', function() {
expect(emailSendingService.getReplyAllRecipients(email, sender)).to.shallowDeepEqual(expectedEmail);
});

it('should leverage the replyTo filed instead of FROM (when provided)', function() {
it('should leverage the replyTo field instead of FROM (when provided)', function() {
email = {
to: [{displayName: '1', email: '[email protected]'}, {displayName: '2', email: '[email protected]'}],
cc: [{displayName: '3', email: '[email protected]'}, {displayName: '4', email: '[email protected]'}],
bcc: [{displayName: '5', email: '[email protected]'}, {displayName: '6', email: '[email protected]'}],
from: {displayName: '0', email: '[email protected]'},
replyTo: {displayName: 'replyToEmail', email: '[email protected]'}
replyTo: [{displayName: 'replyToEmail', email: '[email protected]'}]
};

sender = {displayName: 'sender', email: '[email protected]'};
Expand Down Expand Up @@ -807,37 +807,47 @@ describe('The Unified Inbox Angular module services', function() {

describe('The getReplyRecipients function', function() {
var email, sender, expectedEmail;

it('should do nothing when email is not provided', function() {
expect(emailSendingService.getReplyRecipients(null)).to.be.undefined;
});

it('should reply to FROM if FROM is not the sender', function() {
it('should reply to FROM if ReplyTo is not present', function() {
email = {
from: {displayName: '0', email: '[email protected]'}
};

sender = {displayName: 'sender', email: '[email protected]'};

expectedEmail = {
to: [{displayName: '0', email: '[email protected]'}]
};

expect(emailSendingService.getReplyRecipients(email, sender)).to.shallowDeepEqual(expectedEmail);
expect(emailSendingService.getReplyRecipients(email)).to.shallowDeepEqual(expectedEmail);
});

it('should reply to ReplyTo if ReplyTo is not the sender', function() {
it('should reply to ReplyTo if ReplyTo is present', function() {
email = {
from: {displayName: '0', email: '[email protected]'},
replyTo: {displayName: 'replyto', email: '[email protected]'}
replyTo: [{displayName: 'replyto', email: '[email protected]'}]
};

sender = {displayName: 'sender', email: '[email protected]'};

expectedEmail = {
to: [{displayName: 'replyto', email: '[email protected]'}]
};

expect(emailSendingService.getReplyRecipients(email, sender)).to.shallowDeepEqual(expectedEmail);
expect(emailSendingService.getReplyRecipients(email)).to.shallowDeepEqual(expectedEmail);
});

it('should reply to ReplyTo if ReplyTo is present, filtering out unknown EMailers', function() {
email = {
from: {displayName: '0', email: '[email protected]'},
replyTo: [{displayName: 'replyto', email: '[email protected]'}, { email: '@' }, { name: 'second', email: '[email protected]' }]
};

expectedEmail = {
to: [{displayName: 'replyto', email: '[email protected]'}, { name: 'second', email: '[email protected]' }]
};

expect(emailSendingService.getReplyRecipients(email)).to.shallowDeepEqual(expectedEmail);
});

});
Expand Down

0 comments on commit 756cbe7

Please sign in to comment.