summaryrefslogtreecommitdiff
path: root/mailnews/imap/src/nsImapUrl.h
blob: d1925d87a6fd7c68d8e22d12b242c571cf162ce4 (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
/* -*- 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 nsImapUrl_h___
#define nsImapUrl_h___

#include "mozilla/Attributes.h"
#include "nsIImapUrl.h"
#include "nsIImapMockChannel.h"
#include "nsCOMPtr.h"
#include "nsMsgMailNewsUrl.h"
#include "nsIMsgIncomingServer.h"
#include "nsIImapMailFolderSink.h"
#include "nsIImapServerSink.h"
#include "nsIImapMessageSink.h"

#include "nsWeakPtr.h"
#include "nsIFile.h"
#include "mozilla/Mutex.h"

class nsImapUrl : public nsIImapUrl, public nsMsgMailNewsUrl, public nsIMsgMessageUrl, public nsIMsgI18NUrl
{
public:

  NS_DECL_ISUPPORTS_INHERITED

  // nsIURI override
  NS_IMETHOD SetSpec(const nsACString &aSpec) override;
  NS_IMETHOD SetQuery(const nsACString &aQuery) override;
  NS_IMETHOD CloneInternal(uint32_t aRefHandlingMode,
                           const nsACString& newRef, nsIURI **_retval) override;

  //////////////////////////////////////////////////////////////////////////////
  // we support the nsIImapUrl interface
  //////////////////////////////////////////////////////////////////////////////
  NS_DECL_NSIIMAPURL

  // nsIMsgMailNewsUrl overrides
  NS_IMETHOD IsUrlType(uint32_t type, bool *isType) override;
  NS_IMETHOD GetFolder(nsIMsgFolder **aFolder) override;
  NS_IMETHOD SetFolder(nsIMsgFolder *aFolder) override;
  // nsIMsgMessageUrl
  NS_DECL_NSIMSGMESSAGEURL
  NS_DECL_NSIMSGI18NURL

  // nsImapUrl
  nsImapUrl();

  static nsresult ConvertToCanonicalFormat(const char *folderName, char onlineDelimiter, char **resultingCanonicalPath);
  static nsresult EscapeSlashes(const char *sourcePath, char **resultPath);
  static nsresult UnescapeSlashes(char *path);
  static char *  ReplaceCharsInCopiedString(const char *stringToCopy, char oldChar, char newChar);

protected:
  virtual ~nsImapUrl();
  virtual nsresult ParseUrl();

  char *m_listOfMessageIds;

  // handle the imap specific parsing
  void ParseImapPart(char *imapPartOfUrl);

  void ParseFolderPath(char **resultingCanonicalPath);
  void ParseSearchCriteriaString();
  void ParseUidChoice();
  void ParseMsgFlags();
  void ParseListOfMessageIds();
  void ParseCustomMsgFetchAttribute();
  void ParseNumBytes();

  nsresult GetMsgFolder(nsIMsgFolder **msgFolder);

  char        *m_sourceCanonicalFolderPathSubString;
  char        *m_destinationCanonicalFolderPathSubString;
  char        *m_tokenPlaceHolder;
  char        *m_urlidSubString;
  char        m_onlineSubDirSeparator;
  char        *m_searchCriteriaString;  // should we use m_search, or is this special?
  nsCString     m_command;       // for custom commands
  nsCString     m_msgFetchAttribute; // for fetching custom msg attributes
  nsCString     m_customAttributeResult; // for fetching custom msg attributes
  nsCString     m_customCommandResult; // custom command response
  nsCString     m_customAddFlags;       // these two are for setting and clearing custom flags
  nsCString     m_customSubtractFlags;
  int32_t       m_numBytesToFetch; // when doing a msg body preview, how many bytes to read
  bool m_validUrl;
  bool m_runningUrl;
  bool m_idsAreUids;
  bool m_mimePartSelectorDetected;
  bool m_allowContentChange;  // if false, we can't use Mime parts on demand
  bool m_fetchPartsOnDemand; // if true, we should fetch leave parts on server.
  bool m_msgLoadingFromCache; // if true, we might need to mark read on server
  bool m_externalLinkUrl; // if true, we're running this url because the user
  // True if the fetch results should be put in the offline store.
  bool m_storeResultsOffline;
  bool m_storeOfflineOnFallback;
  bool m_localFetchOnly;
  bool m_rerunningUrl; // first attempt running this failed with connection error; retrying
  bool m_moreHeadersToDownload;
  nsImapContentModifiedType  m_contentModified;

  int32_t    m_extraStatus;

  nsCString  m_userName;
  nsCString  m_serverKey;
  // event sinks
  imapMessageFlagsType  m_flags;
  nsImapAction  m_imapAction;

  nsWeakPtr m_imapFolder;
  nsWeakPtr m_imapMailFolderSink;
  nsWeakPtr m_imapMessageSink;

  nsWeakPtr m_imapServerSink;

  // online message copy support; i don't have a better solution yet
  nsCOMPtr <nsISupports> m_copyState;   // now, refcounted.
  nsCOMPtr<nsIFile> m_file;
  nsWeakPtr m_channelWeakPtr;

  // used by save message to disk
  nsCOMPtr<nsIFile> m_messageFile;
  bool                  m_addDummyEnvelope;
  bool                  m_canonicalLineEnding; // CRLF

  nsCString mURI; // the RDF URI associated with this url.
  nsCString mCharsetOverride; // used by nsIMsgI18NUrl...
  mozilla::Mutex mLock;
};

#endif /* nsImapUrl_h___ */