1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 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/. */
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 */
13
#include "nsStringAPI.h"
14
#include "nsIMsgCompFields.h"
15
#include "nsEnigMsgCompose.h"
16
#include "nsIEnigMsgCompFields.h"
17
#include "nsIEnigScriptableMsgCompose.h"
18
#include "nsComponentManagerUtils.h"
20
///undef MOZILLA_INTERNAL_API
23
PRLogModuleInfo* gEnigMsgComposeLog = NULL;
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)
30
#define NS_MSGCOMPOSESECURE_CID \
31
{ /* dd753201-9a23-4e08-957f-b3616bf7e012 */ \
32
0xdd753201, 0x9a23, 0x4e08, \
33
{0x95, 0x7f, 0xb3, 0x61, 0x6b, 0xf7, 0xe0, 0x12 }}
35
static NS_DEFINE_CID(kMsgComposeSecureCID, NS_MSGCOMPOSESECURE_CID);
38
#define MAX_HEADER_BYTES 16000
39
#define MAX_SIGNATURE_BYTES 16000
41
static const PRUint32 kCharMax = 1024;
43
// nsEnigMsgCompose implementation
45
// nsISupports implementation
46
NS_IMPL_THREADSAFE_ISUPPORTS1(nsEnigMsgCompose,
49
// nsEnigMsgCompose implementation
50
nsEnigMsgCompose::nsEnigMsgCompose()
51
: mInitialized(PR_FALSE),
53
mEnigMsgComposeJS(NULL),
54
mMsgComposeSecure(NULL)
61
if (gEnigMsgComposeLog == NULL) {
62
gEnigMsgComposeLog = PR_NewLogModule("nsEnigMsgCompose");
66
// Remember to use original CID, not CONTRACTID, to avoid infinite looping!
67
mMsgComposeSecure = do_CreateInstance(kMsgComposeSecureCID, &rv);
70
nsCOMPtr<nsIThread> myThread;
71
rv = ENIG_GET_THREAD(myThread);
72
DEBUG_LOG(("nsEnigMsgCompose:: <<<<<<<<< CTOR(%p): myThread=%p\n",
73
this, myThread.get()));
78
nsEnigMsgCompose::~nsEnigMsgCompose()
82
nsCOMPtr<nsIThread> myThread;
83
rv = ENIG_GET_THREAD(myThread);
84
DEBUG_LOG(("nsEnigMsgCompose:: >>>>>>>>> DTOR(%p): myThread=%p\n",
85
this, myThread.get()));
93
nsEnigMsgCompose::Finalize()
95
DEBUG_LOG(("nsEnigMsgCompose::Finalize:\n"));
97
// do something useful
103
///////////////////////////////////////////////////////////////////////////////
104
// nsIMsgComposeSecure methods:
105
///////////////////////////////////////////////////////////////////////////////
108
nsEnigMsgCompose::RequiresCryptoEncapsulation(
109
nsIMsgIdentity* aIdentity,
110
nsIMsgCompFields* aCompFields,
111
bool* aRequiresEncryptionWork)
114
DEBUG_LOG(("nsEnigMsgCompose::RequiresCryptoEncapsulation: \n"));
116
if (!mMsgComposeSecure)
117
return NS_ERROR_FAILURE;
119
rv = mMsgComposeSecure->RequiresCryptoEncapsulation(aIdentity,
126
DEBUG_LOG(("nsEnigMsgCompose::RequiresCryptoEncapsulation: Using SMIME\n"));
127
*aRequiresEncryptionWork = PR_TRUE;
131
mEnigMsgComposeJS = do_CreateInstance("@enigmail.net/enigmail/newcomposesecure;1", &rv);
134
ERROR_LOG(("nsEnigMsgCompose::RequiresCryptoEncapsulation: could not create JS object\n"));
139
rv = mEnigMsgComposeJS->DisableSMimeCheck();
140
NS_ENSURE_SUCCESS(rv, rv);
142
return mEnigMsgComposeJS->RequiresCryptoEncapsulation(aIdentity,
144
aRequiresEncryptionWork);
150
nsEnigMsgCompose::BeginCryptoEncapsulation(
151
nsIOutputStream* aStream,
152
const char* aRecipients,
153
nsIMsgCompFields* aCompFields,
154
nsIMsgIdentity* aIdentity,
155
nsIMsgSendReport* sendReport,
158
DEBUG_LOG(("nsEnigMsgCompose::BeginCryptoEncapsulation: %s\n", aRecipients));
160
if (!mMsgComposeSecure)
161
return NS_ERROR_FAILURE;
164
return mMsgComposeSecure->BeginCryptoEncapsulation(aStream, aRecipients,
165
aCompFields, aIdentity,
166
sendReport, aIsDraft);
169
return mEnigMsgComposeJS->BeginCryptoEncapsulation(aStream, aRecipients,
170
aCompFields, aIdentity,
171
sendReport, aIsDraft);
175
nsEnigMsgCompose::FinishCryptoEncapsulation(bool aAbort,
176
nsIMsgSendReport* sendReport)
178
DEBUG_LOG(("nsEnigMsgCompose::FinishCryptoEncapsulation: \n"));
180
if (!mMsgComposeSecure)
181
return NS_ERROR_FAILURE;
184
return mMsgComposeSecure->FinishCryptoEncapsulation(aAbort, sendReport);
187
return mEnigMsgComposeJS->FinishCryptoEncapsulation(aAbort, sendReport);
194
nsEnigMsgCompose::MimeCryptoWriteBlock(const char *aBuf, PRInt32 aLen)
196
DEBUG_LOG(("nsEnigMsgCompose::MimeCryptoWriteBlock: \n"));
198
if (!mMsgComposeSecure)
199
return NS_ERROR_FAILURE;
202
return mMsgComposeSecure->MimeCryptoWriteBlock(aBuf, aLen);
205
return mEnigMsgComposeJS->MimeCryptoWriteBlock(aBuf, aLen);