Bug 1546364 - Reformat to Google coding style in mailnews/extensions. rs=reformat
# ignore-this-changeset
This commit is contained in:
Родитель
6f937bff08
Коммит
7abc056d03
|
@ -14,16 +14,6 @@ typedef long EDisposeType;
|
|||
typedef long ReceiptHdrType;
|
||||
typedef long MDNIncorporateType;
|
||||
|
||||
%{C++
|
||||
#define NS_MSGMDNGENERATOR_CONTRACTID \
|
||||
"@mozilla.org/messenger-mdn/generator;1"
|
||||
|
||||
#define NS_MSGMDNGENERATOR_CID \
|
||||
{ /* ec917b13-8f73-4d4d-9146-d7f7aafe9076 */ \
|
||||
0xec917b13, 0x8f73, 0x4d4d, \
|
||||
{ 0x91, 0x46, 0xd7, 0xf7, 0xaa, 0xfe, 0x90, 0x76 }}
|
||||
%}
|
||||
|
||||
[scriptable, uuid(440EA3DE-DACA-4886-9875-84E6CD7D7927)]
|
||||
interface nsIMsgMdnGenerator : nsISupports
|
||||
{
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -52,8 +52,7 @@ private:
|
|||
//
|
||||
// Traits per token are maintained as a linked list.
|
||||
//
|
||||
struct TraitPerToken
|
||||
{
|
||||
struct TraitPerToken {
|
||||
uint32_t mId; // identifying number for a trait
|
||||
uint32_t mCount; // count of messages with this token and trait
|
||||
uint32_t mNextLink; // index in mTraitStore for the next trait, or 0
|
||||
|
@ -67,8 +66,7 @@ struct TraitPerToken
|
|||
//
|
||||
// Analyses per token are maintained as a linked list.
|
||||
//
|
||||
struct AnalysisPerToken
|
||||
{
|
||||
struct AnalysisPerToken {
|
||||
uint32_t mTraitIndex; // index representing a protrait/antitrait pair.
|
||||
// So if we are analyzing 3 different traits, then
|
||||
// the first trait is 0, the second 1, etc.
|
||||
|
@ -82,7 +80,6 @@ struct AnalysisPerToken
|
|||
|
||||
class TokenHash {
|
||||
public:
|
||||
|
||||
virtual ~TokenHash();
|
||||
/**
|
||||
* Clears out the previous message tokens.
|
||||
|
@ -110,7 +107,8 @@ public:
|
|||
|
||||
// The training set keeps an occurrence count on each word. This count
|
||||
// is supposed to count the # of messages it occurs in.
|
||||
// When add/remove is called while tokenizing a message and NOT the training set,
|
||||
// When add/remove is called while tokenizing a message and NOT the training
|
||||
// set,
|
||||
//
|
||||
Token* add(const char* word, uint32_t count = 1);
|
||||
|
||||
|
@ -119,9 +117,11 @@ public:
|
|||
void tokenize(const char* text);
|
||||
|
||||
/**
|
||||
* Creates specific tokens based on the mime headers for the message being tokenized
|
||||
* Creates specific tokens based on the mime headers for the message being
|
||||
* tokenized
|
||||
*/
|
||||
void tokenizeHeaders(nsIUTF8StringEnumerator * aHeaderNames, nsIUTF8StringEnumerator * aHeaderValues);
|
||||
void tokenizeHeaders(nsIUTF8StringEnumerator* aHeaderNames,
|
||||
nsIUTF8StringEnumerator* aHeaderValues);
|
||||
|
||||
void tokenizeAttachment(const char* aContentType, const char* aFileName);
|
||||
|
||||
|
@ -134,22 +134,24 @@ public:
|
|||
// Delimiters used in tokenizing a particular header.
|
||||
// Parallel array to mEnabledHeaders
|
||||
nsTArray<nsCString> mEnabledHeadersDelimiters;
|
||||
bool mCustomHeaderTokenization; // Are there any preference-set tokenization customizations?
|
||||
bool mCustomHeaderTokenization; // Are there any preference-set tokenization
|
||||
// customizations?
|
||||
uint32_t mMaxLengthForToken; // maximum length of a token
|
||||
// should we convert iframe to div during tokenization?
|
||||
bool mIframeToDiv;
|
||||
|
||||
private:
|
||||
|
||||
void tokenize_ascii_word(char* word);
|
||||
void tokenize_japanese_word(char* chunk);
|
||||
inline void addTokenForHeader(const char* aTokenPrefix, nsACString& aValue,
|
||||
bool aTokenizeValue = false, const char* aDelimiters = nullptr);
|
||||
bool aTokenizeValue = false,
|
||||
const char* aDelimiters = nullptr);
|
||||
nsresult stripHTML(const nsAString& inString, nsAString& outString);
|
||||
// helper function to escape \n, \t, etc from a CString
|
||||
void UnescapeCString(nsCString& aCString);
|
||||
nsresult ScannerNext(const char16_t* text, int32_t length, int32_t pos,
|
||||
bool isLastBuffer, int32_t *begin, int32_t *end, bool *_retval);
|
||||
bool isLastBuffer, int32_t* begin, int32_t* end,
|
||||
bool* _retval);
|
||||
RefPtr<mozilla::intl::WordBreaker> mWordBreaker;
|
||||
};
|
||||
|
||||
|
@ -179,7 +181,8 @@ public:
|
|||
* @param aTraitId id for the trait whose counts will be remembered
|
||||
* @param aCount number of new messages represented by the token list
|
||||
*/
|
||||
void rememberTokens(Tokenizer& aTokenizer, uint32_t aTraitId, uint32_t aCount);
|
||||
void rememberTokens(Tokenizer& aTokenizer, uint32_t aTraitId,
|
||||
uint32_t aCount);
|
||||
|
||||
/**
|
||||
* decrement counts for tokens in the storage, removing if all counts
|
||||
|
@ -267,9 +270,8 @@ public:
|
|||
* used in storing data from aFile into the local corpus.
|
||||
*
|
||||
*/
|
||||
nsresult UpdateData(nsIFile *aFile, bool aIsAdd,
|
||||
uint32_t aRemapCount, uint32_t *aFromTraits,
|
||||
uint32_t *aToTraits);
|
||||
nsresult UpdateData(nsIFile* aFile, bool aIsAdd, uint32_t aRemapCount,
|
||||
uint32_t* aFromTraits, uint32_t* aToTraits);
|
||||
|
||||
/**
|
||||
* remove all counts (message and tokens) for a trait id
|
||||
|
@ -279,7 +281,6 @@ public:
|
|||
nsresult ClearTrait(uint32_t aTrait);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* return the local corpus storage file for junk traits
|
||||
*/
|
||||
|
@ -331,12 +332,14 @@ protected:
|
|||
// TraitPerToken
|
||||
nsTArray<uint32_t> mMessageCounts; // count of messages per trait
|
||||
// represented in the store
|
||||
nsTArray<uint32_t> mMessageCountsId; // Parallel array to mMessageCounts, with
|
||||
// the corresponding trait ID
|
||||
nsTArray<uint32_t> mMessageCountsId; // Parallel array to mMessageCounts,
|
||||
// with the corresponding trait ID
|
||||
};
|
||||
|
||||
class nsBayesianFilter : public nsIJunkMailPlugin, nsIMsgCorpus,
|
||||
nsIObserver, nsSupportsWeakReference {
|
||||
class nsBayesianFilter : public nsIJunkMailPlugin,
|
||||
nsIMsgCorpus,
|
||||
nsIObserver,
|
||||
nsSupportsWeakReference {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMSGFILTERPLUGIN
|
||||
|
@ -348,13 +351,12 @@ public:
|
|||
|
||||
nsresult Init();
|
||||
|
||||
nsresult tokenizeMessage(const char* messageURI, nsIMsgWindow *aMsgWindow, TokenAnalyzer* analyzer);
|
||||
nsresult tokenizeMessage(const char* messageURI, nsIMsgWindow* aMsgWindow,
|
||||
TokenAnalyzer* analyzer);
|
||||
void classifyMessage(Tokenizer& tokens, const char* messageURI,
|
||||
nsIJunkMailClassificationListener* listener);
|
||||
|
||||
void classifyMessage(
|
||||
Tokenizer& tokenizer,
|
||||
const char* messageURI,
|
||||
void classifyMessage(Tokenizer& tokenizer, const char* messageURI,
|
||||
nsTArray<uint32_t>& aProTraits,
|
||||
nsTArray<uint32_t>& aAntiTraits,
|
||||
nsIJunkMailClassificationListener* listener,
|
||||
|
@ -367,7 +369,6 @@ public:
|
|||
nsIJunkMailClassificationListener* listener,
|
||||
nsIMsgTraitClassificationListener* aTraitListener);
|
||||
|
||||
|
||||
protected:
|
||||
virtual ~nsBayesianFilter();
|
||||
|
||||
|
@ -394,8 +395,8 @@ protected:
|
|||
* Set the value of the AnalysisPerToken object for a particular
|
||||
* token and trait
|
||||
*/
|
||||
nsresult setAnalysis(Token& token, uint32_t aTraitIndex,
|
||||
double aDistance, double aProbability);
|
||||
nsresult setAnalysis(Token& token, uint32_t aTraitIndex, double aDistance,
|
||||
double aProbability);
|
||||
};
|
||||
|
||||
#endif // _nsBayesianFilter_h__
|
||||
|
|
|
@ -10,7 +10,9 @@
|
|||
"@mozilla.org/messenger/filter-plugin;1?name=bayesianfilter"
|
||||
#define NS_BAYESIANFILTER_CID \
|
||||
{ /* F1070BFA-D539-11D6-90CA-00039310A47A */ \
|
||||
0xF1070BFA, 0xD539, 0x11D6, \
|
||||
{ 0x90, 0xCA, 0x00, 0x03, 0x93, 0x10, 0xA4, 0x7A }}
|
||||
0xF1070BFA, 0xD539, 0x11D6, { \
|
||||
0x90, 0xCA, 0x00, 0x03, 0x93, 0x10, 0xA4, 0x7A \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif /* nsBayesianFilterCID_h__ */
|
||||
|
|
|
@ -73,20 +73,27 @@ static const double C_10 = -174611.0 / 125400.0;
|
|||
static const double C_11 = 77683.0 / 5796.0;
|
||||
|
||||
// truncated asymptotic series in 1/z
|
||||
static inline double lngamma_asymp (double z)
|
||||
{
|
||||
static inline double lngamma_asymp(double z) {
|
||||
double w, w2, sum;
|
||||
w = 1.0 / z;
|
||||
w2 = w * w;
|
||||
sum = w * (w2 * (w2 * (w2 * (w2 * (w2 * (w2 * (w2 * (w2 * (w2
|
||||
* (C_11 * w2 + C_10) + C_9) + C_8) + C_7) + C_6)
|
||||
+ C_5) + C_4) + C_3) + C_2) + C_1);
|
||||
sum =
|
||||
w *
|
||||
(w2 * (w2 * (w2 * (w2 * (w2 * (w2 * (w2 * (w2 * (w2 * (C_11 * w2 + C_10) +
|
||||
C_9) +
|
||||
C_8) +
|
||||
C_7) +
|
||||
C_6) +
|
||||
C_5) +
|
||||
C_4) +
|
||||
C_3) +
|
||||
C_2) +
|
||||
C_1);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
struct fact_table_s
|
||||
{
|
||||
struct fact_table_s {
|
||||
double fact;
|
||||
double lnfact;
|
||||
};
|
||||
|
@ -111,8 +118,7 @@ static const struct fact_table_s FactTable[] = {
|
|||
{1307674368000.000, 2.7899271383840891566988e+01},
|
||||
{20922789888000.00, 3.0671860106080672803835e+01},
|
||||
{355687428096000.0, 3.3505073450136888885825e+01},
|
||||
{6402373705728000., 3.6395445208033053576674e+01}
|
||||
};
|
||||
{6402373705728000., 3.6395445208033053576674e+01}};
|
||||
#define FactTableLength (int)(sizeof(FactTable) / sizeof(FactTable[0]))
|
||||
|
||||
// for speed
|
||||
|
@ -127,20 +133,17 @@ static const double ln_2pi_2 = 0.918938533204672741803; // log(2*PI)/2
|
|||
< 1e-10. In two small regions, 1 +/- .001 and 2 +/- .001 errors
|
||||
increase quickly.
|
||||
*/
|
||||
static double nsLnGamma (double z_in, int *gsign)
|
||||
{
|
||||
static double nsLnGamma(double z_in, int *gsign) {
|
||||
double scale, z, sum, result;
|
||||
*gsign = 1;
|
||||
|
||||
int zi = (int)z_in;
|
||||
if (z_in == (double) zi)
|
||||
{
|
||||
if (z_in == (double)zi) {
|
||||
if (0 < zi && zi <= FactTableLength)
|
||||
return FactTable[zi - 1].lnfact; // gamma(z) = (z-1)!
|
||||
}
|
||||
|
||||
for (scale = 1.0, z = z_in; z < 8.0; ++z)
|
||||
scale *= z;
|
||||
for (scale = 1.0, z = z_in; z < 8.0; ++z) scale *= z;
|
||||
|
||||
sum = lngamma_asymp(z);
|
||||
result = (z - 0.5) * log(z) - z + ln_2pi_2 - log(scale);
|
||||
|
@ -149,98 +152,78 @@ static double nsLnGamma (double z_in, int *gsign)
|
|||
}
|
||||
|
||||
// log( e^(-x)*x^a/Gamma(a) )
|
||||
static inline double lnPQfactor (double a, double x)
|
||||
{
|
||||
static inline double lnPQfactor(double a, double x) {
|
||||
int gsign; // ignored because a > 0
|
||||
return a * log(x) - x - nsLnGamma(a, &gsign);
|
||||
}
|
||||
|
||||
static double Pseries (double a, double x, int *error)
|
||||
{
|
||||
static double Pseries(double a, double x, int *error) {
|
||||
double sum, term;
|
||||
const double eps = 2.0 * DBL_EPSILON;
|
||||
const int imax = 5000;
|
||||
int i;
|
||||
|
||||
sum = term = 1.0 / a;
|
||||
for (i = 1; i < imax; ++i)
|
||||
{
|
||||
for (i = 1; i < imax; ++i) {
|
||||
term *= x / (a + i);
|
||||
sum += term;
|
||||
if (fabs (term) < eps * fabs (sum))
|
||||
break;
|
||||
if (fabs(term) < eps * fabs(sum)) break;
|
||||
}
|
||||
|
||||
if (i >= imax)
|
||||
*error = 1;
|
||||
if (i >= imax) *error = 1;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
static double Qcontfrac (double a, double x, int *error)
|
||||
{
|
||||
static double Qcontfrac(double a, double x, int *error) {
|
||||
double result, D, C, e, f, term;
|
||||
const double eps = 2.0 * DBL_EPSILON;
|
||||
const double small =
|
||||
DBL_EPSILON * DBL_EPSILON * DBL_EPSILON * DBL_EPSILON;
|
||||
const double small = DBL_EPSILON * DBL_EPSILON * DBL_EPSILON * DBL_EPSILON;
|
||||
const int imax = 5000;
|
||||
int i;
|
||||
|
||||
// modified Lentz method
|
||||
f = x - a + 1.0;
|
||||
if (fabs (f) < small)
|
||||
f = small;
|
||||
if (fabs(f) < small) f = small;
|
||||
C = f + 1.0 / small;
|
||||
D = 1.0 / f;
|
||||
result = D;
|
||||
for (i = 1; i < imax; ++i)
|
||||
{
|
||||
for (i = 1; i < imax; ++i) {
|
||||
e = i * (a - i);
|
||||
f += 2.0;
|
||||
D = f + e * D;
|
||||
if (fabs (D) < small)
|
||||
D = small;
|
||||
if (fabs(D) < small) D = small;
|
||||
D = 1.0 / D;
|
||||
C = f + e / C;
|
||||
if (fabs (C) < small)
|
||||
C = small;
|
||||
if (fabs(C) < small) C = small;
|
||||
term = C * D;
|
||||
result *= term;
|
||||
if (fabs (term - 1.0) < eps)
|
||||
break;
|
||||
if (fabs(term - 1.0) < eps) break;
|
||||
}
|
||||
|
||||
if (i >= imax)
|
||||
*error = 1;
|
||||
if (i >= imax) *error = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
static double nsIncompleteGammaP (double a, double x, int *error)
|
||||
{
|
||||
static double nsIncompleteGammaP(double a, double x, int *error) {
|
||||
double result, dom, ldom;
|
||||
// domain errors. the return values are meaningless but have
|
||||
// to return something.
|
||||
*error = -1;
|
||||
if (a <= 0.0)
|
||||
return 1.0;
|
||||
if (x < 0.0)
|
||||
return 0.0;
|
||||
if (a <= 0.0) return 1.0;
|
||||
if (x < 0.0) return 0.0;
|
||||
*error = 0;
|
||||
if (x == 0.0)
|
||||
return 0.0;
|
||||
if (x == 0.0) return 0.0;
|
||||
|
||||
ldom = lnPQfactor(a, x);
|
||||
dom = exp(ldom);
|
||||
// might need to adjust the crossover point
|
||||
if (a <= 0.5)
|
||||
{
|
||||
if (a <= 0.5) {
|
||||
if (x < a + 1.0)
|
||||
result = dom * Pseries(a, x, error);
|
||||
else
|
||||
result = 1.0 - dom * Qcontfrac(a, x, error);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (x < a)
|
||||
result = dom * Pseries(a, x, error);
|
||||
else
|
||||
|
@ -248,12 +231,9 @@ static double nsIncompleteGammaP (double a, double x, int *error)
|
|||
}
|
||||
|
||||
// not clear if this can ever happen
|
||||
if (result > 1.0)
|
||||
result = 1.0;
|
||||
if (result < 0.0)
|
||||
result = 0.0;
|
||||
if (result > 1.0) result = 1.0;
|
||||
if (result < 0.0) result = 0.0;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -55,7 +55,6 @@
|
|||
*/
|
||||
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
|
||||
|
||||
|
||||
# include <assert.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
|
@ -71,14 +70,12 @@
|
|||
# define sqlite3_realloc realloc
|
||||
|
||||
static const unsigned char sqlite3Utf8Trans1[] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
|
||||
0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
|
||||
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x00,
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
|
||||
0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
|
||||
0x07, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
|
||||
};
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
@ -92,15 +89,14 @@ typedef unsigned char u8;
|
|||
* encoded byte. The same holds true at exit.
|
||||
* @param c The character to encode; this should be an unsigned int.
|
||||
*/
|
||||
#define WRITE_UTF8(zOut, c) { \
|
||||
# define WRITE_UTF8(zOut, c) \
|
||||
{ \
|
||||
if (c < 0x0080) { \
|
||||
*zOut++ = (u8)(c & 0xff); \
|
||||
} \
|
||||
else if( c<0x0800 ){ \
|
||||
} else if (c < 0x0800) { \
|
||||
*zOut++ = 0xC0 + (u8)((c >> 6) & 0x1F); \
|
||||
*zOut++ = 0x80 + (u8)(c & 0x3F); \
|
||||
} \
|
||||
else if( c<0x10000 ){ \
|
||||
} else if (c < 0x10000) { \
|
||||
*zOut++ = 0xE0 + (u8)((c >> 12) & 0x0F); \
|
||||
*zOut++ = 0x80 + (u8)((c >> 6) & 0x3F); \
|
||||
*zOut++ = 0x80 + (u8)(c & 0x3F); \
|
||||
|
@ -145,16 +141,18 @@ typedef unsigned char u8;
|
|||
* @param c The 'unsigned int' to hold the resulting character value. Do not
|
||||
* use a short or a char.
|
||||
*/
|
||||
#define READ_UTF8(zIn, zTerm, c) { \
|
||||
# define READ_UTF8(zIn, zTerm, c) \
|
||||
{ \
|
||||
c = *(zIn++); \
|
||||
if (c >= 0xc0) { \
|
||||
c = sqlite3Utf8Trans1[c - 0xc0]; \
|
||||
while (zIn != zTerm && (*zIn & 0xc0) == 0x80) { \
|
||||
c = (c << 6) + (0x3f & *(zIn++)); \
|
||||
} \
|
||||
if( c<0x80 \
|
||||
|| (c&0xFFFFF800)==0xD800 \
|
||||
|| (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
|
||||
if (c < 0x80 || (c & 0xFFFFF800) == 0xD800 || \
|
||||
(c & 0xFFFFFFFE) == 0xFFFE) { \
|
||||
c = 0xFFFD; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
|
@ -200,7 +198,6 @@ typedef struct porter_tokenizer_cursor {
|
|||
int iPrevBigramOffset; /* previous result was bi-gram */
|
||||
} porter_tokenizer_cursor;
|
||||
|
||||
|
||||
/* Forward declaration */
|
||||
static const sqlite3_tokenizer_module porterTokenizerModule;
|
||||
|
||||
|
@ -210,10 +207,8 @@ extern unsigned int normalize_character(const unsigned int c);
|
|||
/*
|
||||
** Create a new tokenizer instance.
|
||||
*/
|
||||
static int porterCreate(
|
||||
int argc, const char * const *argv,
|
||||
sqlite3_tokenizer **ppTokenizer
|
||||
){
|
||||
static int porterCreate(int argc, const char *const *argv,
|
||||
sqlite3_tokenizer **ppTokenizer) {
|
||||
porter_tokenizer *t;
|
||||
t = (porter_tokenizer *)sqlite3_malloc(sizeof(*t));
|
||||
if (t == NULL) return SQLITE_NOMEM;
|
||||
|
@ -277,10 +272,8 @@ static int porterClose(sqlite3_tokenizer_cursor *pCursor){
|
|||
/*
|
||||
** Vowel or consonant
|
||||
*/
|
||||
static const char cType[] = {
|
||||
0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0,
|
||||
1, 1, 1, 2, 1
|
||||
};
|
||||
static const char cType[] = {0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1,
|
||||
1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 2, 1};
|
||||
|
||||
/*
|
||||
** isConsonant() and isVowel() determine if their first character in
|
||||
|
@ -335,9 +328,13 @@ static int isVowel(const char *z){
|
|||
** for an instance of of a consonant followed by a vowel.
|
||||
*/
|
||||
static int m_gt_0(const char *z) {
|
||||
while( isVowel(z) ){ z++; }
|
||||
while (isVowel(z)) {
|
||||
z++;
|
||||
}
|
||||
if (*z == 0) return 0;
|
||||
while( isConsonant(z) ){ z++; }
|
||||
while (isConsonant(z)) {
|
||||
z++;
|
||||
}
|
||||
return *z != 0;
|
||||
}
|
||||
|
||||
|
@ -345,13 +342,21 @@ static int m_gt_0(const char *z){
|
|||
** exactly 1
|
||||
*/
|
||||
static int m_eq_1(const char *z) {
|
||||
while( isVowel(z) ){ z++; }
|
||||
while (isVowel(z)) {
|
||||
z++;
|
||||
}
|
||||
if (*z == 0) return 0;
|
||||
while( isConsonant(z) ){ z++; }
|
||||
while (isConsonant(z)) {
|
||||
z++;
|
||||
}
|
||||
if (*z == 0) return 0;
|
||||
while( isVowel(z) ){ z++; }
|
||||
while (isVowel(z)) {
|
||||
z++;
|
||||
}
|
||||
if (*z == 0) return 1;
|
||||
while( isConsonant(z) ){ z++; }
|
||||
while (isConsonant(z)) {
|
||||
z++;
|
||||
}
|
||||
return *z == 0;
|
||||
}
|
||||
|
||||
|
@ -359,13 +364,21 @@ static int m_eq_1(const char *z){
|
|||
** or m>0
|
||||
*/
|
||||
static int m_gt_1(const char *z) {
|
||||
while( isVowel(z) ){ z++; }
|
||||
while (isVowel(z)) {
|
||||
z++;
|
||||
}
|
||||
if (*z == 0) return 0;
|
||||
while( isConsonant(z) ){ z++; }
|
||||
while (isConsonant(z)) {
|
||||
z++;
|
||||
}
|
||||
if (*z == 0) return 0;
|
||||
while( isVowel(z) ){ z++; }
|
||||
while (isVowel(z)) {
|
||||
z++;
|
||||
}
|
||||
if (*z == 0) return 0;
|
||||
while( isConsonant(z) ){ z++; }
|
||||
while (isConsonant(z)) {
|
||||
z++;
|
||||
}
|
||||
return *z != 0;
|
||||
}
|
||||
|
||||
|
@ -373,7 +386,9 @@ static int m_gt_1(const char *z){
|
|||
** Return TRUE if there is a vowel anywhere within z[0..n-1]
|
||||
*/
|
||||
static int hasVowel(const char *z) {
|
||||
while( isConsonant(z) ){ z++; }
|
||||
while (isConsonant(z)) {
|
||||
z++;
|
||||
}
|
||||
return *z != 0;
|
||||
}
|
||||
|
||||
|
@ -396,11 +411,9 @@ static int doubleConsonant(const char *z){
|
|||
** first three letters and the first one cannot be in [wxy].
|
||||
*/
|
||||
static int star_oh(const char *z) {
|
||||
return
|
||||
z[0]!=0 && isConsonant(z) &&
|
||||
z[0]!='w' && z[0]!='x' && z[0]!='y' &&
|
||||
z[1]!=0 && isVowel(z+1) &&
|
||||
z[2]!=0 && isConsonant(z+2);
|
||||
return z[0] != 0 && isConsonant(z) && z[0] != 'w' && z[0] != 'x' &&
|
||||
z[0] != 'y' && z[1] != 0 && isVowel(z + 1) && z[2] != 0 &&
|
||||
isConsonant(z + 2);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -422,7 +435,10 @@ static int stem(
|
|||
int (*xCond)(const char *) /* Condition that must be true */
|
||||
) {
|
||||
char *z = *pz;
|
||||
while( *zFrom && *zFrom==*z ){ z++; zFrom++; }
|
||||
while (*zFrom && *zFrom == *z) {
|
||||
z++;
|
||||
zFrom++;
|
||||
}
|
||||
if (*zFrom != 0) return 0;
|
||||
if (xCond && !xCond(z)) return 1;
|
||||
while (*zTo) {
|
||||
|
@ -434,14 +450,13 @@ static int stem(
|
|||
|
||||
/**
|
||||
* Voiced sound mark is only on Japanese. It is like accent. It combines with
|
||||
* previous character. Example, "サ" (Katakana) with "゛" (voiced sound mark) is
|
||||
* "ザ". Although full-width character mapping has combined character like "ザ",
|
||||
* there is no combined character on half-width Katanaka character mapping.
|
||||
* previous character. Example, "サ" (Katakana) with "゛" (voiced sound mark)
|
||||
* is "ザ". Although full-width character mapping has combined character like
|
||||
* "ザ", there is no combined character on half-width Katanaka character
|
||||
* mapping.
|
||||
*/
|
||||
static int isVoicedSoundMark(const unsigned int c)
|
||||
{
|
||||
if (c == 0xff9e || c == 0xff9f || c == 0x3099 || c == 0x309a)
|
||||
return 1;
|
||||
static int isVoicedSoundMark(const unsigned int c) {
|
||||
if (c == 0xff9e || c == 0xff9f || c == 0x3099 || c == 0x309a) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -508,8 +523,7 @@ static void copy_stemmer(const unsigned char *zIn, const int nBytesIn,
|
|||
/* ignore voiced/semi-voiced sound mark */
|
||||
if (!isVoicedSoundMark(c)) {
|
||||
/* advance one non-voiced sound mark character. */
|
||||
if (zBackStart)
|
||||
READ_UTF8(zBackStart, zOut, trashC);
|
||||
if (zBackStart) READ_UTF8(zBackStart, zOut, trashC);
|
||||
|
||||
WRITE_UTF8(zOut, c);
|
||||
charCount++;
|
||||
|
@ -530,7 +544,6 @@ static void copy_stemmer(const unsigned char *zIn, const int nBytesIn,
|
|||
*pnBytesOut = zOut - zOutStart;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Stem the input word zIn[0..nIn-1]. Store the output in zOut.
|
||||
** zOut is at least big enough to hold nIn bytes. Write the actual
|
||||
|
@ -554,12 +567,8 @@ static void copy_stemmer(const unsigned char *zIn, const int nBytesIn,
|
|||
** Stemming never increases the length of the word. So there is
|
||||
** no chance of overflowing the zOut buffer.
|
||||
*/
|
||||
static void porter_stemmer(
|
||||
const unsigned char *zIn,
|
||||
unsigned int nIn,
|
||||
unsigned char *zOut,
|
||||
int *pnOut
|
||||
){
|
||||
static void porter_stemmer(const unsigned char *zIn, unsigned int nIn,
|
||||
unsigned char *zOut, int *pnOut) {
|
||||
unsigned int i, j, c;
|
||||
char zReverse[28];
|
||||
char *z, *z2;
|
||||
|
@ -587,14 +596,10 @@ static void porter_stemmer(
|
|||
memset(&zReverse[sizeof(zReverse) - 5], 0, 5);
|
||||
z = &zReverse[j + 1];
|
||||
|
||||
|
||||
/* Step 1a */
|
||||
if (z[0] == 's') {
|
||||
if(
|
||||
!stem(&z, "sess", "ss", 0) &&
|
||||
!stem(&z, "sei", "i", 0) &&
|
||||
!stem(&z, "ss", "ss", 0)
|
||||
){
|
||||
if (!stem(&z, "sess", "ss", 0) && !stem(&z, "sei", "i", 0) &&
|
||||
!stem(&z, "ss", "ss", 0)) {
|
||||
z++;
|
||||
}
|
||||
}
|
||||
|
@ -603,12 +608,9 @@ static void porter_stemmer(
|
|||
z2 = z;
|
||||
if (stem(&z, "dee", "ee", m_gt_0)) {
|
||||
/* Do nothing. The work was all in the test */
|
||||
}else if(
|
||||
(stem(&z, "gni", "", hasVowel) || stem(&z, "de", "", hasVowel))
|
||||
&& z!=z2
|
||||
){
|
||||
if( stem(&z, "ta", "ate", 0) ||
|
||||
stem(&z, "lb", "ble", 0) ||
|
||||
} else if ((stem(&z, "gni", "", hasVowel) || stem(&z, "de", "", hasVowel)) &&
|
||||
z != z2) {
|
||||
if (stem(&z, "ta", "ate", 0) || stem(&z, "lb", "ble", 0) ||
|
||||
stem(&z, "zi", "ize", 0)) {
|
||||
/* Do nothing. The work was all in the test */
|
||||
} else if (doubleConsonant(z) && (*z != 'l' && *z != 's' && *z != 'z')) {
|
||||
|
@ -640,10 +642,8 @@ static void porter_stemmer(
|
|||
(void)(stem(&z, "igol", "log", m_gt_0));
|
||||
break;
|
||||
case 'l':
|
||||
(void) (stem(&z, "ilb", "ble", m_gt_0) ||
|
||||
stem(&z, "illa", "al", m_gt_0) ||
|
||||
stem(&z, "iltne", "ent", m_gt_0) ||
|
||||
stem(&z, "ile", "e", m_gt_0) ||
|
||||
(void)(stem(&z, "ilb", "ble", m_gt_0) || stem(&z, "illa", "al", m_gt_0) ||
|
||||
stem(&z, "iltne", "ent", m_gt_0) || stem(&z, "ile", "e", m_gt_0) ||
|
||||
stem(&z, "ilsuo", "ous", m_gt_0));
|
||||
break;
|
||||
case 'o':
|
||||
|
@ -667,16 +667,14 @@ static void porter_stemmer(
|
|||
/* Step 3 */
|
||||
switch (z[0]) {
|
||||
case 'e':
|
||||
(void) (stem(&z, "etaci", "ic", m_gt_0) ||
|
||||
stem(&z, "evita", "", m_gt_0) ||
|
||||
(void)(stem(&z, "etaci", "ic", m_gt_0) || stem(&z, "evita", "", m_gt_0) ||
|
||||
stem(&z, "ezila", "al", m_gt_0));
|
||||
break;
|
||||
case 'i':
|
||||
(void)(stem(&z, "itici", "ic", m_gt_0));
|
||||
break;
|
||||
case 'l':
|
||||
(void) (stem(&z, "laci", "ic", m_gt_0) ||
|
||||
stem(&z, "luf", "", m_gt_0));
|
||||
(void)(stem(&z, "laci", "ic", m_gt_0) || stem(&z, "luf", "", m_gt_0));
|
||||
break;
|
||||
case 's':
|
||||
(void)(stem(&z, "ssen", "", m_gt_0));
|
||||
|
@ -691,7 +689,8 @@ static void porter_stemmer(
|
|||
}
|
||||
break;
|
||||
case 'c':
|
||||
if( z[0]=='e' && z[2]=='n' && (z[3]=='a' || z[3]=='e') && m_gt_1(z+4) ){
|
||||
if (z[0] == 'e' && z[2] == 'n' && (z[3] == 'a' || z[3] == 'e') &&
|
||||
m_gt_1(z + 4)) {
|
||||
z += 4;
|
||||
}
|
||||
break;
|
||||
|
@ -706,7 +705,8 @@ static void porter_stemmer(
|
|||
}
|
||||
break;
|
||||
case 'l':
|
||||
if( z[0]=='e' && z[2]=='b' && (z[3]=='a' || z[3]=='i') && m_gt_1(z+4) ){
|
||||
if (z[0] == 'e' && z[2] == 'b' && (z[3] == 'a' || z[3] == 'i') &&
|
||||
m_gt_1(z + 4)) {
|
||||
z += 4;
|
||||
}
|
||||
break;
|
||||
|
@ -718,8 +718,7 @@ static void porter_stemmer(
|
|||
}
|
||||
} else if (z[2] == 'e') {
|
||||
(void)(stem(&z, "tneme", "", m_gt_1) ||
|
||||
stem(&z, "tnem", "", m_gt_1) ||
|
||||
stem(&z, "tne", "", m_gt_1));
|
||||
stem(&z, "tnem", "", m_gt_1) || stem(&z, "tne", "", m_gt_1));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -738,8 +737,7 @@ static void porter_stemmer(
|
|||
}
|
||||
break;
|
||||
case 't':
|
||||
(void) (stem(&z, "eta", "", m_gt_1) ||
|
||||
stem(&z, "iti", "", m_gt_1));
|
||||
(void)(stem(&z, "eta", "", m_gt_1) || stem(&z, "iti", "", m_gt_1));
|
||||
break;
|
||||
case 'u':
|
||||
if (z[0] == 's' && z[2] == 'o' && m_gt_1(z + 3)) {
|
||||
|
@ -803,7 +801,8 @@ static const char porterIdChar[] = {
|
|||
* 0x20 space. 0x205f is a "medium mathematical space" and defined as roughly
|
||||
* equivalent to an 0x20 space.
|
||||
*/
|
||||
#define IS_UNI_SPACE(x) (((x)>=0x2000&&(x)<=0x200a) || (x)==0x202f || (x)==0x205f)
|
||||
# define IS_UNI_SPACE(x) \
|
||||
(((x) >= 0x2000 && (x) <= 0x200a) || (x) == 0x202f || (x) == 0x205f)
|
||||
/**
|
||||
* What we are checking for:
|
||||
* - 0x3001: Ideographic comma (-> 0x2c ',')
|
||||
|
@ -815,7 +814,9 @@ static const char porterIdChar[] = {
|
|||
*
|
||||
* It is possible we should be treating other things as delimiters!
|
||||
*/
|
||||
#define IS_JA_DELIM(x) (((x)==0x3001)||((x)==0xFF64)||((x)==0xFF0E)||((x)==0x3002)||((x)==0xFF61)||((x)==0xFF0C))
|
||||
# define IS_JA_DELIM(x) \
|
||||
(((x) == 0x3001) || ((x) == 0xFF64) || ((x) == 0xFF0E) || \
|
||||
((x) == 0x3002) || ((x) == 0xFF61) || ((x) == 0xFF0C))
|
||||
|
||||
/**
|
||||
* The previous character was a delimiter (which includes the start of the
|
||||
|
@ -895,9 +896,7 @@ static int isDelim(
|
|||
// and U+1780-U+17FF is Khmer. It is no easy way to break each word.
|
||||
// So these should use bi-gram too.
|
||||
// cases: "aa", ".a", "&a"
|
||||
if (c < 0xe00 ||
|
||||
(c >= 0xf00 && c < 0x1780) ||
|
||||
(c >= 0x1800 && c < 0x2000)) {
|
||||
if (c < 0xe00 || (c >= 0xf00 && c < 0x1780) || (c >= 0x1800 && c < 0x2000)) {
|
||||
*state = BIGRAM_ALPHA; /* not really ASCII but same idea; tokenize it */
|
||||
return 0;
|
||||
}
|
||||
|
@ -1095,18 +1094,15 @@ static int porterNext(
|
|||
// otherwise, drop two-letter words (considered stop-words)
|
||||
(numChars >= 3) ||
|
||||
// wildcard case:
|
||||
(numChars == 1 && iStartOffset == 0 &&
|
||||
(c->iOffset >= 3) &&
|
||||
(c->iOffset == c->nInput - 1) &&
|
||||
(z[c->iOffset] == '*'))) {
|
||||
(numChars == 1 && iStartOffset == 0 && (c->iOffset >= 3) &&
|
||||
(c->iOffset == c->nInput - 1) && (z[c->iOffset] == '*'))) {
|
||||
/* figure out the number of bytes to copy/stem */
|
||||
int n = c->iOffset - iStartOffset;
|
||||
/* make sure there is enough buffer space */
|
||||
if (n * MAX_UTF8_GROWTH_FACTOR > c->nAllocated) {
|
||||
c->nAllocated = n * MAX_UTF8_GROWTH_FACTOR + 20;
|
||||
c->zToken = sqlite3_realloc(c->zToken, c->nAllocated);
|
||||
if (c->zToken == NULL)
|
||||
return SQLITE_NOMEM;
|
||||
if (c->zToken == NULL) return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
if (state == BIGRAM_USE) {
|
||||
|
@ -1129,12 +1125,7 @@ static int porterNext(
|
|||
** The set of routines that implement the porter-stemmer tokenizer
|
||||
*/
|
||||
static const sqlite3_tokenizer_module porterTokenizerModule = {
|
||||
0,
|
||||
porterCreate,
|
||||
porterDestroy,
|
||||
porterOpen,
|
||||
porterClose,
|
||||
porterNext,
|
||||
0, porterCreate, porterDestroy, porterOpen, porterClose, porterNext,
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -1142,8 +1133,7 @@ static const sqlite3_tokenizer_module porterTokenizerModule = {
|
|||
** tokenizer in *ppModule
|
||||
*/
|
||||
void sqlite3Fts3PorterTokenizerModule(
|
||||
sqlite3_tokenizer_module const**ppModule
|
||||
){
|
||||
sqlite3_tokenizer_module const **ppModule) {
|
||||
*ppModule = &porterTokenizerModule;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ typedef struct sqlite3_tokenizer sqlite3_tokenizer;
|
|||
typedef struct sqlite3_tokenizer_cursor sqlite3_tokenizer_cursor;
|
||||
|
||||
struct sqlite3_tokenizer_module {
|
||||
|
||||
/*
|
||||
** Structure version. Should always be set to 0.
|
||||
*/
|
||||
|
@ -73,8 +72,7 @@ struct sqlite3_tokenizer_module {
|
|||
** sqlite3_tokenizer.pModule variable should not be initialised by
|
||||
** this callback. The caller will do so.
|
||||
*/
|
||||
int (*xCreate)(
|
||||
int argc, /* Size of argv array */
|
||||
int (*xCreate)(int argc, /* Size of argv array */
|
||||
const char *const *argv, /* Tokenizer argument strings */
|
||||
sqlite3_tokenizer **ppTokenizer /* OUT: Created tokenizer */
|
||||
);
|
||||
|
|
|
@ -15,43 +15,34 @@
|
|||
extern "C" void sqlite3Fts3PorterTokenizerModule(
|
||||
sqlite3_tokenizer_module const **ppModule);
|
||||
|
||||
extern "C" void glodaRankFunc(sqlite3_context *pCtx,
|
||||
int nVal,
|
||||
extern "C" void glodaRankFunc(sqlite3_context *pCtx, int nVal,
|
||||
sqlite3_value **apVal);
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsFts3Tokenizer, nsIFts3Tokenizer)
|
||||
|
||||
nsFts3Tokenizer::nsFts3Tokenizer()
|
||||
{
|
||||
}
|
||||
nsFts3Tokenizer::nsFts3Tokenizer() {}
|
||||
|
||||
nsFts3Tokenizer::~nsFts3Tokenizer()
|
||||
{
|
||||
}
|
||||
nsFts3Tokenizer::~nsFts3Tokenizer() {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFts3Tokenizer::RegisterTokenizer(mozIStorageConnection *connection)
|
||||
{
|
||||
nsFts3Tokenizer::RegisterTokenizer(mozIStorageConnection *connection) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<mozIStorageStatement> selectStatement;
|
||||
|
||||
// -- register the tokenizer
|
||||
rv = connection->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT fts3_tokenizer(?1, ?2)"),
|
||||
rv = connection->CreateStatement(
|
||||
NS_LITERAL_CSTRING("SELECT fts3_tokenizer(?1, ?2)"),
|
||||
getter_AddRefs(selectStatement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
const sqlite3_tokenizer_module *module = nullptr;
|
||||
sqlite3Fts3PorterTokenizerModule(&module);
|
||||
if (!module)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!module) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = selectStatement->BindUTF8StringByIndex(
|
||||
0, NS_LITERAL_CSTRING("mozporter"));
|
||||
rv = selectStatement->BindUTF8StringByIndex(0,
|
||||
NS_LITERAL_CSTRING("mozporter"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = selectStatement->BindBlobByIndex(1,
|
||||
(uint8_t*)&module,
|
||||
sizeof(module));
|
||||
rv = selectStatement->BindBlobByIndex(1, (uint8_t *)&module, sizeof(module));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
bool hasMore;
|
||||
|
@ -61,11 +52,9 @@ nsFts3Tokenizer::RegisterTokenizer(mozIStorageConnection *connection)
|
|||
// -- register the ranking function
|
||||
nsCOMPtr<mozIStorageFunction> func = new nsGlodaRankerFunction();
|
||||
NS_ENSURE_TRUE(func, NS_ERROR_OUT_OF_MEMORY);
|
||||
rv = connection->CreateFunction(
|
||||
NS_LITERAL_CSTRING("glodaRank"),
|
||||
rv = connection->CreateFunction(NS_LITERAL_CSTRING("glodaRank"),
|
||||
-1, // variable argument support
|
||||
func
|
||||
);
|
||||
func);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return rv;
|
||||
|
|
|
@ -6,10 +6,12 @@
|
|||
#ifndef nsFts3TokenizerCID_h__
|
||||
#define nsFts3TokenizerCID_h__
|
||||
|
||||
#define NS_FTS3TOKENIZER_CONTRACTID \
|
||||
"@mozilla.org/messenger/fts3tokenizer;1"
|
||||
#define NS_FTS3TOKENIZER_CONTRACTID "@mozilla.org/messenger/fts3tokenizer;1"
|
||||
#define NS_FTS3TOKENIZER_CID \
|
||||
{ 0xa67d724d, 0x0015, 0x4e2e, \
|
||||
{ 0x8c, 0xad, 0xb8, 0x47, 0x75, 0x33, 0x09, 0x24 }}
|
||||
{ \
|
||||
0xa67d724d, 0x0015, 0x4e2e, { \
|
||||
0x8c, 0xad, 0xb8, 0x47, 0x75, 0x33, 0x09, 0x24 \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif /* nsFts3TokenizerCID_h__ */
|
||||
|
|
|
@ -17,13 +17,9 @@
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsGlodaRankerFunction, mozIStorageFunction)
|
||||
|
||||
nsGlodaRankerFunction::nsGlodaRankerFunction()
|
||||
{
|
||||
}
|
||||
nsGlodaRankerFunction::nsGlodaRankerFunction() {}
|
||||
|
||||
nsGlodaRankerFunction::~nsGlodaRankerFunction()
|
||||
{
|
||||
}
|
||||
nsGlodaRankerFunction::~nsGlodaRankerFunction() {}
|
||||
|
||||
static uint32_t COLUMN_SATURATION[] = {10, 1, 1, 1, 1};
|
||||
|
||||
|
@ -37,8 +33,7 @@ static uint32_t COLUMN_SATURATION[] = {10, 1, 1, 1, 1};
|
|||
*/
|
||||
NS_IMETHODIMP
|
||||
nsGlodaRankerFunction::OnFunctionCall(mozIStorageValueArray *aArguments,
|
||||
nsIVariant **_result)
|
||||
{
|
||||
nsIVariant **_result) {
|
||||
// all argument names are maintained from the original SQLite code.
|
||||
uint32_t nVal;
|
||||
nsresult rv = aArguments->GetNumEntries(&nVal);
|
||||
|
@ -50,16 +45,14 @@ nsGlodaRankerFunction::OnFunctionCall(mozIStorageValueArray *aArguments,
|
|||
* to contain the number of reportable phrases in the users full-text
|
||||
* query, and nCol to the number of columns in the table.
|
||||
*/
|
||||
if (nVal < 1)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
if (nVal < 1) return NS_ERROR_INVALID_ARG;
|
||||
|
||||
uint32_t lenArgsData;
|
||||
uint32_t *aArgsData = (uint32_t *)aArguments->AsSharedBlob(0, &lenArgsData);
|
||||
|
||||
uint32_t nPhrase = aArgsData[0];
|
||||
uint32_t nCol = aArgsData[1];
|
||||
if (nVal != (1 + nCol))
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
if (nVal != (1 + nCol)) return NS_ERROR_INVALID_ARG;
|
||||
|
||||
double score = 0.0;
|
||||
|
||||
|
@ -72,9 +65,9 @@ nsGlodaRankerFunction::OnFunctionCall(mozIStorageValueArray *aArguments,
|
|||
uint32_t nHitCount = aArgsData[2 + (iPhrase + 1) * nCol + iCol];
|
||||
double weight = aArguments->AsDouble(iCol + 1);
|
||||
if (nHitCount > 0) {
|
||||
score += (nHitCount > COLUMN_SATURATION[iCol]) ?
|
||||
(COLUMN_SATURATION[iCol] * weight) :
|
||||
(nHitCount * weight);
|
||||
score += (nHitCount > COLUMN_SATURATION[iCol])
|
||||
? (COLUMN_SATURATION[iCol] * weight)
|
||||
: (nHitCount * weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,9 +88,9 @@ nsGlodaRankerFunction::OnFunctionCall(mozIStorageValueArray *aArguments,
|
|||
uint32_t nHitCount = aPhraseinfo[3 * iCol];
|
||||
double weight = aArguments->AsDouble(iCol + 1);
|
||||
if (nHitCount > 0) {
|
||||
score += (nHitCount > COLUMN_SATURATION[iCol]) ?
|
||||
(COLUMN_SATURATION[iCol] * weight) :
|
||||
(nHitCount * weight);
|
||||
score += (nHitCount > COLUMN_SATURATION[iCol])
|
||||
? (COLUMN_SATURATION[iCol] * weight)
|
||||
: (nHitCount * weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,13 +11,13 @@
|
|||
* Basically a port of the example FTS3 ranking function to mozStorage's
|
||||
* view of the universe. This might get fancier at some point.
|
||||
*/
|
||||
class nsGlodaRankerFunction final : public mozIStorageFunction
|
||||
{
|
||||
class nsGlodaRankerFunction final : public mozIStorageFunction {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_MOZISTORAGEFUNCTION
|
||||
|
||||
nsGlodaRankerFunction();
|
||||
|
||||
private:
|
||||
~nsGlodaRankerFunction();
|
||||
};
|
||||
|
|
|
@ -24,54 +24,49 @@
|
|||
#define kDefaultViewNotJunk "Not Junk"
|
||||
#define kDefaultViewHasAttachments "Has Attachments"
|
||||
|
||||
nsMsgMailView::nsMsgMailView()
|
||||
{
|
||||
nsMsgMailView::nsMsgMailView() {
|
||||
mViewSearchTerms = nsArray::Create();
|
||||
NS_ASSERTION(mViewSearchTerms, "Failed to allocate a nsIMutableArray for mViewSearchTerms");
|
||||
NS_ASSERTION(mViewSearchTerms,
|
||||
"Failed to allocate a nsIMutableArray for mViewSearchTerms");
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsMsgMailView)
|
||||
NS_IMPL_RELEASE(nsMsgMailView)
|
||||
NS_IMPL_QUERY_INTERFACE(nsMsgMailView, nsIMsgMailView)
|
||||
|
||||
nsMsgMailView::~nsMsgMailView()
|
||||
{
|
||||
if (mViewSearchTerms)
|
||||
mViewSearchTerms->Clear();
|
||||
nsMsgMailView::~nsMsgMailView() {
|
||||
if (mViewSearchTerms) mViewSearchTerms->Clear();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailView::GetMailViewName(char16_t ** aMailViewName)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailView::GetMailViewName(char16_t **aMailViewName) {
|
||||
NS_ENSURE_ARG_POINTER(aMailViewName);
|
||||
|
||||
*aMailViewName = ToNewUnicode(mName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailView::SetMailViewName(const char16_t * aMailViewName)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailView::SetMailViewName(const char16_t *aMailViewName) {
|
||||
mName = aMailViewName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailView::GetPrettyName(char16_t ** aMailViewName)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailView::GetPrettyName(char16_t **aMailViewName) {
|
||||
NS_ENSURE_ARG_POINTER(aMailViewName);
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (!mBundle)
|
||||
{
|
||||
if (!mBundle) {
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
mozilla::services::GetStringBundleService();
|
||||
NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
|
||||
bundleService->CreateBundle("chrome://messenger/locale/mailviews.properties",
|
||||
bundleService->CreateBundle(
|
||||
"chrome://messenger/locale/mailviews.properties",
|
||||
getter_AddRefs(mBundle));
|
||||
}
|
||||
|
||||
NS_ENSURE_TRUE(mBundle, NS_ERROR_FAILURE);
|
||||
|
||||
// see if mName has an associated pretty name inside our string bundle and if so, use that as the pretty name
|
||||
// otherwise just return mName
|
||||
// see if mName has an associated pretty name inside our string bundle and if
|
||||
// so, use that as the pretty name otherwise just return mName
|
||||
nsAutoString mailViewName;
|
||||
if (mName.EqualsLiteral(kDefaultViewPeopleIKnow)) {
|
||||
rv = mBundle->GetStringFromName("mailViewPeopleIKnow", mailViewName);
|
||||
|
@ -95,30 +90,27 @@ NS_IMETHODIMP nsMsgMailView::GetPrettyName(char16_t ** aMailViewName)
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailView::GetSearchTerms(nsIMutableArray **aSearchTerms)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailView::GetSearchTerms(nsIMutableArray **aSearchTerms) {
|
||||
NS_ENSURE_ARG_POINTER(aSearchTerms);
|
||||
NS_IF_ADDREF(*aSearchTerms = mViewSearchTerms);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailView::SetSearchTerms(nsIMutableArray *aSearchTerms)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailView::SetSearchTerms(nsIMutableArray *aSearchTerms) {
|
||||
mViewSearchTerms = aSearchTerms;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailView::AppendTerm(nsIMsgSearchTerm *aTerm)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailView::AppendTerm(nsIMsgSearchTerm *aTerm) {
|
||||
NS_ENSURE_TRUE(aTerm, NS_ERROR_NULL_POINTER);
|
||||
|
||||
return mViewSearchTerms->AppendElement(aTerm);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailView::CreateTerm(nsIMsgSearchTerm **aResult)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailView::CreateTerm(nsIMsgSearchTerm **aResult) {
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
nsCOMPtr<nsIMsgSearchTerm> searchTerm = do_CreateInstance("@mozilla.org/messenger/searchTerm;1");
|
||||
nsCOMPtr<nsIMsgSearchTerm> searchTerm =
|
||||
do_CreateInstance("@mozilla.org/messenger/searchTerm;1");
|
||||
searchTerm.forget(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -126,30 +118,23 @@ NS_IMETHODIMP nsMsgMailView::CreateTerm(nsIMsgSearchTerm **aResult)
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// nsMsgMailViewList implementation
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
nsMsgMailViewList::nsMsgMailViewList()
|
||||
{
|
||||
LoadMailViews();
|
||||
}
|
||||
nsMsgMailViewList::nsMsgMailViewList() { LoadMailViews(); }
|
||||
|
||||
NS_IMPL_ADDREF(nsMsgMailViewList)
|
||||
NS_IMPL_RELEASE(nsMsgMailViewList)
|
||||
NS_IMPL_QUERY_INTERFACE(nsMsgMailViewList, nsIMsgMailViewList)
|
||||
|
||||
nsMsgMailViewList::~nsMsgMailViewList()
|
||||
{
|
||||
nsMsgMailViewList::~nsMsgMailViewList() {}
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailViewList::GetMailViewCount(uint32_t * aCount)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailViewList::GetMailViewCount(uint32_t *aCount) {
|
||||
NS_ENSURE_ARG_POINTER(aCount);
|
||||
|
||||
*aCount = m_mailViews.Length();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailViewList::GetMailViewAt(uint32_t aMailViewIndex, nsIMsgMailView ** aMailView)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailViewList::GetMailViewAt(uint32_t aMailViewIndex,
|
||||
nsIMsgMailView **aMailView) {
|
||||
NS_ENSURE_ARG_POINTER(aMailView);
|
||||
|
||||
uint32_t mailViewCount = m_mailViews.Length();
|
||||
|
@ -160,39 +145,33 @@ NS_IMETHODIMP nsMsgMailViewList::GetMailViewAt(uint32_t aMailViewIndex, nsIMsgMa
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailViewList::AddMailView(nsIMsgMailView * aMailView)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailViewList::AddMailView(nsIMsgMailView *aMailView) {
|
||||
NS_ENSURE_ARG_POINTER(aMailView);
|
||||
|
||||
m_mailViews.AppendElement(aMailView);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailViewList::RemoveMailView(nsIMsgMailView * aMailView)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailViewList::RemoveMailView(nsIMsgMailView *aMailView) {
|
||||
NS_ENSURE_ARG_POINTER(aMailView);
|
||||
|
||||
m_mailViews.RemoveElement(aMailView);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailViewList::CreateMailView(nsIMsgMailView ** aMailView)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgMailViewList::CreateMailView(nsIMsgMailView **aMailView) {
|
||||
NS_ENSURE_ARG_POINTER(aMailView);
|
||||
NS_ADDREF(*aMailView = new nsMsgMailView);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailViewList::Save()
|
||||
{
|
||||
// brute force...remove all the old filters in our filter list, then we'll re-add our current
|
||||
// list
|
||||
NS_IMETHODIMP nsMsgMailViewList::Save() {
|
||||
// brute force...remove all the old filters in our filter list, then we'll
|
||||
// re-add our current list
|
||||
nsCOMPtr<nsIMsgFilter> msgFilter;
|
||||
uint32_t numFilters = 0;
|
||||
if (mFilterList)
|
||||
mFilterList->GetFilterCount(&numFilters);
|
||||
while (numFilters)
|
||||
{
|
||||
if (mFilterList) mFilterList->GetFilterCount(&numFilters);
|
||||
while (numFilters) {
|
||||
mFilterList->RemoveFilterAt(numFilters - 1);
|
||||
numFilters--;
|
||||
}
|
||||
|
@ -204,21 +183,17 @@ NS_IMETHODIMP nsMsgMailViewList::Save()
|
|||
return mFilterList ? mFilterList->SaveToDefaultFile() : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsMsgMailViewList::ConvertMailViewListToFilterList()
|
||||
{
|
||||
nsresult nsMsgMailViewList::ConvertMailViewListToFilterList() {
|
||||
uint32_t mailViewCount = m_mailViews.Length();
|
||||
nsCOMPtr<nsIMsgMailView> mailView;
|
||||
nsCOMPtr<nsIMsgFilter> newMailFilter;
|
||||
nsString mailViewName;
|
||||
for (uint32_t index = 0; index < mailViewCount; index++)
|
||||
{
|
||||
for (uint32_t index = 0; index < mailViewCount; index++) {
|
||||
GetMailViewAt(index, getter_AddRefs(mailView));
|
||||
if (!mailView)
|
||||
continue;
|
||||
if (!mailView) continue;
|
||||
mailView->GetMailViewName(getter_Copies(mailViewName));
|
||||
mFilterList->CreateFilter(mailViewName, getter_AddRefs(newMailFilter));
|
||||
if (!newMailFilter)
|
||||
continue;
|
||||
if (!newMailFilter) continue;
|
||||
|
||||
nsCOMPtr<nsIMutableArray> searchTerms;
|
||||
mailView->GetSearchTerms(getter_AddRefs(searchTerms));
|
||||
|
@ -229,41 +204,47 @@ nsresult nsMsgMailViewList::ConvertMailViewListToFilterList()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgMailViewList::LoadMailViews()
|
||||
{
|
||||
nsresult nsMsgMailViewList::LoadMailViews() {
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file));
|
||||
nsresult rv =
|
||||
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = file->AppendNative(nsDependentCString("mailViews.dat"));
|
||||
|
||||
// if the file doesn't exist, we should try to get it from the defaults directory and copy it over
|
||||
// if the file doesn't exist, we should try to get it from the defaults
|
||||
// directory and copy it over
|
||||
bool exists = false;
|
||||
file->Exists(&exists);
|
||||
if (!exists)
|
||||
{
|
||||
nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
|
||||
if (!exists) {
|
||||
nsCOMPtr<nsIMsgMailSession> mailSession =
|
||||
do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIFile> defaultMessagesFile;
|
||||
nsCOMPtr<nsIFile> profileDir;
|
||||
rv = mailSession->GetDataFilesDir("messenger", getter_AddRefs(defaultMessagesFile));
|
||||
rv = mailSession->GetDataFilesDir("messenger",
|
||||
getter_AddRefs(defaultMessagesFile));
|
||||
rv = defaultMessagesFile->AppendNative(nsDependentCString("mailViews.dat"));
|
||||
|
||||
// get the profile directory
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir));
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
|
||||
getter_AddRefs(profileDir));
|
||||
|
||||
// now copy the file over to the profile directory
|
||||
defaultMessagesFile->CopyToNative(profileDir, EmptyCString());
|
||||
}
|
||||
// this is kind of a hack but I think it will be an effective hack. The filter service already knows how to
|
||||
// take a nsIFile and parse the contents into filters which are very similar to mail views. Instead of
|
||||
// re-writing all of that dirty parsing code, let's just re-use it then convert the results into a data strcuture
|
||||
// we wish to give to our consumers.
|
||||
// this is kind of a hack but I think it will be an effective hack. The filter
|
||||
// service already knows how to take a nsIFile and parse the contents into
|
||||
// filters which are very similar to mail views. Instead of re-writing all of
|
||||
// that dirty parsing code, let's just re-use it then convert the results into
|
||||
// a data strcuture we wish to give to our consumers.
|
||||
|
||||
nsCOMPtr<nsIMsgFilterService> filterService = do_GetService(NS_MSGFILTERSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIMsgFilterService> filterService =
|
||||
do_GetService(NS_MSGFILTERSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIMsgFilterList> mfilterList;
|
||||
|
||||
rv = filterService->OpenFilterList(file, nullptr, nullptr, getter_AddRefs(mFilterList));
|
||||
rv = filterService->OpenFilterList(file, nullptr, nullptr,
|
||||
getter_AddRefs(mFilterList));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return ConvertFilterListToMailViews();
|
||||
|
@ -272,20 +253,17 @@ nsresult nsMsgMailViewList::LoadMailViews()
|
|||
* Converts the filter list into our mail view objects,
|
||||
* stripping out just the info we need.
|
||||
*/
|
||||
nsresult nsMsgMailViewList::ConvertFilterListToMailViews()
|
||||
{
|
||||
nsresult nsMsgMailViewList::ConvertFilterListToMailViews() {
|
||||
nsresult rv = NS_OK;
|
||||
m_mailViews.Clear();
|
||||
|
||||
// iterate over each filter in the list
|
||||
uint32_t numFilters = 0;
|
||||
mFilterList->GetFilterCount(&numFilters);
|
||||
for (uint32_t index = 0; index < numFilters; index++)
|
||||
{
|
||||
for (uint32_t index = 0; index < numFilters; index++) {
|
||||
nsCOMPtr<nsIMsgFilter> msgFilter;
|
||||
rv = mFilterList->GetFilterAt(index, getter_AddRefs(msgFilter));
|
||||
if (NS_FAILED(rv) || !msgFilter)
|
||||
continue;
|
||||
if (NS_FAILED(rv) || !msgFilter) continue;
|
||||
|
||||
// create a new nsIMsgMailView for this item
|
||||
nsCOMPtr<nsIMsgMailView> newMailView;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* 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 _nsMsgMailViewList_H_
|
||||
#define _nsMsgMailViewList_H_
|
||||
|
||||
|
@ -17,8 +16,7 @@
|
|||
#include "nsIMsgFilterList.h"
|
||||
|
||||
// a mail View is just a name and an array of search terms
|
||||
class nsMsgMailView : public nsIMsgMailView
|
||||
{
|
||||
class nsMsgMailView : public nsIMsgMailView {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMSGMAILVIEW
|
||||
|
@ -32,9 +30,7 @@ protected:
|
|||
nsCOMPtr<nsIMutableArray> mViewSearchTerms;
|
||||
};
|
||||
|
||||
|
||||
class nsMsgMailViewList : public nsIMsgMailViewList
|
||||
{
|
||||
class nsMsgMailViewList : public nsIMsgMailViewList {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMSGMAILVIEWLIST
|
||||
|
@ -43,12 +39,14 @@ public:
|
|||
|
||||
protected:
|
||||
virtual ~nsMsgMailViewList();
|
||||
nsresult LoadMailViews(); // reads in user defined mail views from our default file
|
||||
nsresult
|
||||
LoadMailViews(); // reads in user defined mail views from our default file
|
||||
nsresult ConvertFilterListToMailViews();
|
||||
nsresult ConvertMailViewListToFilterList();
|
||||
|
||||
nsCOMArray<nsIMsgMailView> m_mailViews;
|
||||
nsCOMPtr<nsIMsgFilterList> mFilterList; // our internal filter list representation
|
||||
nsCOMPtr<nsIMsgFilterList>
|
||||
mFilterList; // our internal filter list representation
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
#ifndef nsMsgMailViewsCID_h__
|
||||
#define nsMsgMailViewsCID_h__
|
||||
|
||||
#define NS_MSGMAILVIEWLIST_CONTRACTID \
|
||||
"@mozilla.org/messenger/mailviewlist;1"
|
||||
#define NS_MSGMAILVIEWLIST_CONTRACTID "@mozilla.org/messenger/mailviewlist;1"
|
||||
|
||||
#define NS_MSGMAILVIEWLIST_CID \
|
||||
{ /* A0258267-44FD-4886-A858-8192615178EC */ \
|
||||
0xa0258267, 0x44fd, 0x4886, \
|
||||
{ 0xa8, 0x58, 0x81, 0x92, 0x61, 0x51, 0x78, 0xec }}
|
||||
0xa0258267, 0x44fd, 0x4886, { \
|
||||
0xa8, 0x58, 0x81, 0x92, 0x61, 0x51, 0x78, 0xec \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif /* nsMsgMailViewsCID_h__*/
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
#ifndef nsMsgMdnCID_h__
|
||||
#define nsMsgMdnCID_h__
|
||||
|
||||
#define NS_MSGMDNGENERATOR_CONTRACTID \
|
||||
"@mozilla.org/messenger-mdn/generator;1"
|
||||
#define NS_MSGMDNGENERATOR_CONTRACTID "@mozilla.org/messenger-mdn/generator;1"
|
||||
#define NS_MSGMDNGENERATOR_CID \
|
||||
{ /* ec917b13-8f73-4d4d-9146-d7f7aafe9076 */ \
|
||||
0xec917b13, 0x8f73, 0x4d4d, \
|
||||
{ 0x91, 0x46, 0xd7, 0xf7, 0xaa, 0xfe, 0x90, 0x76 }}
|
||||
0xec917b13, 0x8f73, 0x4d4d, { \
|
||||
0x91, 0x46, 0xd7, 0xf7, 0xaa, 0xfe, 0x90, 0x76 \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif /* nsMsgMdnCID_h__ */
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -23,8 +23,7 @@
|
|||
#define eAskMeOp ((int32_t)2)
|
||||
#define eDeniedOp ((int32_t)3)
|
||||
|
||||
class nsMsgMdnGenerator : public nsIMsgMdnGenerator, public nsIUrlListener
|
||||
{
|
||||
class nsMsgMdnGenerator : public nsIMsgMdnGenerator, public nsIUrlListener {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMSGMDNGENERATOR
|
||||
|
@ -53,8 +52,7 @@ private:
|
|||
|
||||
// string bundle helper methods
|
||||
nsresult GetStringFromName(const char *aName, nsAString &aResultString);
|
||||
nsresult FormatStringFromName(const char *aName,
|
||||
const char16_t *aString,
|
||||
nsresult FormatStringFromName(const char *aName, const char16_t *aString,
|
||||
nsAString &aResultString);
|
||||
|
||||
// other helper methods
|
||||
|
@ -87,4 +85,3 @@ private:
|
|||
};
|
||||
|
||||
#endif // _nsMsgMdnGenerator_H_
|
||||
|
||||
|
|
|
@ -28,12 +28,10 @@
|
|||
using namespace mozilla;
|
||||
|
||||
MOZ_TYPE_SPECIFIC_UNIQUE_PTR_TEMPLATE(UniqueCERTCertNicknames,
|
||||
CERTCertNicknames,
|
||||
CERT_FreeNicknames)
|
||||
CERTCertNicknames, CERT_FreeNicknames)
|
||||
|
||||
CERTCertNicknames*
|
||||
getNSSCertNicknamesFromCertList(const UniqueCERTCertList& certList)
|
||||
{
|
||||
CERTCertNicknames *getNSSCertNicknamesFromCertList(
|
||||
const UniqueCERTCertList &certList) {
|
||||
nsAutoString expiredString, notYetValidString;
|
||||
nsAutoString expiredStringLeadingSpace, notYetValidStringLeadingSpace;
|
||||
|
||||
|
@ -49,15 +47,13 @@ getNSSCertNicknamesFromCertList(const UniqueCERTCertList& certList)
|
|||
NS_ConvertUTF16toUTF8 aUtf8ExpiredString(expiredStringLeadingSpace);
|
||||
NS_ConvertUTF16toUTF8 aUtf8NotYetValidString(notYetValidStringLeadingSpace);
|
||||
|
||||
return CERT_NicknameStringsFromCertList(certList.get(),
|
||||
const_cast<char*>(aUtf8ExpiredString.get()),
|
||||
return CERT_NicknameStringsFromCertList(
|
||||
certList.get(), const_cast<char *>(aUtf8ExpiredString.get()),
|
||||
const_cast<char *>(aUtf8NotYetValidString.get()));
|
||||
}
|
||||
|
||||
nsresult
|
||||
FormatUIStrings(nsIX509Cert* cert, const nsAutoString& nickname,
|
||||
nsAutoString& nickWithSerial, nsAutoString& details)
|
||||
{
|
||||
nsresult FormatUIStrings(nsIX509Cert *cert, const nsAutoString &nickname,
|
||||
nsAutoString &nickWithSerial, nsAutoString &details) {
|
||||
if (!NS_IsMainThread()) {
|
||||
NS_ERROR("nsNSSCertificate::FormatUIStrings called off the main thread");
|
||||
return NS_ERROR_NOT_SAME_THREAD;
|
||||
|
@ -105,7 +101,8 @@ FormatUIStrings(nsIX509Cert* cert, const nsAutoString& nickname,
|
|||
details.Append(info);
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(validity->GetNotBeforeLocalTime(temp1)) && !temp1.IsEmpty()) {
|
||||
if (NS_SUCCEEDED(validity->GetNotBeforeLocalTime(temp1)) &&
|
||||
!temp1.IsEmpty()) {
|
||||
details.Append(char16_t(' '));
|
||||
if (NS_SUCCEEDED(mcs->GetSMIMEBundleString(u"CertInfoFrom", info))) {
|
||||
details.Append(info);
|
||||
|
@ -114,7 +111,8 @@ FormatUIStrings(nsIX509Cert* cert, const nsAutoString& nickname,
|
|||
details.Append(temp1);
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(validity->GetNotAfterLocalTime(temp1)) && !temp1.IsEmpty()) {
|
||||
if (NS_SUCCEEDED(validity->GetNotAfterLocalTime(temp1)) &&
|
||||
!temp1.IsEmpty()) {
|
||||
details.Append(char16_t(' '));
|
||||
if (NS_SUCCEEDED(mcs->GetSMIMEBundleString(u"CertInfoTo", info))) {
|
||||
details.Append(info);
|
||||
|
@ -143,15 +141,10 @@ FormatUIStrings(nsIX509Cert* cert, const nsAutoString& nickname,
|
|||
|
||||
nsAutoString firstEmail;
|
||||
const char *aWalkAddr;
|
||||
for (aWalkAddr = CERT_GetFirstEmailAddress(nssCert.get())
|
||||
;
|
||||
aWalkAddr
|
||||
;
|
||||
aWalkAddr = CERT_GetNextEmailAddress(nssCert.get(), aWalkAddr))
|
||||
{
|
||||
for (aWalkAddr = CERT_GetFirstEmailAddress(nssCert.get()); aWalkAddr;
|
||||
aWalkAddr = CERT_GetNextEmailAddress(nssCert.get(), aWalkAddr)) {
|
||||
NS_ConvertUTF8toUTF16 email(aWalkAddr);
|
||||
if (email.IsEmpty())
|
||||
continue;
|
||||
if (email.IsEmpty()) continue;
|
||||
|
||||
if (firstEmail.IsEmpty()) {
|
||||
// If the first email address from the subject DN is also present
|
||||
|
@ -166,8 +159,7 @@ FormatUIStrings(nsIX509Cert* cert, const nsAutoString& nickname,
|
|||
details.AppendLiteral(": ");
|
||||
}
|
||||
details.Append(email);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Append current address if it's different from the first one.
|
||||
if (!firstEmail.Equals(email)) {
|
||||
details.AppendLiteral(", ");
|
||||
|
@ -216,17 +208,11 @@ FormatUIStrings(nsIX509Cert* cert, const nsAutoString& nickname,
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsCertPicker, nsICertPickDialogs, nsIUserCertPicker)
|
||||
|
||||
nsCertPicker::nsCertPicker()
|
||||
{
|
||||
}
|
||||
nsCertPicker::nsCertPicker() {}
|
||||
|
||||
nsCertPicker::~nsCertPicker()
|
||||
{
|
||||
}
|
||||
nsCertPicker::~nsCertPicker() {}
|
||||
|
||||
nsresult
|
||||
nsCertPicker::Init()
|
||||
{
|
||||
nsresult nsCertPicker::Init() {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISupports> psm = do_GetService("@mozilla.org/psm;1", &rv);
|
||||
return rv;
|
||||
|
@ -235,11 +221,8 @@ nsCertPicker::Init()
|
|||
NS_IMETHODIMP
|
||||
nsCertPicker::PickCertificate(nsIInterfaceRequestor *ctx,
|
||||
const char16_t **certNickList,
|
||||
const char16_t **certDetailsList,
|
||||
uint32_t count,
|
||||
int32_t *selectedIndex,
|
||||
bool *canceled)
|
||||
{
|
||||
const char16_t **certDetailsList, uint32_t count,
|
||||
int32_t *selectedIndex, bool *canceled) {
|
||||
nsresult rv;
|
||||
uint32_t i;
|
||||
|
||||
|
@ -267,9 +250,8 @@ nsCertPicker::PickCertificate(nsIInterfaceRequestor *ctx,
|
|||
rv = block->SetInt(1, *selectedIndex);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = nsNSSDialogHelper::openDialog(nullptr,
|
||||
"chrome://messenger/content/certpicker.xul",
|
||||
block);
|
||||
rv = nsNSSDialogHelper::openDialog(
|
||||
nullptr, "chrome://messenger/content/certpicker.xul", block);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
int32_t status;
|
||||
|
@ -286,13 +268,10 @@ nsCertPicker::PickCertificate(nsIInterfaceRequestor *ctx,
|
|||
|
||||
NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx,
|
||||
const char16_t *selectedNickname,
|
||||
int32_t certUsage,
|
||||
bool allowInvalid,
|
||||
int32_t certUsage, bool allowInvalid,
|
||||
bool allowDuplicateNicknames,
|
||||
const nsAString &emailAddress,
|
||||
bool *canceled,
|
||||
nsIX509Cert **_retval)
|
||||
{
|
||||
bool *canceled, nsIX509Cert **_retval) {
|
||||
int32_t selectedIndex = -1;
|
||||
bool selectionFound = false;
|
||||
char16_t **certNicknameList = nullptr;
|
||||
|
@ -301,19 +280,17 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx,
|
|||
nsresult rv = NS_OK;
|
||||
|
||||
{
|
||||
// Iterate over all certs. This assures that user is logged in to all hardware tokens.
|
||||
// Iterate over all certs. This assures that user is logged in to all
|
||||
// hardware tokens.
|
||||
nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext();
|
||||
UniqueCERTCertList allcerts(PK11_ListCerts(PK11CertListUnique, ctx));
|
||||
}
|
||||
|
||||
/* find all user certs that are valid for the specified usage */
|
||||
/* note that we are allowing expired certs in this list */
|
||||
UniqueCERTCertList certList(
|
||||
CERT_FindUserCertsByUsage(CERT_GetDefaultCertDB(),
|
||||
(SECCertUsage)certUsage,
|
||||
!allowDuplicateNicknames,
|
||||
!allowInvalid,
|
||||
ctx));
|
||||
UniqueCERTCertList certList(CERT_FindUserCertsByUsage(
|
||||
CERT_GetDefaultCertDB(), (SECCertUsage)certUsage,
|
||||
!allowDuplicateNicknames, !allowInvalid, ctx));
|
||||
if (!certList) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
@ -349,8 +326,10 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx,
|
|||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
certNicknameList = (char16_t **)moz_xmalloc(sizeof(char16_t *) * nicknames->numnicknames);
|
||||
certDetailsList = (char16_t **)moz_xmalloc(sizeof(char16_t *) * nicknames->numnicknames);
|
||||
certNicknameList =
|
||||
(char16_t **)moz_xmalloc(sizeof(char16_t *) * nicknames->numnicknames);
|
||||
certDetailsList =
|
||||
(char16_t **)moz_xmalloc(sizeof(char16_t *) * nicknames->numnicknames);
|
||||
|
||||
if (!certNicknameList || !certDetailsList) {
|
||||
free(certNicknameList);
|
||||
|
@ -363,14 +342,12 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx,
|
|||
for (CertsToUse = 0, node = CERT_LIST_HEAD(certList.get());
|
||||
!CERT_LIST_END(node, certList.get()) &&
|
||||
CertsToUse < nicknames->numnicknames;
|
||||
node = CERT_LIST_NEXT(node)
|
||||
)
|
||||
{
|
||||
node = CERT_LIST_NEXT(node)) {
|
||||
RefPtr<nsNSSCertificate> tempCert(nsNSSCertificate::Create(node->cert));
|
||||
|
||||
if (tempCert) {
|
||||
|
||||
nsAutoString i_nickname(NS_ConvertUTF8toUTF16(nicknames->nicknames[CertsToUse]));
|
||||
nsAutoString i_nickname(
|
||||
NS_ConvertUTF8toUTF16(nicknames->nicknames[CertsToUse]));
|
||||
nsAutoString nickWithSerial;
|
||||
nsAutoString details;
|
||||
|
||||
|
@ -382,8 +359,8 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx,
|
|||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(FormatUIStrings(tempCert, i_nickname, nickWithSerial,
|
||||
details))) {
|
||||
if (NS_SUCCEEDED(
|
||||
FormatUIStrings(tempCert, i_nickname, nickWithSerial, details))) {
|
||||
certNicknameList[CertsToUse] = ToNewUnicode(nickWithSerial);
|
||||
certDetailsList[CertsToUse] = ToNewUnicode(details);
|
||||
if (!selectionFound) {
|
||||
|
@ -393,8 +370,7 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx,
|
|||
selectionFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
certNicknameList[CertsToUse] = nullptr;
|
||||
certDetailsList[CertsToUse] = nullptr;
|
||||
}
|
||||
|
@ -429,10 +405,8 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx,
|
|||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && !*canceled) {
|
||||
for (i = 0, node = CERT_LIST_HEAD(certList);
|
||||
!CERT_LIST_END(node, certList);
|
||||
for (i = 0, node = CERT_LIST_HEAD(certList); !CERT_LIST_END(node, certList);
|
||||
++i, node = CERT_LIST_NEXT(node)) {
|
||||
|
||||
if (i == selectedIndex) {
|
||||
RefPtr<nsNSSCertificate> cert = nsNSSCertificate::Create(node->cert);
|
||||
if (!cert) {
|
||||
|
|
|
@ -10,11 +10,13 @@
|
|||
#include "nsIUserCertPicker.h"
|
||||
|
||||
#define NS_CERT_PICKER_CID \
|
||||
{ 0x735959a1, 0xaf01, 0x447e, { 0xb0, 0x2d, 0x56, 0xe9, 0x68, 0xfa, 0x52, 0xb4 } }
|
||||
{ \
|
||||
0x735959a1, 0xaf01, 0x447e, { \
|
||||
0xb0, 0x2d, 0x56, 0xe9, 0x68, 0xfa, 0x52, 0xb4 \
|
||||
} \
|
||||
}
|
||||
|
||||
class nsCertPicker : public nsICertPickDialogs
|
||||
, public nsIUserCertPicker
|
||||
{
|
||||
class nsCertPicker : public nsICertPickDialogs, public nsIUserCertPicker {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICERTPICKDIALOGS
|
||||
|
|
|
@ -6,31 +6,27 @@
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsEncryptedSMIMEURIsService, nsIEncryptedSMIMEURIsService)
|
||||
|
||||
nsEncryptedSMIMEURIsService::nsEncryptedSMIMEURIsService()
|
||||
{
|
||||
}
|
||||
nsEncryptedSMIMEURIsService::nsEncryptedSMIMEURIsService() {}
|
||||
|
||||
nsEncryptedSMIMEURIsService::~nsEncryptedSMIMEURIsService()
|
||||
{
|
||||
}
|
||||
nsEncryptedSMIMEURIsService::~nsEncryptedSMIMEURIsService() {}
|
||||
|
||||
NS_IMETHODIMP nsEncryptedSMIMEURIsService::RememberEncrypted(const nsACString & uri)
|
||||
{
|
||||
NS_IMETHODIMP nsEncryptedSMIMEURIsService::RememberEncrypted(
|
||||
const nsACString &uri) {
|
||||
// Assuming duplicates are allowed.
|
||||
mEncryptedURIs.AppendElement(uri);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEncryptedSMIMEURIsService::ForgetEncrypted(const nsACString & uri)
|
||||
{
|
||||
NS_IMETHODIMP nsEncryptedSMIMEURIsService::ForgetEncrypted(
|
||||
const nsACString &uri) {
|
||||
// Assuming, this will only remove one copy of the string, if the array
|
||||
// contains multiple copies of the same string.
|
||||
mEncryptedURIs.RemoveElement(uri);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEncryptedSMIMEURIsService::IsEncrypted(const nsACString & uri, bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsEncryptedSMIMEURIsService::IsEncrypted(const nsACString &uri,
|
||||
bool *_retval) {
|
||||
*_retval = mEncryptedURIs.Contains(uri);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -9,8 +9,7 @@
|
|||
#include "nsTArray.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsEncryptedSMIMEURIsService : public nsIEncryptedSMIMEURIsService
|
||||
{
|
||||
class nsEncryptedSMIMEURIsService : public nsIEncryptedSMIMEURIsService {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIENCRYPTEDSMIMEURISSERVICE
|
||||
|
|
|
@ -41,7 +41,8 @@ using namespace mozilla::psm;
|
|||
// displayed only if the MUA doesn't support MIME.
|
||||
// We need to consider what to do in case the server doesn't support 8BITMIME.
|
||||
// In short, we can't use non-ASCII characters here.
|
||||
static const char crypto_multipart_blurb[] = "This is a cryptographically signed message in MIME format.";
|
||||
static const char crypto_multipart_blurb[] =
|
||||
"This is a cryptographically signed message in MIME format.";
|
||||
|
||||
static void mime_crypto_write_base64(void *closure, const char *buf,
|
||||
unsigned long size);
|
||||
|
@ -55,43 +56,35 @@ static nsresult make_multipart_signed_header_string(bool outer_p,
|
|||
int16_t hash_type);
|
||||
static char *mime_make_separator(const char *prefix);
|
||||
|
||||
|
||||
static void
|
||||
GenerateGlobalRandomBytes(unsigned char *buf, int32_t len)
|
||||
{
|
||||
static void GenerateGlobalRandomBytes(unsigned char *buf, int32_t len) {
|
||||
static bool firstTime = true;
|
||||
|
||||
if (firstTime)
|
||||
{
|
||||
if (firstTime) {
|
||||
// Seed the random-number generator with current time so that
|
||||
// the numbers will be different every time we run.
|
||||
srand((unsigned)PR_Now());
|
||||
firstTime = false;
|
||||
}
|
||||
|
||||
for( int32_t i = 0; i < len; i++ )
|
||||
buf[i] = rand() % 10;
|
||||
for (int32_t i = 0; i < len; i++) buf[i] = rand() % 10;
|
||||
}
|
||||
|
||||
char
|
||||
*mime_make_separator(const char *prefix)
|
||||
{
|
||||
char *mime_make_separator(const char *prefix) {
|
||||
unsigned char rand_buf[13];
|
||||
GenerateGlobalRandomBytes(rand_buf, 12);
|
||||
|
||||
return PR_smprintf("------------%s"
|
||||
return PR_smprintf(
|
||||
"------------%s"
|
||||
"%02X%02X%02X%02X"
|
||||
"%02X%02X%02X%02X"
|
||||
"%02X%02X%02X%02X",
|
||||
prefix,
|
||||
rand_buf[0], rand_buf[1], rand_buf[2], rand_buf[3],
|
||||
rand_buf[4], rand_buf[5], rand_buf[6], rand_buf[7],
|
||||
rand_buf[8], rand_buf[9], rand_buf[10], rand_buf[11]);
|
||||
prefix, rand_buf[0], rand_buf[1], rand_buf[2], rand_buf[3], rand_buf[4],
|
||||
rand_buf[5], rand_buf[6], rand_buf[7], rand_buf[8], rand_buf[9],
|
||||
rand_buf[10], rand_buf[11]);
|
||||
}
|
||||
|
||||
// end of copied code which needs fixed....
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of nsMsgComposeSecure
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -99,8 +92,7 @@ char
|
|||
NS_IMPL_ISUPPORTS(nsMsgComposeSecure, nsIMsgComposeSecure)
|
||||
|
||||
nsMsgComposeSecure::nsMsgComposeSecure()
|
||||
:mSignMessage(false), mAlwaysEncryptMessage(false)
|
||||
{
|
||||
: mSignMessage(false), mAlwaysEncryptMessage(false) {
|
||||
/* member initializers and constructor code */
|
||||
mMultipartSignedBoundary = 0;
|
||||
mBuffer = 0;
|
||||
|
@ -108,8 +100,7 @@ nsMsgComposeSecure::nsMsgComposeSecure()
|
|||
mHashType = 0;
|
||||
}
|
||||
|
||||
nsMsgComposeSecure::~nsMsgComposeSecure()
|
||||
{
|
||||
nsMsgComposeSecure::~nsMsgComposeSecure() {
|
||||
/* destructor code */
|
||||
if (mEncryptionContext) {
|
||||
if (mBufferedBytes) {
|
||||
|
@ -124,80 +115,68 @@ nsMsgComposeSecure::~nsMsgComposeSecure()
|
|||
PR_FREEIF(mMultipartSignedBoundary);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgComposeSecure::SetSignMessage(bool value)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgComposeSecure::SetSignMessage(bool value) {
|
||||
mSignMessage = value;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgComposeSecure::GetSignMessage(bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgComposeSecure::GetSignMessage(bool *_retval) {
|
||||
*_retval = mSignMessage;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgComposeSecure::SetRequireEncryptMessage(bool value)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgComposeSecure::SetRequireEncryptMessage(bool value) {
|
||||
mAlwaysEncryptMessage = value;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgComposeSecure::GetRequireEncryptMessage(bool *_retval)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgComposeSecure::GetRequireEncryptMessage(bool *_retval) {
|
||||
*_retval = mAlwaysEncryptMessage;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMsgComposeSecure::RequiresCryptoEncapsulation(nsIMsgIdentity * aIdentity, nsIMsgCompFields * aCompFields, bool * aRequiresEncryptionWork)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgComposeSecure::RequiresCryptoEncapsulation(
|
||||
nsIMsgIdentity *aIdentity, nsIMsgCompFields *aCompFields,
|
||||
bool *aRequiresEncryptionWork) {
|
||||
NS_ENSURE_ARG_POINTER(aRequiresEncryptionWork);
|
||||
|
||||
*aRequiresEncryptionWork = false;
|
||||
|
||||
bool alwaysEncryptMessages = false;
|
||||
bool signMessage = false;
|
||||
nsresult rv = ExtractEncryptionState(aIdentity, aCompFields, &signMessage, &alwaysEncryptMessages);
|
||||
nsresult rv = ExtractEncryptionState(aIdentity, aCompFields, &signMessage,
|
||||
&alwaysEncryptMessages);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (alwaysEncryptMessages || signMessage)
|
||||
*aRequiresEncryptionWork = true;
|
||||
if (alwaysEncryptMessages || signMessage) *aRequiresEncryptionWork = true;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsMsgComposeSecure::GetSMIMEBundleString(const char16_t *name,
|
||||
nsString &outString)
|
||||
{
|
||||
nsString &outString) {
|
||||
outString.Truncate();
|
||||
|
||||
NS_ENSURE_ARG_POINTER(name);
|
||||
|
||||
NS_ENSURE_TRUE(InitializeSMIMEBundle(), NS_ERROR_FAILURE);
|
||||
|
||||
return mSMIMEBundle->GetStringFromName(NS_ConvertUTF16toUTF8(name).get(), outString);
|
||||
return mSMIMEBundle->GetStringFromName(NS_ConvertUTF16toUTF8(name).get(),
|
||||
outString);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgComposeSecure::
|
||||
SMIMEBundleFormatStringFromName(const char *name,
|
||||
const char16_t **params,
|
||||
uint32_t numParams,
|
||||
nsAString& outString)
|
||||
{
|
||||
nsresult nsMsgComposeSecure::SMIMEBundleFormatStringFromName(
|
||||
const char *name, const char16_t **params, uint32_t numParams,
|
||||
nsAString &outString) {
|
||||
NS_ENSURE_ARG_POINTER(name);
|
||||
|
||||
if (!InitializeSMIMEBundle())
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!InitializeSMIMEBundle()) return NS_ERROR_FAILURE;
|
||||
|
||||
return mSMIMEBundle->FormatStringFromName(name, params, numParams, outString);
|
||||
}
|
||||
|
||||
bool nsMsgComposeSecure::InitializeSMIMEBundle()
|
||||
{
|
||||
if (mSMIMEBundle)
|
||||
return true;
|
||||
bool nsMsgComposeSecure::InitializeSMIMEBundle() {
|
||||
if (mSMIMEBundle) return true;
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
mozilla::services::GetStringBundleService();
|
||||
|
@ -208,33 +187,28 @@ bool nsMsgComposeSecure::InitializeSMIMEBundle()
|
|||
return true;
|
||||
}
|
||||
|
||||
void nsMsgComposeSecure::SetError(nsIMsgSendReport *sendReport, const char16_t *bundle_string)
|
||||
{
|
||||
if (!sendReport || !bundle_string)
|
||||
return;
|
||||
void nsMsgComposeSecure::SetError(nsIMsgSendReport *sendReport,
|
||||
const char16_t *bundle_string) {
|
||||
if (!sendReport || !bundle_string) return;
|
||||
|
||||
if (mErrorAlreadyReported)
|
||||
return;
|
||||
if (mErrorAlreadyReported) return;
|
||||
|
||||
mErrorAlreadyReported = true;
|
||||
|
||||
nsString errorString;
|
||||
nsresult res = GetSMIMEBundleString(bundle_string, errorString);
|
||||
if (NS_SUCCEEDED(res) && !errorString.IsEmpty())
|
||||
{
|
||||
sendReport->SetMessage(nsIMsgSendReport::process_Current,
|
||||
errorString.get(),
|
||||
if (NS_SUCCEEDED(res) && !errorString.IsEmpty()) {
|
||||
sendReport->SetMessage(nsIMsgSendReport::process_Current, errorString.get(),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
void nsMsgComposeSecure::SetErrorWithParam(nsIMsgSendReport *sendReport, const char *bundle_string, const char *param)
|
||||
{
|
||||
if (!sendReport || !bundle_string || !param)
|
||||
return;
|
||||
void nsMsgComposeSecure::SetErrorWithParam(nsIMsgSendReport *sendReport,
|
||||
const char *bundle_string,
|
||||
const char *param) {
|
||||
if (!sendReport || !bundle_string || !param) return;
|
||||
|
||||
if (mErrorAlreadyReported)
|
||||
return;
|
||||
if (mErrorAlreadyReported) return;
|
||||
|
||||
mErrorAlreadyReported = true;
|
||||
|
||||
|
@ -245,21 +219,17 @@ void nsMsgComposeSecure::SetErrorWithParam(nsIMsgSendReport *sendReport, const c
|
|||
NS_ConvertASCIItoUTF16 ucs2(param);
|
||||
params[0] = ucs2.get();
|
||||
|
||||
res = SMIMEBundleFormatStringFromName(bundle_string,
|
||||
params,
|
||||
1,
|
||||
errorString);
|
||||
res = SMIMEBundleFormatStringFromName(bundle_string, params, 1, errorString);
|
||||
|
||||
if (NS_SUCCEEDED(res) && !errorString.IsEmpty())
|
||||
{
|
||||
sendReport->SetMessage(nsIMsgSendReport::process_Current,
|
||||
errorString.get(),
|
||||
if (NS_SUCCEEDED(res) && !errorString.IsEmpty()) {
|
||||
sendReport->SetMessage(nsIMsgSendReport::process_Current, errorString.get(),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsMsgComposeSecure::ExtractEncryptionState(nsIMsgIdentity * aIdentity, nsIMsgCompFields * aComposeFields, bool * aSignMessage, bool * aEncrypt)
|
||||
{
|
||||
nsresult nsMsgComposeSecure::ExtractEncryptionState(
|
||||
nsIMsgIdentity *aIdentity, nsIMsgCompFields *aComposeFields,
|
||||
bool *aSignMessage, bool *aEncrypt) {
|
||||
if (!aComposeFields && !aIdentity)
|
||||
return NS_ERROR_FAILURE; // kick out...invalid args....
|
||||
|
||||
|
@ -274,9 +244,8 @@ nsresult nsMsgComposeSecure::ExtractEncryptionState(nsIMsgIdentity * aIdentity,
|
|||
|
||||
// Select a hash algorithm to sign message
|
||||
// based on subject public key type and size.
|
||||
static nsresult
|
||||
GetSigningHashFunction(nsIX509Cert *aSigningCert, int16_t *hashType)
|
||||
{
|
||||
static nsresult GetSigningHashFunction(nsIX509Cert *aSigningCert,
|
||||
int16_t *hashType) {
|
||||
// Get the signing certificate
|
||||
CERTCertificate *scert = nullptr;
|
||||
if (aSigningCert) {
|
||||
|
@ -353,20 +322,19 @@ GetSigningHashFunction(nsIX509Cert *aSigningCert, int16_t *hashType)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void beginCryptoEncapsulation (in nsOutputFileStream aStream, in boolean aEncrypt, in boolean aSign, in string aRecipeints, in boolean aIsDraft); */
|
||||
NS_IMETHODIMP nsMsgComposeSecure::BeginCryptoEncapsulation(nsIOutputStream * aStream,
|
||||
const char * aRecipients,
|
||||
nsIMsgCompFields * aCompFields,
|
||||
nsIMsgIdentity * aIdentity,
|
||||
nsIMsgSendReport *sendReport,
|
||||
bool aIsDraft)
|
||||
{
|
||||
/* void beginCryptoEncapsulation (in nsOutputFileStream aStream, in boolean
|
||||
* aEncrypt, in boolean aSign, in string aRecipeints, in boolean aIsDraft); */
|
||||
NS_IMETHODIMP nsMsgComposeSecure::BeginCryptoEncapsulation(
|
||||
nsIOutputStream *aStream, const char *aRecipients,
|
||||
nsIMsgCompFields *aCompFields, nsIMsgIdentity *aIdentity,
|
||||
nsIMsgSendReport *sendReport, bool aIsDraft) {
|
||||
mErrorAlreadyReported = false;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
bool encryptMessages = false;
|
||||
bool signMessage = false;
|
||||
ExtractEncryptionState(aIdentity, aCompFields, &signMessage, &encryptMessages);
|
||||
ExtractEncryptionState(aIdentity, aCompFields, &signMessage,
|
||||
&encryptMessages);
|
||||
|
||||
if (!signMessage && !encryptMessages) return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -387,7 +355,8 @@ NS_IMETHODIMP nsMsgComposeSecure::BeginCryptoEncapsulation(nsIOutputStream * aSt
|
|||
aIdentity->GetUnicharAttribute("encryption_cert_name", mEncryptionCertName);
|
||||
aIdentity->GetCharAttribute("encryption_cert_dbkey", mEncryptionCertDBKey);
|
||||
|
||||
rv = MimeCryptoHackCerts(aRecipients, sendReport, encryptMessages, signMessage, aIdentity);
|
||||
rv = MimeCryptoHackCerts(aRecipients, sendReport, encryptMessages,
|
||||
signMessage, aIdentity);
|
||||
if (NS_FAILED(rv)) {
|
||||
goto FAIL;
|
||||
}
|
||||
|
@ -397,8 +366,7 @@ NS_IMETHODIMP nsMsgComposeSecure::BeginCryptoEncapsulation(nsIOutputStream * aSt
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
switch (mCryptoState)
|
||||
{
|
||||
switch (mCryptoState) {
|
||||
case mime_crypto_clear_signed:
|
||||
rv = MimeInitMultipartSigned(true, sendReport);
|
||||
break;
|
||||
|
@ -428,8 +396,8 @@ FAIL:
|
|||
}
|
||||
|
||||
/* void finishCryptoEncapsulation (in boolean aAbort); */
|
||||
NS_IMETHODIMP nsMsgComposeSecure::FinishCryptoEncapsulation(bool aAbort, nsIMsgSendReport *sendReport)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgComposeSecure::FinishCryptoEncapsulation(
|
||||
bool aAbort, nsIMsgSendReport *sendReport) {
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!aAbort) {
|
||||
|
@ -456,16 +424,16 @@ NS_IMETHODIMP nsMsgComposeSecure::FinishCryptoEncapsulation(bool aAbort, nsIMsgS
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgComposeSecure::MimeInitMultipartSigned(bool aOuter, nsIMsgSendReport *sendReport)
|
||||
{
|
||||
nsresult nsMsgComposeSecure::MimeInitMultipartSigned(
|
||||
bool aOuter, nsIMsgSendReport *sendReport) {
|
||||
/* First, construct and write out the multipart/signed MIME header data.
|
||||
*/
|
||||
nsresult rv = NS_OK;
|
||||
char *header = 0;
|
||||
uint32_t L;
|
||||
|
||||
rv = make_multipart_signed_header_string(aOuter, &header,
|
||||
&mMultipartSignedBoundary, mHashType);
|
||||
rv = make_multipart_signed_header_string(
|
||||
aOuter, &header, &mMultipartSignedBoundary, mHashType);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -502,8 +470,8 @@ nsresult nsMsgComposeSecure::MimeInitMultipartSigned(bool aOuter, nsIMsgSendRepo
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgComposeSecure::MimeInitEncryption(bool aSign, nsIMsgSendReport *sendReport)
|
||||
{
|
||||
nsresult nsMsgComposeSecure::MimeInitEncryption(bool aSign,
|
||||
nsIMsgSendReport *sendReport) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIStringBundleService> bundleSvc =
|
||||
mozilla::services::GetStringBundleService();
|
||||
|
@ -514,8 +482,7 @@ nsresult nsMsgComposeSecure::MimeInitEncryption(bool aSign, nsIMsgSendReport *se
|
|||
|
||||
bundleSvc->CreateBundle(SMIME_STRBUNDLE_URL, getter_AddRefs(sMIMEBundle));
|
||||
|
||||
if (!sMIMEBundle)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!sMIMEBundle) return NS_ERROR_FAILURE;
|
||||
|
||||
sMIMEBundle->GetStringFromName("mime_smimeEncryptedContentDesc",
|
||||
mime_smime_enc_content_desc);
|
||||
|
@ -525,22 +492,19 @@ nsresult nsMsgComposeSecure::MimeInitEncryption(bool aSign, nsIMsgSendReport *se
|
|||
do_GetService(NS_MIME_CONVERTER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCString encodedContentDescription;
|
||||
mimeConverter->EncodeMimePartIIStr_UTF8(enc_content_desc_utf8, false,
|
||||
sizeof("Content-Description: "),
|
||||
nsIMimeConverter::MIME_ENCODED_WORD_SIZE,
|
||||
encodedContentDescription);
|
||||
mimeConverter->EncodeMimePartIIStr_UTF8(
|
||||
enc_content_desc_utf8, false, sizeof("Content-Description: "),
|
||||
nsIMimeConverter::MIME_ENCODED_WORD_SIZE, encodedContentDescription);
|
||||
|
||||
/* First, construct and write out the opaque-crypto-blob MIME header data.
|
||||
*/
|
||||
|
||||
char *s =
|
||||
PR_smprintf("Content-Type: " APPLICATION_PKCS7_MIME
|
||||
char *s = PR_smprintf("Content-Type: " APPLICATION_PKCS7_MIME
|
||||
"; name=\"smime.p7m\"; smime-type=enveloped-data" CRLF
|
||||
"Content-Transfer-Encoding: " ENCODING_BASE64 CRLF
|
||||
"Content-Disposition: attachment"
|
||||
"; filename=\"smime.p7m\"" CRLF
|
||||
"Content-Description: %s" CRLF
|
||||
CRLF,
|
||||
"Content-Description: %s" CRLF CRLF,
|
||||
encodedContentDescription.get());
|
||||
|
||||
uint32_t L;
|
||||
|
@ -567,8 +531,7 @@ nsresult nsMsgComposeSecure::MimeInitEncryption(bool aSign, nsIMsgSendReport *se
|
|||
|
||||
// Initialize the base64 encoder
|
||||
MOZ_ASSERT(!mCryptoEncoder, "Shouldn't have an encoder already");
|
||||
mCryptoEncoder = MimeEncoder::GetBase64Encoder(mime_encoder_output_fn,
|
||||
this);
|
||||
mCryptoEncoder = MimeEncoder::GetBase64Encoder(mime_encoder_output_fn, this);
|
||||
|
||||
/* Initialize the encrypter (and add the sender's cert.) */
|
||||
PR_ASSERT(mSelfEncryptionCert);
|
||||
|
@ -586,13 +549,13 @@ nsresult nsMsgComposeSecure::MimeInitEncryption(bool aSign, nsIMsgSendReport *se
|
|||
|
||||
if (!mBuffer) {
|
||||
mBuffer = new char[eBufferSize];
|
||||
if (!mBuffer)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (!mBuffer) return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
mBufferedBytes = 0;
|
||||
|
||||
rv = mEncryptionContext->Start(mEncryptionCinfo, mime_crypto_write_base64, mCryptoEncoder);
|
||||
rv = mEncryptionContext->Start(mEncryptionCinfo, mime_crypto_write_base64,
|
||||
mCryptoEncoder);
|
||||
if (NS_FAILED(rv)) {
|
||||
SetError(sendReport, u"ErrorEncryptMail");
|
||||
goto FAIL;
|
||||
|
@ -610,14 +573,16 @@ nsresult nsMsgComposeSecure::MimeInitEncryption(bool aSign, nsIMsgSendReport *se
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgComposeSecure::MimeFinishMultipartSigned (bool aOuter, nsIMsgSendReport *sendReport)
|
||||
{
|
||||
nsresult nsMsgComposeSecure::MimeFinishMultipartSigned(
|
||||
bool aOuter, nsIMsgSendReport *sendReport) {
|
||||
int status;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICMSMessage> cinfo = do_CreateInstance(NS_CMSMESSAGE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsICMSMessage> cinfo =
|
||||
do_CreateInstance(NS_CMSMESSAGE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsICMSEncoder> encoder = do_CreateInstance(NS_CMSENCODER_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsICMSEncoder> encoder =
|
||||
do_CreateInstance(NS_CMSENCODER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
char *header = nullptr;
|
||||
|
@ -630,8 +595,7 @@ nsresult nsMsgComposeSecure::MimeFinishMultipartSigned (bool aOuter, nsIMsgSendR
|
|||
|
||||
bundleSvc->CreateBundle(SMIME_STRBUNDLE_URL, getter_AddRefs(sMIMEBundle));
|
||||
|
||||
if (!sMIMEBundle)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!sMIMEBundle) return NS_ERROR_FAILURE;
|
||||
|
||||
sMIMEBundle->GetStringFromName("mime_smimeSignatureContentDesc",
|
||||
mime_smime_sig_content_desc);
|
||||
|
@ -652,18 +616,13 @@ nsresult nsMsgComposeSecure::MimeFinishMultipartSigned (bool aOuter, nsIMsgSendR
|
|||
/* Write out the headers for the signature.
|
||||
*/
|
||||
uint32_t L;
|
||||
header =
|
||||
PR_smprintf(CRLF
|
||||
"--%s" CRLF
|
||||
"Content-Type: " APPLICATION_PKCS7_SIGNATURE
|
||||
header = PR_smprintf(
|
||||
CRLF "--%s" CRLF "Content-Type: " APPLICATION_PKCS7_SIGNATURE
|
||||
"; name=\"smime.p7s\"" CRLF
|
||||
"Content-Transfer-Encoding: " ENCODING_BASE64 CRLF
|
||||
"Content-Disposition: attachment; "
|
||||
"filename=\"smime.p7s\"" CRLF
|
||||
"Content-Description: %s" CRLF
|
||||
CRLF,
|
||||
mMultipartSignedBoundary,
|
||||
sig_content_desc_utf8.get());
|
||||
"filename=\"smime.p7s\"" CRLF "Content-Description: %s" CRLF CRLF,
|
||||
mMultipartSignedBoundary, sig_content_desc_utf8.get());
|
||||
|
||||
if (!header) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -695,7 +654,8 @@ nsresult nsMsgComposeSecure::MimeFinishMultipartSigned (bool aOuter, nsIMsgSendR
|
|||
PR_SetError(0, 0);
|
||||
|
||||
rv = cinfo->CreateSigned(mSelfSigningCert, mSelfEncryptionCert,
|
||||
(unsigned char*)hashString.get(), hashString.Length(), mHashType);
|
||||
(unsigned char *)hashString.get(),
|
||||
hashString.Length(), mHashType);
|
||||
if (NS_FAILED(rv)) {
|
||||
SetError(sendReport, u"ErrorCanNotSignMail");
|
||||
goto FAIL;
|
||||
|
@ -733,8 +693,7 @@ nsresult nsMsgComposeSecure::MimeFinishMultipartSigned (bool aOuter, nsIMsgSendR
|
|||
*/
|
||||
{
|
||||
uint32_t L;
|
||||
char *header = PR_smprintf(CRLF "--%s--" CRLF,
|
||||
mMultipartSignedBoundary);
|
||||
char *header = PR_smprintf(CRLF "--%s--" CRLF, mMultipartSignedBoundary);
|
||||
PR_Free(mMultipartSignedBoundary);
|
||||
mMultipartSignedBoundary = 0;
|
||||
|
||||
|
@ -760,12 +719,11 @@ FAIL:
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/* Helper function for mime_finish_crypto_encapsulation() to close off
|
||||
an opaque crypto object (for encrypted or signed-and-encrypted messages.)
|
||||
*/
|
||||
nsresult nsMsgComposeSecure::MimeFinishEncryption (bool aSign, nsIMsgSendReport *sendReport)
|
||||
{
|
||||
nsresult nsMsgComposeSecure::MimeFinishEncryption(
|
||||
bool aSign, nsIMsgSendReport *sendReport) {
|
||||
nsresult rv;
|
||||
|
||||
/* If this object is both encrypted and signed, close off the
|
||||
|
@ -812,8 +770,7 @@ nsresult nsMsgComposeSecure::MimeFinishEncryption (bool aSign, nsIMsgSendReport
|
|||
|
||||
uint32_t n;
|
||||
rv = mStream->Write(CRLF, 2, &n);
|
||||
if (NS_FAILED(rv) || n < 2)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv) || n < 2) rv = NS_ERROR_FAILURE;
|
||||
|
||||
FAIL:
|
||||
return rv;
|
||||
|
@ -823,10 +780,8 @@ nsresult nsMsgComposeSecure::MimeFinishEncryption (bool aSign, nsIMsgSendReport
|
|||
*/
|
||||
nsresult nsMsgComposeSecure::MimeCryptoHackCerts(const char *aRecipients,
|
||||
nsIMsgSendReport *sendReport,
|
||||
bool aEncrypt,
|
||||
bool aSign,
|
||||
nsIMsgIdentity *aIdentity)
|
||||
{
|
||||
bool aEncrypt, bool aSign,
|
||||
nsIMsgIdentity *aIdentity) {
|
||||
nsCOMPtr<nsIX509CertDB> certdb = do_GetService(NS_X509CERTDB_CONTRACTID);
|
||||
nsresult res;
|
||||
|
||||
|
@ -854,14 +809,11 @@ nsresult nsMsgComposeSecure::MimeCryptoHackCerts(const char *aRecipients,
|
|||
res = certdb->FindCertByDBKey(mEncryptionCertDBKey,
|
||||
getter_AddRefs(mSelfEncryptionCert));
|
||||
if (NS_SUCCEEDED(res) && mSelfEncryptionCert &&
|
||||
(certVerifier->VerifyCert(mSelfEncryptionCert->GetCert(),
|
||||
certificateUsageEmailRecipient,
|
||||
mozilla::pkix::Now(),
|
||||
nullptr, nullptr,
|
||||
builtChain,
|
||||
(certVerifier->VerifyCert(
|
||||
mSelfEncryptionCert->GetCert(), certificateUsageEmailRecipient,
|
||||
mozilla::pkix::Now(), nullptr, nullptr, builtChain,
|
||||
// Only local checks can run on the main thread.
|
||||
CertVerifier::FLAG_LOCAL_ONLY)
|
||||
!= mozilla::pkix::Success)) {
|
||||
CertVerifier::FLAG_LOCAL_ONLY) != mozilla::pkix::Success)) {
|
||||
// not suitable for encryption, so unset cert and clear pref
|
||||
mSelfEncryptionCert = nullptr;
|
||||
mEncryptionCertDBKey.Truncate();
|
||||
|
@ -875,14 +827,11 @@ nsresult nsMsgComposeSecure::MimeCryptoHackCerts(const char *aRecipients,
|
|||
res = certdb->FindCertByDBKey(mSigningCertDBKey,
|
||||
getter_AddRefs(mSelfSigningCert));
|
||||
if (NS_SUCCEEDED(res) && mSelfSigningCert &&
|
||||
(certVerifier->VerifyCert(mSelfSigningCert->GetCert(),
|
||||
certificateUsageEmailSigner,
|
||||
mozilla::pkix::Now(),
|
||||
nullptr, nullptr,
|
||||
builtChain,
|
||||
(certVerifier->VerifyCert(
|
||||
mSelfSigningCert->GetCert(), certificateUsageEmailSigner,
|
||||
mozilla::pkix::Now(), nullptr, nullptr, builtChain,
|
||||
// Only local checks can run on the main thread.
|
||||
CertVerifier::FLAG_LOCAL_ONLY)
|
||||
!= mozilla::pkix::Success)) {
|
||||
CertVerifier::FLAG_LOCAL_ONLY) != mozilla::pkix::Success)) {
|
||||
// not suitable for signing, so unset cert and clear pref
|
||||
mSelfSigningCert = nullptr;
|
||||
mSigningCertDBKey.Truncate();
|
||||
|
@ -901,7 +850,6 @@ nsresult nsMsgComposeSecure::MimeCryptoHackCerts(const char *aRecipients,
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
if (aEncrypt && mSelfEncryptionCert) {
|
||||
// Make sure self's configured cert is prepared for being used
|
||||
// as an email recipient cert.
|
||||
|
@ -929,12 +877,12 @@ nsresult nsMsgComposeSecure::MimeCryptoHackCerts(const char *aRecipients,
|
|||
ToLowerCase(mailboxes[i], mailbox_lowercase);
|
||||
nsCOMPtr<nsIX509Cert> cert;
|
||||
// TODO: allow user to override and go ahead with an invalid certificate
|
||||
res = FindCertByEmailAddress(mailbox_lowercase, true, getter_AddRefs(cert));
|
||||
res =
|
||||
FindCertByEmailAddress(mailbox_lowercase, true, getter_AddRefs(cert));
|
||||
if (NS_FAILED(res)) {
|
||||
// Failure to find a valid encryption cert is fatal.
|
||||
// Here I assume that mailbox is ascii rather than utf8.
|
||||
SetErrorWithParam(sendReport,
|
||||
"MissingRecipientEncryptionCert",
|
||||
SetErrorWithParam(sendReport, "MissingRecipientEncryptionCert",
|
||||
mailboxes[i].get());
|
||||
|
||||
return res;
|
||||
|
@ -948,8 +896,7 @@ nsresult nsMsgComposeSecure::MimeCryptoHackCerts(const char *aRecipients,
|
|||
*/
|
||||
|
||||
bool isSame;
|
||||
if (NS_SUCCEEDED(cert->Equals(mSelfEncryptionCert, &isSame))
|
||||
&& isSame) {
|
||||
if (NS_SUCCEEDED(cert->Equals(mSelfEncryptionCert, &isSame)) && isSame) {
|
||||
already_added_self_cert = true;
|
||||
}
|
||||
|
||||
|
@ -963,8 +910,8 @@ nsresult nsMsgComposeSecure::MimeCryptoHackCerts(const char *aRecipients,
|
|||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgComposeSecure::MimeCryptoWriteBlock (const char *buf, int32_t size)
|
||||
{
|
||||
NS_IMETHODIMP nsMsgComposeSecure::MimeCryptoWriteBlock(const char *buf,
|
||||
int32_t size) {
|
||||
int status = 0;
|
||||
nsresult rv;
|
||||
|
||||
|
@ -979,8 +926,7 @@ NS_IMETHODIMP nsMsgComposeSecure::MimeCryptoWriteBlock (const char *buf, int32_t
|
|||
if (size >= 5 && buf[0] == 'F' && !strncmp(buf, "From ", 5)) {
|
||||
char mangle[] = ">";
|
||||
nsresult res = MimeCryptoWriteBlock(mangle, 1);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
if (NS_FAILED(res)) return res;
|
||||
// This value will actually be cast back to an nsresult before use, so this
|
||||
// cast is reasonable under the circumstances.
|
||||
status = static_cast<int>(res);
|
||||
|
@ -1006,7 +952,8 @@ NS_IMETHODIMP nsMsgComposeSecure::MimeCryptoWriteBlock (const char *buf, int32_t
|
|||
|
||||
while (inputBytesLeft) {
|
||||
const uint32_t spaceLeftInBuffer = eBufferSize - mBufferedBytes;
|
||||
const uint32_t bytesToAppend = std::min(inputBytesLeft, spaceLeftInBuffer);
|
||||
const uint32_t bytesToAppend =
|
||||
std::min(inputBytesLeft, spaceLeftInBuffer);
|
||||
|
||||
memcpy(mBuffer + mBufferedBytes, inputBytesIterator, bytesToAppend);
|
||||
mBufferedBytes += bytesToAppend;
|
||||
|
@ -1047,18 +994,15 @@ NS_IMETHODIMP nsMsgComposeSecure::MimeCryptoWriteBlock (const char *buf, int32_t
|
|||
of a multipart object. The boundary itself is also returned (so that
|
||||
the caller knows what to write to close it off.)
|
||||
*/
|
||||
static nsresult
|
||||
make_multipart_signed_header_string(bool outer_p,
|
||||
static nsresult make_multipart_signed_header_string(bool outer_p,
|
||||
char **header_return,
|
||||
char **boundary_return,
|
||||
int16_t hash_type)
|
||||
{
|
||||
int16_t hash_type) {
|
||||
const char *hashStr;
|
||||
*header_return = 0;
|
||||
*boundary_return = mime_make_separator("ms");
|
||||
|
||||
if (!*boundary_return)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (!*boundary_return) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
switch (hash_type) {
|
||||
case nsICryptoHash::SHA1:
|
||||
|
@ -1077,19 +1021,17 @@ make_multipart_signed_header_string(bool outer_p,
|
|||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
*header_return = PR_smprintf(
|
||||
"Content-Type: " MULTIPART_SIGNED "; "
|
||||
"protocol=\"" APPLICATION_PKCS7_SIGNATURE "\"; "
|
||||
*header_return = PR_smprintf("Content-Type: " MULTIPART_SIGNED
|
||||
"; "
|
||||
"protocol=\"" APPLICATION_PKCS7_SIGNATURE
|
||||
"\"; "
|
||||
"micalg=%s; "
|
||||
"boundary=\"%s\"" CRLF
|
||||
CRLF
|
||||
"boundary=\"%s\"" CRLF CRLF
|
||||
"%s%s"
|
||||
"--%s" CRLF,
|
||||
hashStr,
|
||||
*boundary_return,
|
||||
hashStr, *boundary_return,
|
||||
(outer_p ? crypto_multipart_blurb : ""),
|
||||
(outer_p ? CRLF CRLF : ""),
|
||||
*boundary_return);
|
||||
(outer_p ? CRLF CRLF : ""), *boundary_return);
|
||||
|
||||
if (!*header_return) {
|
||||
PR_Free(*boundary_return);
|
||||
|
@ -1109,22 +1051,19 @@ make_multipart_signed_header_string(bool outer_p,
|
|||
it's used to write the encoded representation of the signature. The only
|
||||
difference is which MimeEncoder object is used.
|
||||
*/
|
||||
static void
|
||||
mime_crypto_write_base64 (void *closure, const char *buf, unsigned long size)
|
||||
{
|
||||
static void mime_crypto_write_base64(void *closure, const char *buf,
|
||||
unsigned long size) {
|
||||
MimeEncoder *encoder = (MimeEncoder *)closure;
|
||||
nsresult rv = encoder->Write(buf, size);
|
||||
PR_SetError(NS_FAILED(rv) ? static_cast<uint32_t>(rv) : 0, 0);
|
||||
}
|
||||
|
||||
|
||||
/* Used as the output function of MimeEncoder -- when we have generated
|
||||
the signature for a multipart/signed object, this is used to write the
|
||||
base64-encoded representation of the signature to the file.
|
||||
*/
|
||||
// TODO: size should probably be converted to uint32_t
|
||||
nsresult mime_encoder_output_fn(const char *buf, int32_t size, void *closure)
|
||||
{
|
||||
nsresult mime_encoder_output_fn(const char *buf, int32_t size, void *closure) {
|
||||
nsMsgComposeSecure *state = (nsMsgComposeSecure *)closure;
|
||||
nsCOMPtr<nsIOutputStream> stream;
|
||||
state->GetOutputStream(getter_AddRefs(stream));
|
||||
|
@ -1141,9 +1080,8 @@ nsresult mime_encoder_output_fn(const char *buf, int32_t size, void *closure)
|
|||
signature should be fed into the crypto engine, rather than being written
|
||||
directly to the file.
|
||||
*/
|
||||
static nsresult
|
||||
mime_nested_encoder_output_fn (const char *buf, int32_t size, void *closure)
|
||||
{
|
||||
static nsresult mime_nested_encoder_output_fn(const char *buf, int32_t size,
|
||||
void *closure) {
|
||||
nsMsgComposeSecure *state = (nsMsgComposeSecure *)closure;
|
||||
|
||||
// Copy to new null-terminated string so JS glue doesn't crash when
|
||||
|
@ -1156,8 +1094,7 @@ mime_nested_encoder_output_fn (const char *buf, int32_t size, void *closure)
|
|||
NS_IMETHODIMP
|
||||
nsMsgComposeSecure::FindCertByEmailAddress(const nsACString &aEmailAddress,
|
||||
bool aRequireValidCert,
|
||||
nsIX509Cert** _retval)
|
||||
{
|
||||
nsIX509Cert **_retval) {
|
||||
nsresult rv = BlockUntilLoadableRootsLoaded();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
|
@ -1169,8 +1106,7 @@ nsMsgComposeSecure::FindCertByEmailAddress(const nsACString& aEmailAddress,
|
|||
const nsCString &flatEmailAddress = PromiseFlatCString(aEmailAddress);
|
||||
UniqueCERTCertList certlist(
|
||||
PK11_FindCertsFromEmailAddress(flatEmailAddress.get(), nullptr));
|
||||
if (!certlist)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!certlist) return NS_ERROR_FAILURE;
|
||||
|
||||
// certlist now contains certificates with the right email address,
|
||||
// but they might not have the correct usage or might even be invalid
|
||||
|
@ -1180,16 +1116,12 @@ nsMsgComposeSecure::FindCertByEmailAddress(const nsACString& aEmailAddress,
|
|||
|
||||
CERTCertListNode *node;
|
||||
// search for a valid certificate
|
||||
for (node = CERT_LIST_HEAD(certlist);
|
||||
!CERT_LIST_END(node, certlist);
|
||||
for (node = CERT_LIST_HEAD(certlist); !CERT_LIST_END(node, certlist);
|
||||
node = CERT_LIST_NEXT(node)) {
|
||||
UniqueCERTCertList unusedCertChain;
|
||||
mozilla::pkix::Result result =
|
||||
certVerifier->VerifyCert(node->cert, certificateUsageEmailRecipient,
|
||||
mozilla::pkix::Now(),
|
||||
nullptr /*XXX pinarg*/,
|
||||
nullptr /*hostname*/,
|
||||
unusedCertChain,
|
||||
mozilla::pkix::Result result = certVerifier->VerifyCert(
|
||||
node->cert, certificateUsageEmailRecipient, mozilla::pkix::Now(),
|
||||
nullptr /*XXX pinarg*/, nullptr /*hostname*/, unusedCertChain,
|
||||
// Only local checks can run on the main thread.
|
||||
CertVerifier::FLAG_LOCAL_ONLY);
|
||||
if (result == mozilla::pkix::Success) {
|
||||
|
@ -1198,8 +1130,7 @@ nsMsgComposeSecure::FindCertByEmailAddress(const nsACString& aEmailAddress,
|
|||
}
|
||||
|
||||
if (CERT_LIST_END(node, certlist)) { // no valid cert found
|
||||
if (aRequireValidCert)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (aRequireValidCert) return NS_ERROR_FAILURE;
|
||||
|
||||
// Get the first non-valid then.
|
||||
node = CERT_LIST_HEAD(certlist);
|
||||
|
@ -1208,8 +1139,7 @@ nsMsgComposeSecure::FindCertByEmailAddress(const nsACString& aEmailAddress,
|
|||
// |node| now contains the first valid (if aRequireValidCert true)
|
||||
// certificate with correct usage.
|
||||
RefPtr<nsNSSCertificate> nssCert = nsNSSCertificate::Create(node->cert);
|
||||
if (!nssCert)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (!nssCert) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nssCert.forget(_retval);
|
||||
return NS_OK;
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace mozilla {
|
|||
namespace mailnews {
|
||||
class MimeEncoder;
|
||||
}
|
||||
}
|
||||
} // namespace mozilla
|
||||
|
||||
typedef enum {
|
||||
mime_crypto_none, /* normal unencapsulated MIME message */
|
||||
|
@ -33,15 +33,16 @@ typedef enum {
|
|||
mime_crypto_signed_encrypted /* application/x-pkcs7-mime */
|
||||
} mimeDeliveryCryptoState;
|
||||
|
||||
class nsMsgComposeSecure : public nsIMsgComposeSecure
|
||||
{
|
||||
class nsMsgComposeSecure : public nsIMsgComposeSecure {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMSGCOMPOSESECURE
|
||||
|
||||
nsMsgComposeSecure();
|
||||
|
||||
void GetOutputStream(nsIOutputStream **stream) { NS_IF_ADDREF(*stream = mStream);}
|
||||
void GetOutputStream(nsIOutputStream **stream) {
|
||||
NS_IF_ADDREF(*stream = mStream);
|
||||
}
|
||||
nsresult GetSMIMEBundleString(const char16_t *name, nsString &outString);
|
||||
|
||||
private:
|
||||
|
@ -51,13 +52,17 @@ private:
|
|||
nsresult MimeInitEncryption(bool aSign, nsIMsgSendReport *sendReport);
|
||||
nsresult MimeFinishMultipartSigned(bool aOuter, nsIMsgSendReport *sendReport);
|
||||
nsresult MimeFinishEncryption(bool aSign, nsIMsgSendReport *sendReport);
|
||||
nsresult MimeCryptoHackCerts(const char *aRecipients, nsIMsgSendReport *sendReport, bool aEncrypt, bool aSign, nsIMsgIdentity *aIdentity);
|
||||
nsresult MimeCryptoHackCerts(const char *aRecipients,
|
||||
nsIMsgSendReport *sendReport, bool aEncrypt,
|
||||
bool aSign, nsIMsgIdentity *aIdentity);
|
||||
bool InitializeSMIMEBundle();
|
||||
nsresult SMIMEBundleFormatStringFromName(const char *name,
|
||||
const char16_t **params,
|
||||
uint32_t numParams,
|
||||
nsAString &outString);
|
||||
nsresult ExtractEncryptionState(nsIMsgIdentity * aIdentity, nsIMsgCompFields * aComposeFields, bool * aSignMessage, bool * aEncrypt);
|
||||
nsresult ExtractEncryptionState(nsIMsgIdentity *aIdentity,
|
||||
nsIMsgCompFields *aComposeFields,
|
||||
bool *aSignMessage, bool *aEncrypt);
|
||||
|
||||
bool mSignMessage;
|
||||
bool mAlwaysEncryptMessage;
|
||||
|
@ -87,7 +92,8 @@ private:
|
|||
|
||||
bool mErrorAlreadyReported;
|
||||
void SetError(nsIMsgSendReport *sendReport, const char16_t *bundle_string);
|
||||
void SetErrorWithParam(nsIMsgSendReport *sendReport, const char *bundle_string, const char *param);
|
||||
void SetErrorWithParam(nsIMsgSendReport *sendReport,
|
||||
const char *bundle_string, const char *param);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,23 +8,29 @@
|
|||
|
||||
#define NS_MSGCOMPOSESECURE_CID \
|
||||
{ /* 54976882-7421-4286-8ecc-46373f15d7b5 */ \
|
||||
0x54976882, 0x7421, 0x4286, \
|
||||
{0x8e, 0xcc, 0x46, 0x37, 0x3f, 0x15, 0xd7, 0xb5 }}
|
||||
0x54976882, 0x7421, 0x4286, { \
|
||||
0x8e, 0xcc, 0x46, 0x37, 0x3f, 0x15, 0xd7, 0xb5 \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NS_SMIMEJSHELPER_CONTRACTID \
|
||||
"@mozilla.org/messenger-smime/smimejshelper;1"
|
||||
|
||||
#define NS_SMIMEJSJELPER_CID \
|
||||
{ /* d57d928c-60e4-4f81-999d-5c762e611205 */ \
|
||||
0xd57d928c, 0x60e4, 0x4f81, \
|
||||
{0x99, 0x9d, 0x5c, 0x76, 0x2e, 0x61, 0x12, 0x05 }}
|
||||
0xd57d928c, 0x60e4, 0x4f81, { \
|
||||
0x99, 0x9d, 0x5c, 0x76, 0x2e, 0x61, 0x12, 0x05 \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NS_SMIMEENCRYPTURISERVICE_CONTRACTID \
|
||||
"@mozilla.org/messenger-smime/smime-encrypted-uris-service;1"
|
||||
|
||||
#define NS_SMIMEENCRYPTURISERVICE_CID \
|
||||
{ /* a0134d58-018f-4d40-a099-fa079e5024a6 */ \
|
||||
0xa0134d58, 0x018f, 0x4d40, \
|
||||
{0xa0, 0x99, 0xfa, 0x07, 0x9e, 0x50, 0x24, 0xa6 }}
|
||||
0xa0134d58, 0x018f, 0x4d40, { \
|
||||
0xa0, 0x99, 0xfa, 0x07, 0x9e, 0x50, 0x24, 0xa6 \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif // nsMsgSMIMECID_h__
|
||||
|
|
|
@ -20,24 +20,14 @@ using namespace mozilla::mailnews;
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsSMimeJSHelper, nsISMimeJSHelper)
|
||||
|
||||
nsSMimeJSHelper::nsSMimeJSHelper()
|
||||
{
|
||||
}
|
||||
nsSMimeJSHelper::nsSMimeJSHelper() {}
|
||||
|
||||
nsSMimeJSHelper::~nsSMimeJSHelper()
|
||||
{
|
||||
}
|
||||
nsSMimeJSHelper::~nsSMimeJSHelper() {}
|
||||
|
||||
NS_IMETHODIMP nsSMimeJSHelper::GetRecipientCertsInfo(
|
||||
nsIMsgCompFields *compFields,
|
||||
uint32_t *count,
|
||||
char16_t ***emailAddresses,
|
||||
int32_t **certVerification,
|
||||
char16_t ***certIssuedInfos,
|
||||
char16_t ***certExpiresInfos,
|
||||
nsIX509Cert ***certs,
|
||||
bool *canEncrypt)
|
||||
{
|
||||
nsIMsgCompFields *compFields, uint32_t *count, char16_t ***emailAddresses,
|
||||
int32_t **certVerification, char16_t ***certIssuedInfos,
|
||||
char16_t ***certExpiresInfos, nsIX509Cert ***certs, bool *canEncrypt) {
|
||||
NS_ENSURE_ARG_POINTER(count);
|
||||
*count = 0;
|
||||
|
||||
|
@ -62,29 +52,30 @@ NS_IMETHODIMP nsSMimeJSHelper::GetRecipientCertsInfo(
|
|||
*canEncrypt = false;
|
||||
rv = NS_OK;
|
||||
|
||||
if (mailbox_count)
|
||||
{
|
||||
if (mailbox_count) {
|
||||
nsCOMPtr<nsIMsgComposeSecure> composeSecure =
|
||||
do_CreateInstance(NS_MSGCOMPOSESECURE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
char16_t **outEA = static_cast<char16_t **>(moz_xmalloc(mailbox_count * sizeof(char16_t *)));
|
||||
int32_t *outCV = static_cast<int32_t *>(moz_xmalloc(mailbox_count * sizeof(int32_t)));
|
||||
char16_t **outCII = static_cast<char16_t **>(moz_xmalloc(mailbox_count * sizeof(char16_t *)));
|
||||
char16_t **outCEI = static_cast<char16_t **>(moz_xmalloc(mailbox_count * sizeof(char16_t *)));
|
||||
nsIX509Cert **outCerts = static_cast<nsIX509Cert **>(moz_xmalloc(mailbox_count * sizeof(nsIX509Cert *)));
|
||||
char16_t **outEA = static_cast<char16_t **>(
|
||||
moz_xmalloc(mailbox_count * sizeof(char16_t *)));
|
||||
int32_t *outCV =
|
||||
static_cast<int32_t *>(moz_xmalloc(mailbox_count * sizeof(int32_t)));
|
||||
char16_t **outCII = static_cast<char16_t **>(
|
||||
moz_xmalloc(mailbox_count * sizeof(char16_t *)));
|
||||
char16_t **outCEI = static_cast<char16_t **>(
|
||||
moz_xmalloc(mailbox_count * sizeof(char16_t *)));
|
||||
nsIX509Cert **outCerts = static_cast<nsIX509Cert **>(
|
||||
moz_xmalloc(mailbox_count * sizeof(nsIX509Cert *)));
|
||||
|
||||
if (!outEA || !outCV || !outCII || !outCEI || !outCerts)
|
||||
{
|
||||
if (!outEA || !outCV || !outCII || !outCEI || !outCerts) {
|
||||
free(outEA);
|
||||
free(outCV);
|
||||
free(outCII);
|
||||
free(outCEI);
|
||||
free(outCerts);
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
char16_t **iEA = outEA;
|
||||
int32_t *iCV = outCV;
|
||||
char16_t **iCII = outCII;
|
||||
|
@ -94,10 +85,8 @@ NS_IMETHODIMP nsSMimeJSHelper::GetRecipientCertsInfo(
|
|||
bool found_blocker = false;
|
||||
bool memory_failure = false;
|
||||
|
||||
for (uint32_t i = 0;
|
||||
i < mailbox_count;
|
||||
++i, ++iEA, ++iCV, ++iCII, ++iCEI, ++iCert)
|
||||
{
|
||||
for (uint32_t i = 0; i < mailbox_count;
|
||||
++i, ++iEA, ++iCV, ++iCII, ++iCEI, ++iCert) {
|
||||
*iCert = nullptr;
|
||||
*iCV = 0;
|
||||
*iCII = nullptr;
|
||||
|
@ -120,8 +109,7 @@ NS_IMETHODIMP nsSMimeJSHelper::GetRecipientCertsInfo(
|
|||
|
||||
nsCOMPtr<nsIX509Cert> cert;
|
||||
if (NS_SUCCEEDED(composeSecure->FindCertByEmailAddress(
|
||||
email_lowercase, false, getter_AddRefs(cert))))
|
||||
{
|
||||
email_lowercase, false, getter_AddRefs(cert)))) {
|
||||
cert.forget(iCert);
|
||||
|
||||
nsCOMPtr<nsIX509CertValidity> validity;
|
||||
|
@ -130,8 +118,7 @@ NS_IMETHODIMP nsSMimeJSHelper::GetRecipientCertsInfo(
|
|||
if (NS_SUCCEEDED(rv)) {
|
||||
nsString id, ed;
|
||||
|
||||
if (NS_SUCCEEDED(validity->GetNotBeforeLocalDay(id)))
|
||||
{
|
||||
if (NS_SUCCEEDED(validity->GetNotBeforeLocalDay(id))) {
|
||||
*iCII = ToNewUnicode(id);
|
||||
if (!*iCII) {
|
||||
memory_failure = true;
|
||||
|
@ -139,8 +126,7 @@ NS_IMETHODIMP nsSMimeJSHelper::GetRecipientCertsInfo(
|
|||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(validity->GetNotAfterLocalDay(ed)))
|
||||
{
|
||||
if (NS_SUCCEEDED(validity->GetNotAfterLocalDay(ed))) {
|
||||
*iCEI = ToNewUnicode(ed);
|
||||
if (!*iCEI) {
|
||||
memory_failure = true;
|
||||
|
@ -148,9 +134,7 @@ NS_IMETHODIMP nsSMimeJSHelper::GetRecipientCertsInfo(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
found_blocker = true;
|
||||
}
|
||||
}
|
||||
|
@ -162,10 +146,8 @@ NS_IMETHODIMP nsSMimeJSHelper::GetRecipientCertsInfo(
|
|||
NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(mailbox_count, outCerts);
|
||||
free(outCV);
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else {
|
||||
if (mailbox_count > 0 && !found_blocker)
|
||||
{
|
||||
} else {
|
||||
if (mailbox_count > 0 && !found_blocker) {
|
||||
*canEncrypt = true;
|
||||
}
|
||||
|
||||
|
@ -180,11 +162,9 @@ NS_IMETHODIMP nsSMimeJSHelper::GetRecipientCertsInfo(
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSMimeJSHelper::GetNoCertAddresses(
|
||||
nsIMsgCompFields *compFields,
|
||||
NS_IMETHODIMP nsSMimeJSHelper::GetNoCertAddresses(nsIMsgCompFields *compFields,
|
||||
uint32_t *count,
|
||||
char16_t ***emailAddresses)
|
||||
{
|
||||
char16_t ***emailAddresses) {
|
||||
NS_ENSURE_ARG_POINTER(count);
|
||||
*count = 0;
|
||||
|
||||
|
@ -198,8 +178,7 @@ NS_IMETHODIMP nsSMimeJSHelper::GetNoCertAddresses(
|
|||
|
||||
uint32_t mailbox_count = mailboxes.Length();
|
||||
|
||||
if (!mailbox_count)
|
||||
{
|
||||
if (!mailbox_count) {
|
||||
*count = 0;
|
||||
*emailAddresses = nullptr;
|
||||
return NS_OK;
|
||||
|
@ -211,17 +190,14 @@ NS_IMETHODIMP nsSMimeJSHelper::GetNoCertAddresses(
|
|||
|
||||
uint32_t missing_count = 0;
|
||||
bool *haveCert = new bool[mailbox_count];
|
||||
if (!haveCert)
|
||||
{
|
||||
if (!haveCert) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
rv = NS_OK;
|
||||
|
||||
if (mailbox_count)
|
||||
{
|
||||
for (uint32_t i = 0; i < mailbox_count; ++i)
|
||||
{
|
||||
if (mailbox_count) {
|
||||
for (uint32_t i = 0; i < mailbox_count; ++i) {
|
||||
haveCert[i] = false;
|
||||
|
||||
nsCString email_lowercase;
|
||||
|
@ -232,34 +208,27 @@ NS_IMETHODIMP nsSMimeJSHelper::GetNoCertAddresses(
|
|||
email_lowercase, true, getter_AddRefs(cert))))
|
||||
haveCert[i] = true;
|
||||
|
||||
if (!haveCert[i])
|
||||
++missing_count;
|
||||
if (!haveCert[i]) ++missing_count;
|
||||
}
|
||||
}
|
||||
|
||||
*count = missing_count;
|
||||
|
||||
if (missing_count)
|
||||
{
|
||||
char16_t **outEA = static_cast<char16_t **>(moz_xmalloc(missing_count * sizeof(char16_t *)));
|
||||
if (!outEA )
|
||||
{
|
||||
if (missing_count) {
|
||||
char16_t **outEA = static_cast<char16_t **>(
|
||||
moz_xmalloc(missing_count * sizeof(char16_t *)));
|
||||
if (!outEA) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
char16_t **iEA = outEA;
|
||||
|
||||
bool memory_failure = false;
|
||||
|
||||
for (uint32_t i = 0; i < mailbox_count; ++i)
|
||||
{
|
||||
if (!haveCert[i])
|
||||
{
|
||||
for (uint32_t i = 0; i < mailbox_count; ++i) {
|
||||
if (!haveCert[i]) {
|
||||
if (memory_failure) {
|
||||
*iEA = nullptr;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*iEA = ToNewUnicode(NS_ConvertUTF8toUTF16(mailboxes[i]));
|
||||
if (!*iEA) {
|
||||
memory_failure = true;
|
||||
|
@ -272,14 +241,11 @@ NS_IMETHODIMP nsSMimeJSHelper::GetNoCertAddresses(
|
|||
if (memory_failure) {
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(missing_count, outEA);
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*emailAddresses = outEA;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*emailAddresses = nullptr;
|
||||
}
|
||||
|
||||
|
@ -288,29 +254,23 @@ NS_IMETHODIMP nsSMimeJSHelper::GetNoCertAddresses(
|
|||
}
|
||||
|
||||
nsresult nsSMimeJSHelper::getMailboxList(nsIMsgCompFields *compFields,
|
||||
nsTArray<nsCString> &mailboxes)
|
||||
{
|
||||
if (!compFields)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
nsTArray<nsCString> &mailboxes) {
|
||||
if (!compFields) return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsresult res;
|
||||
nsString to, cc, bcc, ng;
|
||||
|
||||
res = compFields->GetTo(to);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
res = compFields->GetCc(cc);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
res = compFields->GetBcc(bcc);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
res = compFields->GetNewsgroups(ng);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
{
|
||||
nsCString all_recipients;
|
||||
|
@ -330,8 +290,7 @@ nsresult nsSMimeJSHelper::getMailboxList(nsIMsgCompFields *compFields,
|
|||
all_recipients.Append(',');
|
||||
}
|
||||
|
||||
if (!ng.IsEmpty())
|
||||
all_recipients.Append(NS_ConvertUTF16toUTF8(ng));
|
||||
if (!ng.IsEmpty()) all_recipients.Append(NS_ConvertUTF16toUTF8(ng));
|
||||
|
||||
ExtractEmails(EncodedHeader(all_recipients),
|
||||
UTF16ArrayAdapter<>(mailboxes));
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
#include "nsISMimeJSHelper.h"
|
||||
#include "nsIMsgCompFields.h"
|
||||
|
||||
class nsSMimeJSHelper : public nsISMimeJSHelper
|
||||
{
|
||||
class nsSMimeJSHelper : public nsISMimeJSHelper {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISMIMEJSHELPER
|
||||
|
|
Загрузка…
Ссылка в новой задаче