diff options
author | Zara Gebru <zgebru@thoughtworks.com> | 2016-12-02 15:25:23 +0100 |
---|---|---|
committer | Zara Gebru <zgebru@thoughtworks.com> | 2016-12-02 15:25:23 +0100 |
commit | b14833fbb56bcd5bff0750c16fd9214009b955be (patch) | |
tree | a1ec621dd5f76d756ac59b72a763a34a2c189387 /web-ui/app/js/services/model | |
parent | 688a8b42e8ab7c6d4529b6dda66f40eead07ad02 (diff) |
[refactor] move app dir into public dir
Diffstat (limited to 'web-ui/app/js/services/model')
-rw-r--r-- | web-ui/app/js/services/model/mail.js | 126 |
1 files changed, 0 insertions, 126 deletions
diff --git a/web-ui/app/js/services/model/mail.js b/web-ui/app/js/services/model/mail.js deleted file mode 100644 index 64a10c1c..00000000 --- a/web-ui/app/js/services/model/mail.js +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2014 ThoughtWorks, Inc. - * - * Pixelated is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Pixelated is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. - */ -define(['helpers/contenttype'], function (contentType) { - 'use strict'; - function isSentMail() { - return _.has(this, 'mailbox') && this.mailbox.toUpperCase() === 'SENT'; - } - - function isDraftMail() { - return _.has(this, 'mailbox') && this.mailbox.toUpperCase() === 'DRAFTS'; - } - - function isInTrash() { - return _.has(this, 'mailbox') && this.mailbox.toUpperCase() === 'TRASH'; - } - - function setDraftReplyFor(ident) { - this.draft_reply_for = ident; - } - - function replyToAddress() { - return { - to: [this.replying.single], - cc: [] - }; - } - - function replyToAllAddress() { - return { - to: this.replying.all['to-field'], - cc: this.replying.all['cc-field'] - }; - } - - function getHeadersFromMailPart (rawBody) { - var lines, headerLines, endOfHeaders, headers; - - lines = rawBody.split('\n'); - endOfHeaders = _.indexOf(lines, ''); - headerLines = lines.slice(0, endOfHeaders); - - headers = _.map(headerLines, function (headerLine) { - return _.map(headerLine.split(':'), function(elem){return elem.trim();}); - }); - - return _.object(headers); - } - - function getBodyFromMailPart (rawBody) { - var lines, endOfHeaders; - - lines = rawBody.split('\n'); - endOfHeaders = _.indexOf(lines, ''); - - return lines.slice(endOfHeaders + 1).join('\n'); - } - - function parseWithHeaders(rawBody) { - return {headers: getHeadersFromMailPart(rawBody), body: getBodyFromMailPart(rawBody)}; - } - - function getMailMultiParts () { - var mediaType = this.getMailMediaType(); - var boundary = '--' + mediaType.params.boundary + '\n'; - var finalBoundary = '--' + mediaType.params.boundary + '--'; - - var bodyParts = this.body.split(finalBoundary)[0].split(boundary); - - bodyParts = _.reject(bodyParts, function(bodyPart) { return _.isEmpty(bodyPart.trim()); }); - - return _.map(bodyParts, parseWithHeaders); - } - - function getMailMediaType () { - return new contentType.MediaType(this.header.content_type); - } - - function isMailMultipartAlternative () { - return this.getMailMediaType().type === 'multipart/alternative'; - } - - function availableBodyPartsContentType () { - var bodyParts = this.getMailMultiParts(); - - return _.pluck(_.pluck(bodyParts, 'headers'), 'Content-Type'); - } - - function getMailPartByContentType (contentType) { - var bodyParts = this.getMailMultiParts(); - - return _.findWhere(bodyParts, {headers: {'Content-Type': contentType}}); - } - - return { - create: function (mail) { - if (!mail) { return; } - - mail.isSentMail = isSentMail; - mail.isDraftMail = isDraftMail; - mail.isInTrash = isInTrash; - mail.setDraftReplyFor = setDraftReplyFor; - mail.replyToAddress = replyToAddress; - mail.replyToAllAddress = replyToAllAddress; - mail.getMailMediaType = getMailMediaType; - mail.isMailMultipartAlternative = isMailMultipartAlternative; - mail.getMailMultiParts = getMailMultiParts; - mail.availableBodyPartsContentType = availableBodyPartsContentType; - mail.getMailPartByContentType = getMailPartByContentType; - return mail; - } - }; -}); |