summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/imap/src/nsImapNamespace.h
blob: 5d11d731208bcd0053c7cdcb67431c234aaab85e (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 "nsImapCore.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 nsCString GetFolderOwnerNameFromPath(
      nsImapNamespace* namespaceForFolder, const char* canonicalFolderName);
  static void SuggestHierarchySeparatorForNamespace(
      nsImapNamespace* namespaceForFolder, char delimiterFromFolder);
  static nsCString GenerateFullFolderNameWithDefaultNamespace(
      const char* hostName, const char* canonicalFolderName, const char* owner,
      EIMAPNamespaceType nsType, nsImapNamespace** nsUsed);

 protected:
  static char* AllocateServerFolderName(const char* canonicalFolderName,
                                        char delimiter);
  static nsCString AllocateCanonicalFolderName(const char* onlineFolderName,
                                               char delimiter);
  nsImapNamespaceList();  // use CreatensImapNamespaceList to create one

  nsTArray<nsImapNamespace*> m_NamespaceList;
};
#endif