1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * Creates an IMAP account. 26 * @class 27 * This class represents an IMAP account. 28 * 29 * @param {String} id the id 30 * 31 * @extends ZmDataSource 32 */ 33 ZmImapAccount = function(id) { 34 ZmDataSource.call(this, ZmAccount.TYPE_IMAP, id); 35 }; 36 37 ZmImapAccount.prototype = new ZmDataSource; 38 ZmImapAccount.prototype.constructor = ZmImapAccount; 39 40 41 // Constants 42 /** 43 * Defines the "cleartext" port. 44 * 45 * @type int 46 */ 47 ZmImapAccount.PORT_CLEAR = 143; 48 /** 49 * Defines the "ssl" port. 50 * 51 * @type int 52 */ 53 ZmImapAccount.PORT_SSL = 993; 54 ZmImapAccount.PORT_DEFAULT = ZmImapAccount.PORT_CLEAR; 55 56 57 // advanced settings 58 ZmImapAccount.prototype.ELEMENT_NAME = "imap"; 59 ZmImapAccount.prototype.port = ZmImapAccount.PORT_DEFAULT; 60 61 62 // Public methods 63 64 ZmImapAccount.prototype.toString = 65 function() { 66 return "ZmImapAccount"; 67 }; 68 69 /** 70 * Gets the default port. 71 * 72 * @return {int} the port 73 */ 74 ZmImapAccount.prototype.getDefaultPort = 75 function() { 76 return (this.connectionType == ZmDataSource.CONNECT_SSL) 77 ? ZmImapAccount.PORT_SSL : ZmImapAccount.PORT_DEFAULT; 78 }; 79 80 /** 81 * Comparison function for *IMAP* folders. Since IMAP folderId's are *not* well- 82 * known, we have to compare their names instead of their ID's. 83 * 84 * @param {ZmFolder} folderA 85 * @param {ZmFolder} folderB 86 * @return {int} 0 if the folders are the same; 1 if "a" is before "b"; -1 if "b" is before "a" 87 */ 88 ZmImapAccount.sortCompare = 89 function(folderA, folderB) { 90 var check = ZmOrganizer.checkSortArgs(folderA, folderB); 91 if (check != null) { return check; } 92 93 var aId = ZmFolder.getIdForName(folderA.name); 94 var bId = ZmFolder.getIdForName(folderB.name); 95 96 if (ZmFolder.SORT_ORDER[aId] && ZmFolder.SORT_ORDER[bId]) { 97 return (ZmFolder.SORT_ORDER[aId] - ZmFolder.SORT_ORDER[bId]); 98 } 99 if (!ZmFolder.SORT_ORDER[aId] && ZmFolder.SORT_ORDER[bId]) { return 1; } 100 if (ZmFolder.SORT_ORDER[aId] && !ZmFolder.SORT_ORDER[bId]) { return -1; } 101 if (folderA.name.toLowerCase() > folderB.name.toLowerCase()) { return 1; } 102 if (folderA.name.toLowerCase() < folderB.name.toLowerCase()) { return -1; } 103 return 0; 104 }; 105 106