summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/news/src/nsNewsFolder.h
blob: e18a768375b24a2a3248372007042876ca540526 (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
/* -*- Mode: C++; tab-width: 2; 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/. */

/**
   Interface for representing News folders.
*/

#ifndef nsMsgNewsFolder_h__
#define nsMsgNewsFolder_h__

#include "mozilla/Attributes.h"
#include "nsMsgDBFolder.h"
#include "nsIFile.h"
#include "nsNewsUtils.h"
#include "nsMsgKeySet.h"
#include "nsIMsgNewsFolder.h"
#include "nsCOMPtr.h"
#include "nsIMsgFilterList.h"

class nsMsgNewsFolder : public nsMsgDBFolder, public nsIMsgNewsFolder {
 public:
  nsMsgNewsFolder(void);

  NS_DECL_ISUPPORTS_INHERITED
  NS_DECL_NSIMSGNEWSFOLDER

  // nsIMsgFolder methods:
  NS_IMETHOD GetSubFolders(nsTArray<RefPtr<nsIMsgFolder>>& folders) override;

  NS_IMETHOD UpdateFolder(nsIMsgWindow* aWindow) override;

  NS_IMETHOD CreateSubfolder(const nsAString& folderName,
                             nsIMsgWindow* msgWindow) override;

  NS_IMETHOD DeleteStorage() override;
  NS_IMETHOD Rename(const nsAString& newName, nsIMsgWindow* msgWindow) override;

  NS_IMETHOD GetAbbreviatedName(nsAString& aAbbreviatedName) override;

  NS_IMETHOD GetFolderURL(nsACString& url) override;

  NS_IMETHOD GetExpungedBytesCount(int64_t* count);
  NS_IMETHOD GetDeletable(bool* deletable) override;

  NS_IMETHOD RefreshSizeOnDisk();

  NS_IMETHOD GetSizeOnDisk(int64_t* size) override;

  NS_IMETHOD GetDBFolderInfoAndDB(nsIDBFolderInfo** folderInfo,
                                  nsIMsgDatabase** db) override;

  NS_IMETHOD DeleteMessages(nsTArray<RefPtr<nsIMsgDBHdr>> const& messages,
                            nsIMsgWindow* msgWindow, bool deleteStorage,
                            bool isMove, nsIMsgCopyServiceListener* listener,
                            bool allowUndo) override;
  NS_IMETHOD GetNewMessages(nsIMsgWindow* aWindow,
                            nsIUrlListener* aListener) override;

  NS_IMETHOD GetCanSubscribe(bool* aResult) override;
  NS_IMETHOD GetCanFileMessages(bool* aResult) override;
  NS_IMETHOD GetCanCreateSubfolders(bool* aResult) override;
  NS_IMETHOD GetCanRename(bool* aResult) override;
  NS_IMETHOD GetCanCompact(bool* aResult) override;
  NS_IMETHOD OnReadChanged(nsIDBChangeListener* aInstigator) override;

  NS_IMETHOD DownloadMessagesForOffline(
      nsTArray<RefPtr<nsIMsgDBHdr>> const& messages,
      nsIMsgWindow* window) override;
  NS_IMETHOD GetLocalMsgStream(nsIMsgDBHdr* hdr,
                               nsIInputStream** stream) override;
  NS_IMETHOD Compact(nsIUrlListener* aListener,
                     nsIMsgWindow* aMsgWindow) override;
  NS_IMETHOD DownloadAllForOffline(nsIUrlListener* listener,
                                   nsIMsgWindow* msgWindow) override;
  NS_IMETHOD GetSortOrder(int32_t* order) override;
  NS_IMETHOD SetSortOrder(int32_t order) override;

  NS_IMETHOD Shutdown(bool shutdownChildren) override;

  NS_IMETHOD GetFilterList(nsIMsgWindow* aMsgWindow,
                           nsIMsgFilterList** aFilterList) override;
  NS_IMETHOD GetEditableFilterList(nsIMsgWindow* aMsgWindow,
                                   nsIMsgFilterList** aFilterList) override;
  NS_IMETHOD SetFilterList(nsIMsgFilterList* aFilterList) override;
  NS_IMETHOD SetEditableFilterList(nsIMsgFilterList* aFilterList) override;
  NS_IMETHOD ApplyRetentionSettings() override;
  NS_IMETHOD GetIncomingServerType(nsACString& serverType) override;

 protected:
  virtual ~nsMsgNewsFolder();
  // helper routine to parse the URI and update member variables
  nsresult AbbreviatePrettyName(nsAString& prettyName, int32_t fullwords);
  nsresult ParseFolder(nsIFile* path);
  nsresult CreateSubFolders(nsIFile* path);
  nsresult AddDirectorySeparator(nsIFile* path);
  nsresult GetDatabase() override;
  virtual nsresult CreateChildFromURI(const nsACString& uri,
                                      nsIMsgFolder** folder) override;

  nsresult LoadNewsrcFileAndCreateNewsgroups();
  int32_t RememberLine(const nsACString& line);
  nsresult RememberUnsubscribedGroup(const nsACString& newsgroup,
                                     const nsACString& setStr);
  nsresult ForgetLine(void);
  nsresult GetNewsMessages(nsIMsgWindow* aMsgWindow, bool getOld,
                           nsIUrlListener* aListener);

  int32_t HandleNewsrcLine(const char* line, uint32_t line_size);
  virtual nsresult CreateBaseMessageURI(const nsACString& aURI) override;

 protected:
  int64_t mExpungedBytes;
  bool mGettingNews;
  bool mInitialized;
  bool m_downloadMessageForOfflineUse;

  nsCString mOptionLines;
  nsCString mUnsubscribedNewsgroupLines;
  RefPtr<nsMsgKeySet> mReadSet;

  nsCOMPtr<nsIFile> mNewsrcFilePath;

  // used for auth news
  nsCString mGroupUsername;
  nsCString mGroupPassword;

  // the name of the newsgroup.
  nsCString mRawName;
  int32_t mSortOrder;

 private:
  /**
   * Constructs a signon url for use in login manager.
   *
   * @param ref    The URI ref (should be null unless working with legacy).
   * @param result The result of the string
   */
  nsresult CreateNewsgroupUrlForSignon(const char* ref, nsAString& result);
  nsCOMPtr<nsIMsgFilterList> mFilterList;
};

#endif  // nsMsgNewsFolder_h__