summaryrefslogtreecommitdiffstats
path: root/mailnews/compose/src/nsMsgSendLater.h
blob: 7b6cdf8f73323e8c0a3ddf3962a0d046a1d9951a (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/. */

#ifndef _nsMsgSendLater_H_
#define _nsMsgSendLater_H_

#include "nsCOMArray.h"
#include "nsIMsgFolder.h"
#include "nsIMsgSendListener.h"
#include "nsIMsgSendLaterListener.h"
#include "nsIMsgSendLater.h"
#include "nsIMsgStatusFeedback.h"
#include "nsTObserverArray.h"
#include "nsIObserver.h"
#include "nsITimer.h"
#include "nsIMsgShutdown.h"

////////////////////////////////////////////////////////////////////////////////////
// This is the listener class for the send operation. We have to create this class 
// to listen for message send completion and eventually notify the caller
////////////////////////////////////////////////////////////////////////////////////
class nsMsgSendLater;

class SendOperationListener : public nsIMsgSendListener,
                              public nsIMsgCopyServiceListener
{
public:
  explicit SendOperationListener(nsMsgSendLater *aSendLater);

  NS_DECL_ISUPPORTS
  NS_DECL_NSIMSGSENDLISTENER
  NS_DECL_NSIMSGCOPYSERVICELISTENER

private:
  virtual ~SendOperationListener();
  nsMsgSendLater *mSendLater;
};

class nsMsgSendLater: public nsIMsgSendLater,
                      public nsIFolderListener,
                      public nsIObserver,
                      public nsIUrlListener,
                      public nsIMsgShutdownTask

{
public:
  nsMsgSendLater();
  nsresult Init();

  NS_DECL_ISUPPORTS
  NS_DECL_NSIMSGSENDLATER
  NS_DECL_NSIFOLDERLISTENER
  NS_DECL_NSISTREAMLISTENER
  NS_DECL_NSIREQUESTOBSERVER
  NS_DECL_NSIOBSERVER
  NS_DECL_NSIURLLISTENER
  NS_DECL_NSIMSGSHUTDOWNTASK

  // Methods needed for implementing interface...
  nsresult                  StartNextMailFileSend(nsresult prevStatus);
  nsresult                  CompleteMailFileSend();

  nsresult                  DeleteCurrentMessage();
  nsresult                  SetOrigMsgDisposition();
  // Necessary for creating a valid list of recipients
  nsresult                  BuildHeaders();
  nsresult                  DeliverQueuedLine(char *line, int32_t length);
  nsresult                  RebufferLeftovers(char *startBuf,  uint32_t aLen);
  nsresult                  BuildNewBuffer(const char* aBuf, uint32_t aCount, uint32_t *totalBufSize);

  // methods for listener array processing...
  void NotifyListenersOnStartSending(uint32_t aTotalMessageCount);
  void NotifyListenersOnMessageStartSending(uint32_t aCurrentMessage,
                                            uint32_t aTotalMessage,
                                            nsIMsgIdentity *aIdentity);
  void NotifyListenersOnProgress(uint32_t aCurrentMessage,
                                 uint32_t aTotalMessage,
                                 uint32_t aSendPercent,
                                 uint32_t aCopyPercent);
  void NotifyListenersOnMessageSendError(uint32_t aCurrentMessage,
                                         nsresult aStatus,
                                         const char16_t *aMsg);
  void EndSendMessages(nsresult aStatus, const char16_t *aMsg, 
                       uint32_t aTotalTried, uint32_t aSuccessful);

  bool OnSendStepFinished(nsresult aStatus);
  void OnCopyStepFinished(nsresult aStatus);

  // counters and things for enumeration 
  uint32_t                  mTotalSentSuccessfully;
  uint32_t                  mTotalSendCount;
  nsCOMArray<nsIMsgDBHdr> mMessagesToSend;
  nsCOMPtr<nsISimpleEnumerator> mEnumerator;
  nsCOMPtr<nsIMsgFolder>    mMessageFolder;
  nsCOMPtr<nsIMsgStatusFeedback> mFeedback;
 
  // Private Information
private:
  virtual ~nsMsgSendLater();
  nsresult GetIdentityFromKey(const char *aKey, nsIMsgIdentity **aIdentity);
  nsresult ReparseDBIfNeeded(nsIUrlListener *aListener);
  nsresult InternalSendMessages(bool aUserInitiated,
                                nsIMsgIdentity *aIdentity);

  nsTObserverArray<nsCOMPtr<nsIMsgSendLaterListener> > mListenerArray;
  nsCOMPtr<nsIMsgDBHdr> mMessage;
  nsCOMPtr<nsITimer> mTimer;
  bool mTimerSet;
  nsCOMPtr<nsIUrlListener> mShutdownListener;

  //
  // File output stuff...
  //
  nsCOMPtr<nsIFile>         mTempFile;
  nsCOMPtr<nsIOutputStream> mOutFile;

  // For building headers and stream parsing...
  char                      *m_to;
  char                      *m_bcc;
  char                      *m_fcc;
  char                      *m_newsgroups;
  char                      *m_newshost;
  char                      *m_headers;
  int32_t                   m_flags;
  int32_t                   m_headersFP;
  bool                      m_inhead;
  int32_t                   m_headersPosition;
  int32_t                   m_bytesRead;
  int32_t                   m_position;
  int32_t                   m_flagsPosition;
  int32_t                   m_headersSize;
  char                      *mLeftoverBuffer;
  char                      *mIdentityKey;
  char                      *mAccountKey;

  bool mSendingMessages;
  bool mUserInitiated;
  nsCOMPtr<nsIMsgIdentity> mIdentity;
};


#endif /* _nsMsgSendLater_H_ */