1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2007, 2009, 2010, 2011, 2012, 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, 2011, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 /**
 25  * @overview
 26  * 
 27  * This file defines the account base class.
 28  *
 29  */
 30 
 31 /**
 32  * Creates the account.
 33  * @class
 34  * This class represents an account.
 35  * 
 36  * @param	{constant}	type	the account type (see <code>ZmAccount.TYPE_</code> constants)
 37  * @param	{String}	id		the account id
 38  * @param	{String}	name	the account name
 39  * @see		ZmAccount
 40  */
 41 ZmAccount = function(type, id, name) {
 42 	if (arguments.length == 0) { return; }
 43 
 44 	this.id = id;
 45 	this.name = name;
 46 	this.type = type || ZmAccount.TYPE_ZIMBRA;
 47 };
 48 
 49 
 50 //
 51 // Consts
 52 //
 53 
 54 /**
 55  * Defines the "AOL" account type.
 56  */
 57 ZmAccount.TYPE_AOL		= "AOL";
 58 /**
 59  * Defines the "Gmail" account type.
 60  */
 61 ZmAccount.TYPE_GMAIL	= "Gmail";
 62 /**
 63  * Defines the "IMAP" account type.
 64  */
 65 ZmAccount.TYPE_IMAP		= "Imap";
 66 /**
 67  * Defines the "Microsoft Live" or "Hotmail" account type.
 68  */
 69 ZmAccount.TYPE_LIVE		= "Live";   // MS Live / hotmail
 70 /**
 71  * Defines the "Microsoft Exchange IMAP" account type.
 72  */
 73 ZmAccount.TYPE_MSE		= "MSE";    // exchange IMAP
 74 /**
 75  * Defines the "Microsoft Exchange Mobile Sync" account type.
 76  */
 77 ZmAccount.TYPE_EXCHANGE = "Xsync";  // exchange (using mobile sync protocol)
 78 /**
 79  * Defines the "persona" account type.
 80  */
 81 ZmAccount.TYPE_PERSONA	= "PERSONA";
 82 /**
 83  * Defines the "POP" account type.
 84  */
 85 ZmAccount.TYPE_POP		= "Pop";
 86 /**
 87  * Defines the "Y! Mail" account type.
 88  */
 89 ZmAccount.TYPE_YMP		= "YMP";    // Y! mail
 90 /**
 91  * Defines the "Zimbra" account type.
 92  */
 93 ZmAccount.TYPE_ZIMBRA	= "Zimbra";
 94 /**
 95  * Defines the "Zimbra" account type.
 96  */
 97 ZmAccount.TYPE_CALDAV	= "CalDAV";
 98 
 99 
100 ZmAccount.LOCAL_ACCOUNT_ID = "ffffffff-ffff-ffff-ffff-ffffffffffff";
101 
102 
103 //
104 // Public static methods
105 //
106 
107 /**
108  * Gets the name of the specified type.
109  * 
110  * @param	{constant}	type		the type (see <code>ZmAccount.TYPE_</code> constants)
111  * @return	{String}	the name or unknown
112  * 
113  * @see		ZmAccount
114  */
115 ZmAccount.getTypeName =
116 function(type) {
117 	switch (type) {
118 		case ZmAccount.TYPE_AOL:		return ZmMsg.aol;
119 		case ZmAccount.TYPE_GMAIL:		return ZmMsg.gmail;
120 		case ZmAccount.TYPE_IMAP:		return ZmMsg.accountTypeImap;
121 		case ZmAccount.TYPE_LIVE:		return ZmMsg.msLive;
122 		case ZmAccount.TYPE_MSE:		return ZmMsg.msExchange;
123 		case ZmAccount.TYPE_EXCHANGE:	return ZmMsg.msExchange;
124 		case ZmAccount.TYPE_PERSONA:	return ZmMsg.accountTypePersona;
125 		case ZmAccount.TYPE_POP:		return ZmMsg.accountTypePop;
126 		case ZmAccount.TYPE_YMP:		return ZmMsg.yahooMail;
127 		case ZmAccount.TYPE_ZIMBRA:		return ZmMsg.zimbraTitle;
128 	}
129 	return ZmMsg.unknown;
130 };
131 
132 
133 //
134 // Public methods
135 //
136 
137 /**
138  * Returns a string representation of the object.
139  * 
140  * @return		{String}		a string representation of the object
141  */
142 ZmAccount.prototype.toString =
143 function() {
144 	return "ZmAccount";
145 };
146 
147 /**
148  * Sets the name of the account.
149  * 
150  * @param		{String}	name		the account name
151  */
152 ZmAccount.prototype.setName =
153 function(name) {
154 	this.name = name;
155 };
156 
157 /**
158  * Gets the name of the account.
159  * 
160  * @return		{String}		the account name
161  */
162 ZmAccount.prototype.getName =
163 function() {
164 	return this.name;
165 };
166 
167 // sub-classes MUST override these methods
168 
169 /**
170  * Sets the email address for this account. Subclasses should override this method.
171  * 
172  * @param	{String}	email 	the email address
173  */
174 ZmAccount.prototype.setEmail =
175 function(email) {
176 	throw this.toString()+"#setEmail";
177 };
178 
179 /**
180  * Gets the email address for this account. Subclasses should override this method.
181  * 
182  * @return	{String}	the email address
183  */
184 ZmAccount.prototype.getEmail =
185 function() {
186 	throw this.toString()+"#getEmail";
187 };
188 
189 /**
190  * Gets the identity for this account. Subclasses should override this method.
191  * 
192  * @return	{String}	the identity
193  */
194 ZmAccount.prototype.getIdentity =
195 function() {
196 	throw this.toString()+"#getIdentity";
197 };
198 
199 ZmAccount.prototype.isLocal =
200 function() {
201 	return this.id == ZmAccount.LOCAL_ACCOUNT_ID;
202 };
203