~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to mailnews/extensions/enigmail/src/nsEnigMsgCompose.cpp

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
 *
 
3
 * This Source Code Form is subject to the terms of the Mozilla Public
 
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
6
 
 
7
 
 
8
// Logging of debug output
 
9
// The following define statement should occur before any include statements
 
10
#define FORCE_PR_LOG       /* Allow logging even in release build */
 
11
 
 
12
#include "enigmail.h"
 
13
#include "nsStringAPI.h"
 
14
#include "nsIMsgCompFields.h"
 
15
#include "nsEnigMsgCompose.h"
 
16
#include "nsIEnigMsgCompFields.h"
 
17
#include "nsIEnigScriptableMsgCompose.h"
 
18
#include "nsComponentManagerUtils.h"
 
19
#include "nspr.h"
 
20
///undef MOZILLA_INTERNAL_API
 
21
 
 
22
#ifdef PR_LOGGING
 
23
PRLogModuleInfo* gEnigMsgComposeLog = NULL;
 
24
#endif
 
25
 
 
26
#define ERROR_LOG(args)    PR_LOG(gEnigMsgComposeLog,PR_LOG_ERROR,args)
 
27
#define WARNING_LOG(args)  PR_LOG(gEnigMsgComposeLog,PR_LOG_WARNING,args)
 
28
#define DEBUG_LOG(args)    PR_LOG(gEnigMsgComposeLog,PR_LOG_DEBUG,args)
 
29
 
 
30
#define NS_MSGCOMPOSESECURE_CID                    \
 
31
{ /* dd753201-9a23-4e08-957f-b3616bf7e012 */       \
 
32
   0xdd753201, 0x9a23, 0x4e08,                     \
 
33
  {0x95, 0x7f, 0xb3, 0x61, 0x6b, 0xf7, 0xe0, 0x12 }}
 
34
 
 
35
static NS_DEFINE_CID(kMsgComposeSecureCID, NS_MSGCOMPOSESECURE_CID);
 
36
 
 
37
 
 
38
#define MAX_HEADER_BYTES 16000
 
39
#define MAX_SIGNATURE_BYTES 16000
 
40
 
 
41
static const PRUint32 kCharMax = 1024;
 
42
 
 
43
// nsEnigMsgCompose implementation
 
44
 
 
45
// nsISupports implementation
 
46
NS_IMPL_THREADSAFE_ISUPPORTS1(nsEnigMsgCompose,
 
47
                              nsIMsgComposeSecure)
 
48
 
 
49
// nsEnigMsgCompose implementation
 
50
nsEnigMsgCompose::nsEnigMsgCompose()
 
51
  : mInitialized(PR_FALSE),
 
52
    mUseSMIME(PR_FALSE),
 
53
    mEnigMsgComposeJS(NULL),
 
54
    mMsgComposeSecure(NULL)
 
55
{
 
56
  nsresult rv;
 
57
 
 
58
  NS_INIT_ISUPPORTS();
 
59
 
 
60
#ifdef PR_LOGGING
 
61
  if (gEnigMsgComposeLog == NULL) {
 
62
    gEnigMsgComposeLog = PR_NewLogModule("nsEnigMsgCompose");
 
63
  }
 
64
#endif
 
65
 
 
66
  // Remember to use original CID, not CONTRACTID, to avoid infinite looping!
 
67
  mMsgComposeSecure = do_CreateInstance(kMsgComposeSecureCID, &rv);
 
68
 
 
69
#ifdef FORCE_PR_LOG
 
70
  nsCOMPtr<nsIThread> myThread;
 
71
  rv = ENIG_GET_THREAD(myThread);
 
72
  DEBUG_LOG(("nsEnigMsgCompose:: <<<<<<<<< CTOR(%p): myThread=%p\n",
 
73
         this, myThread.get()));
 
74
#endif
 
75
}
 
76
 
 
77
 
 
78
nsEnigMsgCompose::~nsEnigMsgCompose()
 
79
{
 
80
  nsresult rv;
 
81
#ifdef FORCE_PR_LOG
 
82
  nsCOMPtr<nsIThread> myThread;
 
83
  rv = ENIG_GET_THREAD(myThread);
 
84
  DEBUG_LOG(("nsEnigMsgCompose:: >>>>>>>>> DTOR(%p): myThread=%p\n",
 
85
         this, myThread.get()));
 
86
#endif
 
87
 
 
88
  Finalize();
 
89
 
 
90
}
 
91
 
 
92
nsresult
 
93
nsEnigMsgCompose::Finalize()
 
94
{
 
95
  DEBUG_LOG(("nsEnigMsgCompose::Finalize:\n"));
 
96
 
 
97
  // do something useful
 
98
 
 
99
  return NS_OK;
 
100
}
 
101
 
 
102
 
 
103
///////////////////////////////////////////////////////////////////////////////
 
104
// nsIMsgComposeSecure methods:
 
