summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/imap/src/nsImapHostSessionList.h
blob: 325cbae8687b41ee964160b67f5d19696cf36e7d (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* -*- 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 _nsImapHostSessionList_H_
#define _nsImapHostSessionList_H_

#include "mozilla/Attributes.h"
#include "nsImapCore.h"
#include "../public/nsIImapHostSessionList.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "nspr.h"

class nsImapNamespaceList;
class nsIImapIncomingServer;

class nsIMAPHostInfo {
 public:
  friend class nsImapHostSessionList;

  nsIMAPHostInfo(const char* serverKey, nsIImapIncomingServer* server);
  ~nsIMAPHostInfo();

 protected:
  nsCString fServerKey;
  nsString fCachedPassword;
  nsCString fOnlineDir;
  nsIMAPHostInfo* fNextHost;
  eIMAPCapabilityFlags fCapabilityFlags;
  char* fHierarchyDelimiters;  // string of top-level hierarchy delimiters
  bool fHaveWeEverDiscoveredFolders;
  bool fDiscoveryForHostInProgress;
  char* fCanonicalOnlineSubDir;
  nsImapNamespaceList *fNamespaceList, *fTempNamespaceList;
  bool fNamespacesOverridable;
  bool fUsingSubscription;
  bool fOnlineTrashFolderExists;
  bool fShouldAlwaysListInbox;
  bool fHaveAdminURL;
  bool fPasswordVerifiedOnline;
  bool fDeleteIsMoveToTrash;
  bool fShowDeletedMessages;
  bool fGotNamespaces;
};

// this is an interface to a linked list of host info's
class nsImapHostSessionList : public nsIImapHostSessionList,
                              public nsIObserver,
                              public nsSupportsWeakReference {
 public:
  NS_DECL_THREADSAFE_ISUPPORTS
  NS_DECL_NSIOBSERVER

  nsImapHostSessionList();
  nsresult Init();
  // Host List
  NS_IMETHOD AddHostToList(const char* serverKey,
                           nsIImapIncomingServer* server) override;
  NS_IMETHOD ResetAll() override;

  // Capabilities
  NS_IMETHOD GetHostHasAdminURL(const char* serverKey, bool& result) override;
  NS_IMETHOD SetHostHasAdminURL(const char* serverKey,
                                bool hasAdminUrl) override;
  // Subscription
  NS_IMETHOD GetHostIsUsingSubscription(const char* serverKey,
                                        bool& result) override;
  NS_IMETHOD SetHostIsUsingSubscription(const char* serverKey,
                                        bool usingSubscription) override;

  // Passwords
  NS_IMETHOD GetPasswordForHost(const char* serverKey,
                                nsString& result) override;
  NS_IMETHOD SetPasswordForHost(const char* serverKey,
                                const nsAString& password) override;
  NS_IMETHOD GetPasswordVerifiedOnline(const char* serverKey,
                                       bool& result) override;
  NS_IMETHOD SetPasswordVerifiedOnline(const char* serverKey) override;

  // OnlineDir
  NS_IMETHOD GetOnlineDirForHost(const char* serverKey,
                                 nsString& result) override;
  NS_IMETHOD SetOnlineDirForHost(const char* serverKey,
                                 const char* onlineDir) override;

  // Delete is move to trash folder
  NS_IMETHOD GetDeleteIsMoveToTrashForHost(const char* serverKey,
                                           bool& result) override;
  NS_IMETHOD SetDeleteIsMoveToTrashForHost(const char* serverKey,
                                           bool isMoveToTrash) override;
  // imap delete model (or not)
  NS_IMETHOD GetShowDeletedMessagesForHost(const char* serverKey,
                                           bool& result) override;
  NS_IMETHOD SetShowDeletedMessagesForHost(const char* serverKey,
                                           bool showDeletedMessages) override;

  // Get namespaces
  NS_IMETHOD GetGotNamespacesForHost(const char* serverKey,
                                     bool& result) override;
  NS_IMETHOD SetGotNamespacesForHost(const char* serverKey,
                                     bool gotNamespaces) override;
  // Folders
  NS_IMETHOD SetHaveWeEverDiscoveredFoldersForHost(const char* serverKey,
                                                   bool discovered) override;
  NS_IMETHOD GetHaveWeEverDiscoveredFoldersForHost(const char* serverKey,
                                                   bool& result) override;
  NS_IMETHOD SetDiscoveryForHostInProgress(const char* serverKey,
                                           bool inProgress) override;
  NS_IMETHOD GetDiscoveryForHostInProgress(const char* serverKey,
                                           bool& result) override;

  // Trash Folder
  NS_IMETHOD SetOnlineTrashFolderExistsForHost(const char* serverKey,
                                               bool exists) override;
  NS_IMETHOD GetOnlineTrashFolderExistsForHost(const char* serverKey,
                                               bool& result) override;

  // INBOX
  NS_IMETHOD GetOnlineInboxPathForHost(const char* serverKey,
                                       nsString& result) override;
  NS_IMETHOD GetShouldAlwaysListInboxForHost(const char* serverKey,
                                             bool& result) override;
  NS_IMETHOD SetShouldAlwaysListInboxForHost(const char* serverKey,
                                             bool shouldList) override;

  // Namespaces
  NS_IMETHOD GetNamespaceForMailboxForHost(const char* serverKey,
                                           const char* mailbox_name,
                                           nsImapNamespace*& result) override;
  NS_IMETHOD SetNamespaceFromPrefForHost(const char* serverKey,
                                         const char* namespacePref,
                                         EIMAPNamespaceType type) override;
  NS_IMETHOD AddNewNamespaceForHost(const char* serverKey,
                                    nsImapNamespace* ns) override;
  NS_IMETHOD ClearServerAdvertisedNamespacesForHost(
      const char* serverKey) override;
  NS_IMETHOD ClearPrefsNamespacesForHost(const char* serverKey) override;
  NS_IMETHOD GetDefaultNamespaceOfTypeForHost(
      const char* serverKey, EIMAPNamespaceType type,
      nsImapNamespace*& result) override;
  NS_IMETHOD SetNamespacesOverridableForHost(const char* serverKey,
                                             bool overridable) override;
  NS_IMETHOD GetNamespacesOverridableForHost(const char* serverKey,
                                             bool& result) override;
  NS_IMETHOD GetNumberOfNamespacesForHost(const char* serverKey,
                                          uint32_t& result) override;
  NS_IMETHOD GetNamespaceNumberForHost(const char* serverKey, int32_t n,
                                       nsImapNamespace*& result) override;
  // ### dmb hoo boy, how are we going to do this?
  NS_IMETHOD CommitNamespacesForHost(nsIImapIncomingServer* host) override;
  NS_IMETHOD FlushUncommittedNamespacesForHost(const char* serverKey,
                                               bool& result) override;

  // Hierarchy Delimiters
  NS_IMETHOD SetNamespaceHierarchyDelimiterFromMailboxForHost(
      const char* serverKey, const char* boxName, char delimiter) override;

  PRMonitor* gCachedHostInfoMonitor;
  nsIMAPHostInfo* fHostInfoList;

 protected:
  virtual ~nsImapHostSessionList();
  nsresult SetNamespacesPrefForHost(nsIImapIncomingServer* aHost,
                                    EIMAPNamespaceType type, const char* pref);
  nsIMAPHostInfo* FindHost(const char* serverKey);
};
#endif