summaryrefslogtreecommitdiffstats
path: root/mailnews/imap/src/nsIMAPNamespace.h
blob: 327f78416a95abde6ad60dac06e62e96f4bff361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef _nsIMAPNamespace_H_
#define _nsIMAPNamespace_H_

#include "nsTArray.h"

class nsIMAPNamespace
{
  
public:
  nsIMAPNamespace(EIMAPNamespaceType type, const char *prefix, char delimiter, bool from_prefs);
  
  ~nsIMAPNamespace();
  
  EIMAPNamespaceType    GetType() { return m_namespaceType; }
  const char *          GetPrefix() { return m_prefix; }
  char                  GetDelimiter() { return m_delimiter; }
  void                  SetDelimiter(char delimiter, bool delimiterFilledIn);
  bool                  GetIsDelimiterFilledIn() { return m_delimiterFilledIn; }
  bool                  GetIsNamespaceFromPrefs() { return m_fromPrefs; }
  
  // returns -1 if this box is not part of this namespace,
  // or the length of the prefix if it is part of this namespace
  int                   MailboxMatchesNamespace(const char *boxname);
  
protected:
  EIMAPNamespaceType m_namespaceType;
  char    *m_prefix;
  char    m_delimiter;
  bool    m_fromPrefs;
  bool    m_delimiterFilledIn;
  
};


// represents an array of namespaces for a given host
class nsIMAPNamespaceList
{
public:
  ~nsIMAPNamespaceList();
  
  static nsIMAPNamespaceList *CreatensIMAPNamespaceList();
  
  nsresult InitFromString(const char *nameSpaceString, EIMAPNamespaceType nstype);
  nsresult OutputToString(nsCString &OutputString);
  int UnserializeNamespaces(const char *str, char **prefixes, int len);
  nsresult SerializeNamespaces(char **prefixes, int len, nsCString &serializedNamespace);
  
  void ClearNamespaces(bool deleteFromPrefsNamespaces, bool deleteServerAdvertisedNamespaces, bool reallyDelete);
  int	GetNumberOfNamespaces();
  int	GetNumberOfNamespaces(EIMAPNamespaceType);
  nsIMAPNamespace *GetNamespaceNumber(int nodeIndex);
  nsIMAPNamespace *GetNamespaceNumber(int nodeIndex, EIMAPNamespaceType);
  
  nsIMAPNamespace *GetDefaultNamespaceOfType(EIMAPNamespaceType type);
  int AddNewNamespace(nsIMAPNamespace *ns);
  nsIMAPNamespace *GetNamespaceForMailbox(const char *boxname);
  static nsIMAPNamespace* GetNamespaceForFolder(const char *hostName,
                                           const char *canonicalFolderName,
                                           char delimiter);
  static bool GetFolderIsNamespace(const char *hostName,
                              const char *canonicalFolderName,
                              char delimiter,nsIMAPNamespace *namespaceForFolder);
  static char* GetFolderNameWithoutNamespace(nsIMAPNamespace *namespaceForFolder, const char *canonicalFolderName);
  static char *AllocateServerFolderName(const char *canonicalFolderName, char delimiter);
  static char *GetFolderOwnerNameFromPath(nsIMAPNamespace *namespaceForFolder, const char *canonicalFolderName);
  static char *AllocateCanonicalFolderName(const char *onlineFolderName, char delimiter);
  static void  SuggestHierarchySeparatorForNamespace(nsIMAPNamespace *namespaceForFolder, char delimiterFromFolder);
  static char *GenerateFullFolderNameWithDefaultNamespace(const char *hostName,
                                                                                const char *canonicalFolderName,
                                                                                const char *owner,
                                                                                EIMAPNamespaceType nsType,
                                                                                nsIMAPNamespace **nsUsed);

protected:
  nsIMAPNamespaceList();	// use CreatensIMAPNamespaceList to create one
  
  nsTArray<nsIMAPNamespace*> m_NamespaceList;
  
};


#endif