105
///////////////////////////////////////////////////////////////////////////////
 
106
 
 
107
NS_IMETHODIMP
 
108
nsEnigMsgCompose::RequiresCryptoEncapsulation(
 
109
                                        nsIMsgIdentity* aIdentity,
 
110
                                        nsIMsgCompFields* aCompFields,
 
111
                                        bool* aRequiresEncryptionWork)
 
112
{
 
113
  nsresult rv;
 
114
  DEBUG_LOG(("nsEnigMsgCompose::RequiresCryptoEncapsulation: \n"));
 
115
 
 
116
  if (!mMsgComposeSecure)
 
117
    return NS_ERROR_FAILURE;
 
118
 
 
119
  rv = mMsgComposeSecure->RequiresCryptoEncapsulation(aIdentity,
 
120
                                                      aCompFields,
 
121
                                                      &mUseSMIME);
 
122
  if (NS_FAILED(rv))
 
123
    return rv;
 
124
 
 
125
  if (mUseSMIME) {
 
126
    DEBUG_LOG(("nsEnigMsgCompose::RequiresCryptoEncapsulation: Using SMIME\n"));
 
127
    *aRequiresEncryptionWork = PR_TRUE;
 
128
    return NS_OK;
 
129
  }
 
130
 
 
131
  mEnigMsgComposeJS = do_CreateInstance("@enigmail.net/enigmail/newcomposesecure;1", &rv);
 
132
 
 
133
  if (NS_FAILED(rv)) {
 
134
    ERROR_LOG(("nsEnigMsgCompose::RequiresCryptoEncapsulation: could not create JS object\n"));
 
135
 
 
136
    return rv;
 
137
  }
 
138
 
 
139
  rv = mEnigMsgComposeJS->DisableSMimeCheck();
 
140
  NS_ENSURE_SUCCESS(rv, rv);
 
141
 
 
142
  return mEnigMsgComposeJS->RequiresCryptoEncapsulation(aIdentity,
 
143
                                                      aCompFields,
 
144
                                                      aRequiresEncryptionWork);
 
145
 
 
146
}
 
147
 
 
148
 
 
149
NS_IMETHODIMP
 
150
nsEnigMsgCompose::BeginCryptoEncapsulation(
 
151
                                        nsIOutputStream* aStream,
 
152
                                        const char* aRecipients,
 
153
                                        nsIMsgCompFields* aCompFields,
 
154
                                        nsIMsgIdentity* aIdentity,
 
155
                                        nsIMsgSendReport* sendReport,
 
156
                                        bool aIsDraft)
 
157
{
 
158
  DEBUG_LOG(("nsEnigMsgCompose::BeginCryptoEncapsulation: %s\n", aRecipients));
 
159
 
 
160
  if (!mMsgComposeSecure)
 
161
    return NS_ERROR_FAILURE;
 
162
 
 
163
  if (mUseSMIME) {
 
164
    return mMsgComposeSecure->BeginCryptoEncapsulation(aStream, aRecipients,
 
165
                                                       aCompFields, aIdentity,
 
166
                                                       sendReport, aIsDraft);
 
167
  }
 
168
 
 
169
  return mEnigMsgComposeJS->BeginCryptoEncapsulation(aStream, aRecipients,
 
170
                                                     aCompFields, aIdentity,
 
171
                                                     sendReport, aIsDraft);
 
172
}
 
173
 
 
174
NS_IMETHODIMP
 
175
nsEnigMsgCompose::FinishCryptoEncapsulation(bool aAbort,
 
176
                                            nsIMsgSendReport* sendReport)
 
177
{
 
178
  DEBUG_LOG(("nsEnigMsgCompose::FinishCryptoEncapsulation: \n"));
 
179
 
 
180
  if (!mMsgComposeSecure)
 
181
    return NS_ERROR_FAILURE;
 
182
 
 
183
  if (mUseSMIME) {
 
184
    return mMsgComposeSecure->FinishCryptoEncapsulation(aAbort, sendReport);
 
185
  }
 
186
 
 
187
  return mEnigMsgComposeJS->FinishCryptoEncapsulation(aAbort, sendReport);
 
188
}
 
189
 
 
190
 
 
191
 
 
192
 
 
193
NS_IMETHODIMP
 
194
nsEnigMsgCompose::MimeCryptoWriteBlock(const char *aBuf, PRInt32 aLen)
 
195
{
 
196
  DEBUG_LOG(("nsEnigMsgCompose::MimeCryptoWriteBlock: \n"));
 
197
 
 
198
  if (!mMsgComposeSecure)
 
199
    return NS_ERROR_FAILURE;
 
200
 
 
201
  if (mUseSMIME) {
 
202
    return mMsgComposeSecure->MimeCryptoWriteBlock(aBuf, aLen);
 
203
  }
 
204
 
 
205
  return mEnigMsgComposeJS->MimeCryptoWriteBlock(aBuf, aLen);
 
206
}
 
207