summaryrefslogtreecommitdiffstats
path: root/mailnews/mime/emitters/nsMimeBaseEmitter.h
blob: c33bc26875d2fb13e1403d039099222940d19ad9 (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
/* -*- 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 _nsMimeBaseEmitter_h_
#define _nsMimeBaseEmitter_h_

#include "prio.h"
#include "nsIMimeEmitter.h"
#include "nsMimeRebuffer.h"
#include "nsIStreamListener.h"
#include "nsIInputStream.h"
#include "nsIOutputStream.h"
#include "nsIAsyncInputStream.h"
#include "nsIURI.h"
#include "nsIChannel.h"
#include "nsIMimeMiscStatus.h"
#include "nsIPipe.h"
#include "nsIStringBundle.h"
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "nsIMimeConverter.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIDateTimeFormat.h"

//
// The base emitter will serve as the place to do all of the caching,
// sorting, etc... of mail headers and bodies for this internally developed
// emitter library. The other emitter classes in this file (nsMimeHTMLEmitter, etc.)
// will only be concerned with doing output processing ONLY.
//

//
// Used for keeping track of the attachment information...
//
typedef struct {
  char      *displayName;
  char      *urlSpec;
  char      *contentType;
  bool      isExternalAttachment;
} attachmentInfoType;

//
// For header info...
//
typedef struct {
  char      *name;
  char      *value;
} headerInfoType;

class nsMimeBaseEmitter : public nsIMimeEmitter,
                          public nsIInterfaceRequestor
{
public:
  nsMimeBaseEmitter ();

  // nsISupports interface
  NS_DECL_THREADSAFE_ISUPPORTS

  NS_DECL_NSIMIMEEMITTER
  NS_DECL_NSIINTERFACEREQUESTOR

  // Utility output functions...
  NS_IMETHOD          UtilityWrite(const nsACString &buf);
  NS_IMETHOD          UtilityWriteCRLF(const char *buf);

  // For string bundle usage...
  char                *MimeGetStringByName(const char *aHeaderName);
  char                *MimeGetStringByID(int32_t aID);
  char                *LocalizeHeaderName(const char *aHeaderName, const char *aDefaultName);

  // For header processing...
  const char          *GetHeaderValue(const char  *aHeaderName);

  // To write out a stored header array as HTML
  virtual nsresult            WriteHeaderFieldHTMLPrefix(const nsACString &name);
  virtual nsresult            WriteHeaderFieldHTML(const char *field, const char *value);
  virtual nsresult            WriteHeaderFieldHTMLPostfix();

protected:
  virtual ~nsMimeBaseEmitter();
  // Internal methods...
  void                CleanupHeaderArray(nsTArray<headerInfoType*> *aArray);

  // For header output...
  nsresult            DumpSubjectFromDate();
  nsresult            DumpToCC();
  nsresult            DumpRestOfHeaders();
  nsresult            OutputGenericHeader(const char *aHeaderVal);

  nsresult            WriteHelper(const nsACString &buf, uint32_t *countWritten);

  // For string bundle usage...
  nsCOMPtr<nsIStringBundle>  m_stringBundle;        // for translated strings
  nsCOMPtr<nsIStringBundle>  m_headerStringBundle;  // for non-translated header strings

  // For buffer management on output
  MimeRebuffer        *mBufferMgr;

  // mscott
  // don't ref count the streams....the emitter is owned by the converter
  // which owns these streams...
  //
  nsIOutputStream     *mOutStream;
  nsIInputStream      *mInputStream;
  nsIStreamListener   *mOutListener;
  nsCOMPtr<nsIChannel> mChannel;

  // For gathering statistics on processing...
  uint32_t            mTotalWritten;
  uint32_t            mTotalRead;

  // Output control and info...
  bool                mDocHeader;         // For header determination...
  nsIURI              *mURL;              // the url for the data being processed...
  int32_t             mHeaderDisplayType; // The setting for header output...
  nsCString           mHTMLHeaders;       // HTML Header Data...

  // For attachment processing...
  int32_t             mAttachCount;
  nsTArray<attachmentInfoType*>  *mAttachArray;
  attachmentInfoType  *mCurrentAttachment;

  // For header caching...
  nsTArray<headerInfoType*>  *mHeaderArray;
  nsTArray<headerInfoType*>  *mEmbeddedHeaderArray;

  // For body caching...
  bool                mBodyStarted;
  nsCString           mBody;
  bool                mFirstHeaders;

  // For the format being used...
  int32_t             mFormat;

  // For I18N Conversion...
  nsCOMPtr<nsIMimeConverter> mUnicodeConverter;
  nsString            mCharset;
  nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
  nsresult GenerateDateString(const char * dateString, nsACString& formattedDate,
                              bool showDateForToday);
  // The caller is expected to free the result of GetLocalizedDateString
  char* GetLocalizedDateString(const char * dateString);
};

#endif /* _nsMimeBaseEmitter_h_ */