Back to index

lightning-sunbird  0.9+nobinonly
nsIMAPNamespace.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _nsIMAPNamespace_H_
00039 #define _nsIMAPNamespace_H_
00040 
00041 class nsIMAPNamespace
00042 {
00043   
00044 public:
00045   nsIMAPNamespace(EIMAPNamespaceType type, const char *prefix, char delimiter, PRBool from_prefs);
00046   
00047   ~nsIMAPNamespace();
00048   
00049   EIMAPNamespaceType    GetType() { return m_namespaceType; }
00050   const char *          GetPrefix() { return m_prefix; }
00051   char                  GetDelimiter() { return m_delimiter; }
00052   void                  SetDelimiter(char delimiter, PRBool delimiterFilledIn);
00053   PRBool                GetIsDelimiterFilledIn() { return m_delimiterFilledIn; }
00054   PRBool                GetIsNamespaceFromPrefs() { return m_fromPrefs; }
00055   
00056   // returns -1 if this box is not part of this namespace,
00057   // or the length of the prefix if it is part of this namespace
00058   int                   MailboxMatchesNamespace(const char *boxname);
00059   
00060 protected:
00061   EIMAPNamespaceType m_namespaceType;
00062   char    *m_prefix;
00063   char    m_delimiter;
00064   PRBool  m_fromPrefs;
00065   PRBool  m_delimiterFilledIn;
00066   
00067 };
00068 
00069 
00070 // represents an array of namespaces for a given host
00071 class nsIMAPNamespaceList
00072 {
00073 public:
00074   ~nsIMAPNamespaceList();
00075   
00076   static nsIMAPNamespaceList *CreatensIMAPNamespaceList();
00077   
00078   nsresult InitFromString(const char *nameSpaceString, EIMAPNamespaceType nstype);
00079   nsresult OutputToString(nsCString &OutputString);
00080   int UnserializeNamespaces(const char *str, char **prefixes, int len);
00081   nsresult SerializeNamespaces(char **prefixes, int len, nsCString &serializedNamespace);
00082   
00083   void ClearNamespaces(PRBool deleteFromPrefsNamespaces, PRBool deleteServerAdvertisedNamespaces, PRBool reallyDelete);
00084   int  GetNumberOfNamespaces();
00085   int  GetNumberOfNamespaces(EIMAPNamespaceType);
00086   nsIMAPNamespace *GetNamespaceNumber(int nodeIndex);
00087   nsIMAPNamespace *GetNamespaceNumber(int nodeIndex, EIMAPNamespaceType);
00088   
00089   nsIMAPNamespace *GetDefaultNamespaceOfType(EIMAPNamespaceType type);
00090   int AddNewNamespace(nsIMAPNamespace *ns);
00091   nsIMAPNamespace *GetNamespaceForMailbox(const char *boxname);
00092   static nsIMAPNamespace* GetNamespaceForFolder(const char *hostName,
00093                                            const char *canonicalFolderName,
00094                                            char delimiter);
00095   static PRBool GetFolderIsNamespace(const char *hostName,
00096                               const char *canonicalFolderName,
00097                               char delimiter,nsIMAPNamespace *namespaceForFolder);
00098   static char* GetFolderNameWithoutNamespace(nsIMAPNamespace *namespaceForFolder, const char *canonicalFolderName);
00099   static char *AllocateServerFolderName(const char *canonicalFolderName, char delimiter);
00100   static char *GetFolderOwnerNameFromPath(nsIMAPNamespace *namespaceForFolder, const char *canonicalFolderName);
00101   static char *AllocateCanonicalFolderName(const char *onlineFolderName, char delimiter);
00102   static void  SuggestHierarchySeparatorForNamespace(nsIMAPNamespace *namespaceForFolder, char delimiterFromFolder);
00103   static char *GenerateFullFolderNameWithDefaultNamespace(const char *hostName,
00104                                                                                 const char *canonicalFolderName,
00105                                                                                 const char *owner,
00106                                                                                 EIMAPNamespaceType nsType,
00107                                                                                 nsIMAPNamespace **nsUsed);
00108 
00109 protected:
00110   nsIMAPNamespaceList();    // use CreatensIMAPNamespaceList to create one
00111   
00112   nsVoidArray m_NamespaceList;
00113   
00114 };
00115 
00116 
00117 #endif