mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 12:39:20 +03:00
Typescript (first look)
This commit is contained in:
parent
3217303a65
commit
a74a92638a
17 changed files with 356 additions and 289 deletions
|
|
@ -2,18 +2,16 @@
|
|||
// Base64 encode / decode
|
||||
// http://www.webtoolkit.info/
|
||||
|
||||
const BASE_64_CHR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||
const BASE_64_CHR: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||
|
||||
/* jslint bitwise: true */
|
||||
/* eslint-disable */
|
||||
const Base64 = {
|
||||
|
||||
// public method for urlsafe encoding
|
||||
urlsafe_encode: (input) => Base64.encode(input)
|
||||
urlsafe_encode: (input: string): string => Base64.encode(input)
|
||||
.replace(/[+]/g, '-').replace(/[\/]/g, '_').replace(/[=]/g, '.'),
|
||||
|
||||
// public method for encoding
|
||||
encode: (input) => {
|
||||
encode: (input: string): string => {
|
||||
|
||||
let
|
||||
output = '',
|
||||
|
|
@ -52,7 +50,7 @@ const Base64 = {
|
|||
},
|
||||
|
||||
// public method for decoding
|
||||
decode: (input) => {
|
||||
decode: (input: string): string => {
|
||||
|
||||
let
|
||||
output = '',
|
||||
|
|
@ -90,7 +88,7 @@ const Base64 = {
|
|||
},
|
||||
|
||||
// private method for UTF-8 encoding
|
||||
_utf8_encode: (string) => {
|
||||
_utf8_encode: (string: string): string => {
|
||||
|
||||
string = string.replace(/\r\n/g, "\n");
|
||||
|
||||
|
|
@ -126,7 +124,7 @@ const Base64 = {
|
|||
},
|
||||
|
||||
// private method for UTF-8 decoding
|
||||
_utf8_decode: (utftext) => {
|
||||
_utf8_decode: (utftext: string): string => {
|
||||
|
||||
let
|
||||
string = '',
|
||||
|
|
@ -163,8 +161,6 @@ const Base64 = {
|
|||
return string;
|
||||
}
|
||||
};
|
||||
/* jslint bitwise: false */
|
||||
/* eslint-enable */
|
||||
|
||||
export const decode = Base64.decode;
|
||||
export const encode = Base64.encode;
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
export const MESSAGES_PER_PAGE = 20;
|
||||
|
||||
export const MESSAGES_PER_PAGE_VALUES = [10, 20, 30, 50, 100];
|
||||
|
||||
export const CONTACTS_PER_PAGE = 50;
|
||||
|
||||
export const DEFAULT_AJAX_TIMEOUT = 30000;
|
||||
|
||||
export const SEARCH_AJAX_TIMEOUT = 300000;
|
||||
|
||||
export const SEND_MESSAGE_AJAX_TIMEOUT = 300000;
|
||||
|
||||
export const SAVE_MESSAGE_AJAX_TIMEOUT = 200000;
|
||||
|
||||
export const CONTACTS_SYNC_AJAX_TIMEOUT = 200000;
|
||||
|
||||
export const UNUSED_OPTION_VALUE = '__UNUSE__';
|
||||
|
||||
export const CLIENT_SIDE_STORAGE_INDEX_NAME = 'rlcsc';
|
||||
|
||||
export const IMAP_DEFAULT_PORT = 143;
|
||||
|
||||
export const IMAP_DEFAULT_SECURE_PORT = 993;
|
||||
|
||||
export const SMTP_DEFAULT_PORT = 25;
|
||||
|
||||
export const SMTP_DEFAULT_SECURE_PORT = 465;
|
||||
|
||||
export const SIEVE_DEFAULT_PORT = 4190;
|
||||
|
||||
export const MESSAGE_BODY_CACHE_LIMIT = 15;
|
||||
|
||||
export const AJAX_ERROR_LIMIT = 7;
|
||||
|
||||
export const TOKEN_ERROR_LIMIT = 10;
|
||||
|
||||
export const RAINLOOP_TRIAL_KEY = 'RAINLOOP-TRIAL-KEY';
|
||||
|
||||
export const DATA_IMAGE_USER_DOT_PIC = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC4AAAAuCAYAAABXuSs3AAAHHklEQVRoQ7VZW08bVxCeXRuwIbTGXIwNtBBaqjwgVUiR8lDlbza9qe1DpVZ9aNQ/0KpPeaJK07SpcuEeCEmUAObm21bfrL9lONjexSYrWfbunj37zXdmvpkz9oIgCKTD0W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XLu53D1XAwjhXwvvv+h4BAXVe4bOu3O3ChxF08LiZFG3fel199G9CH3fLyqv24NcB44MRhpdK788U3CpyKwsCw590xmfSpzsBt0Fqc3ud3vtZigxWcVZCklVpSiN0w3q5E/h9TGMIUuA3+EQAAAABJRU5ErkJggg==';
|
||||
|
||||
export const DATA_IMAGE_TRANSP_PIC = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQIW2NkAAIAAAoAAggA9GkAAAAASUVORK5CYII=';
|
||||
42
dev/Common/Consts.ts
Normal file
42
dev/Common/Consts.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
export const MESSAGES_PER_PAGE: number = 20;
|
||||
|
||||
export const MESSAGES_PER_PAGE_VALUES: number[] = [10, 20, 30, 50, 100];
|
||||
|
||||
export const CONTACTS_PER_PAGE: number = 50;
|
||||
|
||||
export const DEFAULT_AJAX_TIMEOUT: number = 30000;
|
||||
|
||||
export const SEARCH_AJAX_TIMEOUT: number = 300000;
|
||||
|
||||
export const SEND_MESSAGE_AJAX_TIMEOUT: number = 300000;
|
||||
|
||||
export const SAVE_MESSAGE_AJAX_TIMEOUT: number = 200000;
|
||||
|
||||
export const CONTACTS_SYNC_AJAX_TIMEOUT: number = 200000;
|
||||
|
||||
export const UNUSED_OPTION_VALUE: string = '__UNUSE__';
|
||||
|
||||
export const CLIENT_SIDE_STORAGE_INDEX_NAME: string = 'rlcsc';
|
||||
|
||||
export const IMAP_DEFAULT_PORT: number = 143;
|
||||
|
||||
export const IMAP_DEFAULT_SECURE_PORT: number = 993;
|
||||
|
||||
export const SMTP_DEFAULT_PORT: number = 25;
|
||||
|
||||
export const SMTP_DEFAULT_SECURE_PORT: number = 465;
|
||||
|
||||
export const SIEVE_DEFAULT_PORT: number = 4190;
|
||||
|
||||
export const MESSAGE_BODY_CACHE_LIMIT: number = 15;
|
||||
|
||||
export const AJAX_ERROR_LIMIT: number = 7;
|
||||
|
||||
export const TOKEN_ERROR_LIMIT: number = 10;
|
||||
|
||||
export const RAINLOOP_TRIAL_KEY: string = 'RAINLOOP-TRIAL-KEY';
|
||||
|
||||
export const DATA_IMAGE_USER_DOT_PIC: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC4AAAAuCAYAAABXuSs3AAAHHklEQVRoQ7VZW08bVxCeXRuwIbTGXIwNtBBaqjwgVUiR8lDlbza9qe1DpVZ9aNQ/0KpPeaJK07SpcuEeCEmUAObm21bfrL9lONjexSYrWfbunj37zXdmvpkz9oIgCKTD0Wg0xPd94TDP83Q0zvWa50vzklSrdanVanqf4/D84GBGr+F+Op3S8fqoJxLOdnZgTvsO/nYhenHA+UC7CWF1uXwkb9++ldPTUwVerVbVqFQqpR8YPjQ0JCMjI5LNDijoRgP3PQVu5+5Eor2XGLg7IV4GkIdHJ/LmzRs5ODiIwNbrdR0O0GCcq4Xz4eFhmZyclP7+tDQaIik/BG5XKQn4SwG3zJTLZXn9+rUclI8UHD5YVoDDN8bSzXhONwL48fFxGR4eilzFZT1uFRIB5yT8BqCdnR3Z3d0VP9Un6XRawYJpggVrZBv38ME4XKtUKnLt2jUplUoy1PR/l3U7T6sVSAQcgMAkj8PDQ9ne3pajoyMRL7zeKsYZWHgWYDGmv78/mmdwcFA+mJlSgziHDWrERrsjEXDXegTi1tZW+DLxI2bxIrqFNYTXyDyCFweMAHCwb8e4RnTNuOsqe3t7sra21pTD0Kct666E8XlcZyzw9/RUUXK5nK5oUinUQI6TQ3cynO/v78vq6qrKXCNwlTiJJpyNGc3nZHp6uqV2dwrQWOCtZBDAV1ZWwsQk7f0wiQn5kffbAu/0/KWBYzIC1+XukfGx0RGZmppKlC2tIV0Bh4aDcZW7HhkfH8urLLZL7T2pihvlkMNnz56FiadHxicL41IsFpN41bkxsYxbRdFo9jwB8KdPn14J8KnSpBQKhQs63nPmbCVRcBUAR2Lq1VVmpksyMTFxAXjcEsQybiegESionjx5osCZOeNe1O4+EhCAX7bQSgQc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eMltovbDfh6c1vIgMYcliSsKv4IWFr6VDHxvldvBAH+1sA+cnl5WYOPmmr9ir+1l9I0Cgz0yjhXjfJJ0JROnmezWbl165ayr/5fqwcBNr7IfhjMqKcvESSM4eRcCasQ3bDNObmKPLdGUGpZsN24cUNLBm9zazu4d++e6qpNBFaTuUS26U5dpuR1CxyA7J9ddrMRqlz4pwLLYawymPd++/2PADt2ugcGwq9gCCdhQ96C6xWwa6j1ceuq+I0EhW0i8MAIVJfeL3d/DVD8EKi12P6/2S2jV/EccVB54O/ejz/9HGCpoBBMta5rXMXLu53D1XAwjhXwvvv+h4BAXVe4bOu3O3ChxF08LiZFG3fel199G9CH3fLyqv24NcB44MRhpdK788U3CpyKwsCw590xmfSpzsBt0Fqc3ud3vtZigxWcVZCklVpSiN0w3q5E/h9TGMIUuA3+EQAAAABJRU5ErkJggg==';
|
||||
|
||||
export const DATA_IMAGE_TRANSP_PIC: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQIW2NkAAIAAAoAAggA9GkAAAAASUVORK5CYII=';
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
/* eslint quote-props: 0 */
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
/* eslint key-spacing: 0 */
|
||||
/* eslint quote-props: 0 */
|
||||
|
||||
const Mime = {
|
||||
const Mime: { [id: string]: string } = {
|
||||
'eml' : 'message/rfc822',
|
||||
'mime' : 'message/rfc822',
|
||||
'txt' : 'text/plain',
|
||||
202
dev/Common/Spec.ts
Normal file
202
dev/Common/Spec.ts
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
import { Mime } from './Mime';
|
||||
import { EventKeyCode } from './Enums';
|
||||
|
||||
interface IPage {
|
||||
current: boolean,
|
||||
name: string,
|
||||
custom: boolean,
|
||||
title: string,
|
||||
value: string
|
||||
};
|
||||
|
||||
export function computedPagenatorHelper(koCurrentPage: () => number, koPageCount: () => number)
|
||||
{
|
||||
return (): IPage[] => {
|
||||
|
||||
const
|
||||
currentPage: number = koCurrentPage(),
|
||||
pageCount: number = koPageCount(),
|
||||
result: IPage[] = [],
|
||||
fAdd = (index: number, push: boolean = true, customName: string = ''): void => {
|
||||
|
||||
const data: IPage = {
|
||||
current: index === currentPage,
|
||||
name: '' === customName ? index.toString() : customName.toString(),
|
||||
custom: '' === customName ? false : true,
|
||||
title: '' === customName ? '' : index.toString(),
|
||||
value: index.toString()
|
||||
};
|
||||
|
||||
if (push)
|
||||
{
|
||||
result.push(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.unshift(data);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
let
|
||||
prev: number = 0,
|
||||
next: number = 0,
|
||||
limit: number = 2
|
||||
;
|
||||
|
||||
if (1 < pageCount || (0 < pageCount && pageCount < currentPage))
|
||||
{
|
||||
if (pageCount < currentPage)
|
||||
{
|
||||
fAdd(pageCount);
|
||||
prev = pageCount;
|
||||
next = pageCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (3 >= currentPage || pageCount - 2 <= currentPage)
|
||||
{
|
||||
limit += 2;
|
||||
}
|
||||
|
||||
fAdd(currentPage);
|
||||
prev = currentPage;
|
||||
next = currentPage;
|
||||
}
|
||||
|
||||
while (0 < limit) {
|
||||
|
||||
prev -= 1;
|
||||
next += 1;
|
||||
|
||||
if (0 < prev)
|
||||
{
|
||||
fAdd(prev, false);
|
||||
limit--;
|
||||
}
|
||||
|
||||
if (pageCount >= next)
|
||||
{
|
||||
fAdd(next, true);
|
||||
limit--;
|
||||
}
|
||||
else if (0 >= prev)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (3 === prev)
|
||||
{
|
||||
fAdd(2, false);
|
||||
}
|
||||
else if (3 < prev)
|
||||
{
|
||||
fAdd(Math.round((prev - 1) / 2), false, '...');
|
||||
}
|
||||
|
||||
if (pageCount - 2 === next)
|
||||
{
|
||||
fAdd(pageCount - 1, true);
|
||||
}
|
||||
else if (pageCount - 2 > next)
|
||||
{
|
||||
fAdd(Math.round((pageCount + next) / 2), true, '...');
|
||||
}
|
||||
|
||||
// first and last
|
||||
if (1 < prev)
|
||||
{
|
||||
fAdd(1, false);
|
||||
}
|
||||
|
||||
if (pageCount > next)
|
||||
{
|
||||
fAdd(pageCount, true);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} fileName
|
||||
* @return {string}
|
||||
*/
|
||||
export function getFileExtension(fileName: string): string
|
||||
{
|
||||
fileName = fileName.trim().toLowerCase();
|
||||
|
||||
const result = fileName.split('.').pop();
|
||||
return result === fileName ? '' : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} fileName
|
||||
* @return {string}
|
||||
*/
|
||||
export function mimeContentType(fileName: string): string
|
||||
{
|
||||
let
|
||||
ext = '',
|
||||
result = 'application/octet-stream'
|
||||
;
|
||||
|
||||
fileName = fileName.trim().toLowerCase();
|
||||
|
||||
if ('winmail.dat' === fileName)
|
||||
{
|
||||
return 'application/ms-tnef';
|
||||
}
|
||||
|
||||
ext = getFileExtension(fileName);
|
||||
if (ext && 0 < ext.length && undefined !== Mime[ext])
|
||||
{
|
||||
result = Mime[ext];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {number} value
|
||||
* @param {Function} fCallback
|
||||
*/
|
||||
export function resizeAndCrop(url: string, value: number, fCallback: (data: string) => void)
|
||||
{
|
||||
const img = new Image();
|
||||
img.onload = function() {
|
||||
|
||||
let
|
||||
diff: number[] = [0, 0]
|
||||
;
|
||||
|
||||
const
|
||||
canvas: HTMLCanvasElement = window.document.createElement('canvas'),
|
||||
ctx: CanvasRenderingContext2D = canvas.getContext('2d')
|
||||
;
|
||||
|
||||
canvas.width = value;
|
||||
canvas.height = value;
|
||||
|
||||
if (this.width > this.height)
|
||||
{
|
||||
diff = [this.width - this.height, 0];
|
||||
}
|
||||
else
|
||||
{
|
||||
diff = [0, this.height - this.width];
|
||||
}
|
||||
|
||||
ctx.fillStyle = '#fff';
|
||||
ctx.fillRect(0, 0, value, value);
|
||||
ctx.drawImage(this, diff[0] / 2, diff[1] / 2, this.width - diff[0], this.height - diff[1], 0, 0, value, value);
|
||||
|
||||
fCallback(canvas.toDataURL('image/jpeg'));
|
||||
};
|
||||
|
||||
img.src = url;
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@ import _ from '_';
|
|||
import ko from 'ko';
|
||||
import {$win, $div, dropdownVisibility, data as GlobalsData} from 'Common/Globals';
|
||||
import {ComposeType, EventKeyCode, SaveSettingsStep, FolderType} from 'Common/Enums';
|
||||
import {Mime} from 'Common/Mime';
|
||||
|
||||
import JSEncrypt from 'JSEncrypt';
|
||||
import Autolinker from 'Autolinker';
|
||||
|
|
@ -1040,45 +1039,6 @@ export function plainToHtml(plain, findEmailAndLinksInText = false)
|
|||
window.rainloop_Utils_htmlToPlain = htmlToPlain;
|
||||
window.rainloop_Utils_plainToHtml = plainToHtml;
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {number} value
|
||||
* @param {Function} fCallback
|
||||
*/
|
||||
export function resizeAndCrop(url, value, fCallback)
|
||||
{
|
||||
const img = new window.Image();
|
||||
img.onload = function() {
|
||||
|
||||
let
|
||||
diff = [0, 0],
|
||||
canvas = window.document.createElement('canvas'),
|
||||
ctx = canvas.getContext('2d')
|
||||
;
|
||||
|
||||
canvas.width = value;
|
||||
canvas.height = value;
|
||||
|
||||
if (this.width > this.height)
|
||||
{
|
||||
diff = [this.width - this.height, 0];
|
||||
}
|
||||
else
|
||||
{
|
||||
diff = [0, this.height - this.width];
|
||||
}
|
||||
|
||||
ctx.fillStyle = '#fff';
|
||||
ctx.fillRect(0, 0, value, value);
|
||||
ctx.drawImage(this, diff[0] / 2, diff[1] / 2, this.width - diff[0], this.height - diff[1], 0, 0, value, value);
|
||||
|
||||
fCallback(canvas.toDataURL('image/jpeg'));
|
||||
};
|
||||
|
||||
img.src = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array} aSystem
|
||||
* @param {Array} aList
|
||||
|
|
@ -1210,121 +1170,6 @@ export function folderListOptionsBuilder(aSystem, aList, aDisabled, aHeaderLines
|
|||
return aResult;
|
||||
}
|
||||
|
||||
export function computedPagenatorHelper(koCurrentPage, koPageCount)
|
||||
{
|
||||
return () => {
|
||||
|
||||
let
|
||||
iPrev = 0,
|
||||
iNext = 0,
|
||||
iLimit = 2,
|
||||
result = [],
|
||||
iCurrentPage = koCurrentPage(),
|
||||
iPageCount = koPageCount(),
|
||||
|
||||
/**
|
||||
* @param {number} index
|
||||
* @param {boolean=} push = true
|
||||
* @param {string=} customName = ''
|
||||
*/
|
||||
fAdd = (index, push = true, customName = '') => {
|
||||
|
||||
const data = {
|
||||
current: index === iCurrentPage,
|
||||
name: isUnd(customName) || '' === customName ? index.toString() : customName.toString(),
|
||||
custom: isUnd(customName) || '' === customName ? false : true,
|
||||
title: isUnd(customName) || '' === customName ? '' : index.toString(),
|
||||
value: index.toString()
|
||||
};
|
||||
|
||||
if (push)
|
||||
{
|
||||
result.push(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.unshift(data);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
if (1 < iPageCount || (0 < iPageCount && iPageCount < iCurrentPage))
|
||||
// if (0 < iPageCount && 0 < iCurrentPage)
|
||||
{
|
||||
if (iPageCount < iCurrentPage)
|
||||
{
|
||||
fAdd(iPageCount);
|
||||
iPrev = iPageCount;
|
||||
iNext = iPageCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (3 >= iCurrentPage || iPageCount - 2 <= iCurrentPage)
|
||||
{
|
||||
iLimit += 2;
|
||||
}
|
||||
|
||||
fAdd(iCurrentPage);
|
||||
iPrev = iCurrentPage;
|
||||
iNext = iCurrentPage;
|
||||
}
|
||||
|
||||
while (0 < iLimit) {
|
||||
|
||||
iPrev -= 1;
|
||||
iNext += 1;
|
||||
|
||||
if (0 < iPrev)
|
||||
{
|
||||
fAdd(iPrev, false);
|
||||
iLimit--;
|
||||
}
|
||||
|
||||
if (iPageCount >= iNext)
|
||||
{
|
||||
fAdd(iNext, true);
|
||||
iLimit--;
|
||||
}
|
||||
else if (0 >= iPrev)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (3 === iPrev)
|
||||
{
|
||||
fAdd(2, false);
|
||||
}
|
||||
else if (3 < iPrev)
|
||||
{
|
||||
fAdd(window.Math.round((iPrev - 1) / 2), false, '...');
|
||||
}
|
||||
|
||||
if (iPageCount - 2 === iNext)
|
||||
{
|
||||
fAdd(iPageCount - 1, true);
|
||||
}
|
||||
else if (iPageCount - 2 > iNext)
|
||||
{
|
||||
fAdd(window.Math.round((iPageCount + iNext) / 2), true, '...');
|
||||
}
|
||||
|
||||
// first and last
|
||||
if (1 < iPrev)
|
||||
{
|
||||
fAdd(1, false);
|
||||
}
|
||||
|
||||
if (iPageCount > iNext)
|
||||
{
|
||||
fAdd(iPageCount, true);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
export function selectElement(element)
|
||||
{
|
||||
let sel, range;
|
||||
|
|
@ -1369,18 +1214,6 @@ export function triggerAutocompleteInputChange(delay = false) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} fileName
|
||||
* @return {string}
|
||||
*/
|
||||
export function getFileExtension(fileName)
|
||||
{
|
||||
fileName = trim(fileName).toLowerCase();
|
||||
|
||||
const result = fileName.split('.').pop();
|
||||
return (result === fileName) ? '' : result;
|
||||
}
|
||||
|
||||
let configurationScriptTagCache = {};
|
||||
|
||||
/**
|
||||
|
|
@ -1403,33 +1236,6 @@ export function getConfigurationFromScriptTag(configuration)
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} fileName
|
||||
* @return {string}
|
||||
*/
|
||||
export function mimeContentType(fileName)
|
||||
{
|
||||
let
|
||||
ext = '',
|
||||
result = 'application/octet-stream'
|
||||
;
|
||||
|
||||
fileName = trim(fileName).toLowerCase();
|
||||
|
||||
if ('winmail.dat' === fileName)
|
||||
{
|
||||
return 'application/ms-tnef';
|
||||
}
|
||||
|
||||
ext = getFileExtension(fileName);
|
||||
if (ext && 0 < ext.length && !isUnd(Mime[ext]))
|
||||
{
|
||||
result = Mime[ext];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {mixed} mPropOrValue
|
||||
* @param {mixed} value
|
||||
|
|
@ -1575,9 +1381,9 @@ if ('ab'.substr(-1) !== 'b')
|
|||
start = start < 0 ? str.length + start : start;
|
||||
return str.substr(start, length);
|
||||
};
|
||||
}
|
||||
|
||||
export {substr};
|
||||
window.String.substr = substr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} mailToUrl
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
Enums = require('Common/Enums'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
Spec = require('Common/Spec'),
|
||||
Links = require('Common/Links'),
|
||||
Audio = require('Common/Audio'),
|
||||
|
||||
|
|
@ -102,7 +103,7 @@
|
|||
this.friendlySize = Utils.friendlySize(this.estimatedSize);
|
||||
this.cidWithOutTags = this.cid.replace(/^<+/, '').replace(/>+$/, '');
|
||||
|
||||
this.fileNameExt = Utils.getFileExtension(this.fileName);
|
||||
this.fileNameExt = Spec.getFileExtension(this.fileName);
|
||||
this.fileType = AttachmentModel.staticFileType(this.fileNameExt, this.mimeType);
|
||||
|
||||
bResult = true;
|
||||
|
|
@ -488,7 +489,7 @@
|
|||
|
||||
aTypes = _.uniq(_.compact(_.map(aData, function (aItem) {
|
||||
return aItem ? AttachmentModel.staticFileType(
|
||||
Utils.getFileExtension(aItem[0]), aItem[1]) : '';
|
||||
Spec.getFileExtension(aItem[0]), aItem[1]) : '';
|
||||
})));
|
||||
|
||||
if (aTypes && 1 === aTypes.length && aTypes[0])
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
ko = require('ko'),
|
||||
|
||||
Utils = require('Common/Utils'),
|
||||
Spec = require('Common/Spec'),
|
||||
|
||||
AttachmentModel = require('Model/Attachment'),
|
||||
|
||||
|
|
@ -67,11 +68,11 @@
|
|||
}, this);
|
||||
|
||||
this.mimeType = ko.computed(function () {
|
||||
return Utils.mimeContentType(this.fileName());
|
||||
return Spec.mimeContentType(this.fileName());
|
||||
}, this);
|
||||
|
||||
this.fileExt = ko.computed(function () {
|
||||
return Utils.getFileExtension(this.fileName());
|
||||
return Spec.getFileExtension(this.fileName());
|
||||
}, this);
|
||||
|
||||
this.regDisposables([this.progressText, this.progressStyle, this.title, this.friendlySize, this.mimeType, this.fileExt]);
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@
|
|||
break;
|
||||
case 'is:unseen,flagged':
|
||||
self.starred(true);
|
||||
/* falls through */
|
||||
case 'is:unseen':
|
||||
self.unseen(true);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
Consts = require('Common/Consts'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
Spec = require('Common/Spec'),
|
||||
Selector = require('Common/Selector'),
|
||||
Links = require('Common/Links'),
|
||||
Translator = require('Common/Translator'),
|
||||
|
|
@ -72,7 +73,7 @@
|
|||
return 0 >= iPage ? 1 : iPage;
|
||||
}, this);
|
||||
|
||||
this.contactsPagenator = ko.computed(Utils.computedPagenatorHelper(this.contactsPage, this.contactsPageCount));
|
||||
this.contactsPagenator = ko.computed(Spec.computedPagenatorHelper(this.contactsPage, this.contactsPageCount));
|
||||
|
||||
this.emptySelection = ko.observable(true);
|
||||
this.viewClearSearch = ko.observable(false);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
Consts = require('Common/Consts'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
Spec = require('Common/Spec'),
|
||||
Links = require('Common/Links'),
|
||||
Events = require('Common/Events'),
|
||||
Selector = require('Common/Selector'),
|
||||
|
|
@ -116,7 +117,7 @@
|
|||
return '' === sValue ? '' : Translator.i18n('MESSAGE_LIST/SEARCH_RESULT_FOR', {'SEARCH': sValue});
|
||||
});
|
||||
|
||||
this.messageListPagenator = ko.computed(Utils.computedPagenatorHelper(
|
||||
this.messageListPagenator = ko.computed(Spec.computedPagenatorHelper(
|
||||
MessageStore.messageListPage, MessageStore.messageListPageCount));
|
||||
|
||||
this.checkAll = ko.computed({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue