Bug 1546364 - Reformat to Google coding style in mailnews/extensions. rs=reformat

# ignore-this-changeset
This commit is contained in:
Jorg K 2019-04-24 10:34:36 +02:00
Родитель 6f937bff08
Коммит 7abc056d03
28 изменённых файлов: 6254 добавлений и 6068 удалений

Просмотреть файл

@ -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
{

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -19,7 +19,7 @@
#include "mozilla/ArenaAllocator.h"
#define DEFAULT_MIN_INTERVAL_BETWEEN_WRITES 15*60*1000
#define DEFAULT_MIN_INTERVAL_BETWEEN_WRITES 15 * 60 * 1000
struct Token;
class TokenEnumeration;
@ -36,13 +36,13 @@ struct CorpusToken;
* or Remove() is performed on the table.
*/
class TokenEnumeration {
public:
explicit TokenEnumeration(PLDHashTable* table);
bool hasMoreTokens();
BaseToken* nextToken();
public:
explicit TokenEnumeration(PLDHashTable* table);
bool hasMoreTokens();
BaseToken* nextToken();
private:
PLDHashTable::Iterator mIterator;
private:
PLDHashTable::Iterator mIterator;
};
// A trait is some aspect of a message, like being junk or tagged as
@ -52,13 +52,12 @@ private:
//
// Traits per token are maintained as a linked list.
//
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
// for none
TraitPerToken(uint32_t aId, uint32_t aCount); // inititializer
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
// for none
TraitPerToken(uint32_t aId, uint32_t aCount); // inititializer
};
// An Analysis is the statistical results for a particular message, a
@ -67,90 +66,93 @@ struct TraitPerToken
//
// Analyses per token are maintained as a linked list.
//
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.
double mDistance; // absolute value of mProbability - 0.5
double mProbability; // relative indicator of match of trait to token
uint32_t mNextLink; // index in mAnalysisStore for the Analysis object
// for the next trait index, or 0 for none.
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.
double mDistance; // absolute value of mProbability - 0.5
double mProbability; // relative indicator of match of trait to token
uint32_t mNextLink; // index in mAnalysisStore for the Analysis object
// for the next trait index, or 0 for none.
// initializer
AnalysisPerToken(uint32_t aTraitIndex, double aDistance, double aProbability);
};
class TokenHash {
public:
public:
virtual ~TokenHash();
/**
* Clears out the previous message tokens.
*/
nsresult clearTokens();
uint32_t countTokens();
TokenEnumeration getTokens();
BaseToken* add(const char* word);
virtual ~TokenHash();
/**
* Clears out the previous message tokens.
*/
nsresult clearTokens();
uint32_t countTokens();
TokenEnumeration getTokens();
BaseToken* add(const char* word);
protected:
explicit TokenHash(uint32_t entrySize);
mozilla::ArenaAllocator<16384, 2> mWordPool;
uint32_t mEntrySize;
PLDHashTable mTokenTable;
char* copyWord(const char* word, uint32_t len);
BaseToken* get(const char* word);
protected:
explicit TokenHash(uint32_t entrySize);
mozilla::ArenaAllocator<16384, 2> mWordPool;
uint32_t mEntrySize;
PLDHashTable mTokenTable;
char* copyWord(const char* word, uint32_t len);
BaseToken* get(const char* word);
};
class Tokenizer: public TokenHash {
public:
Tokenizer();
~Tokenizer();
class Tokenizer : public TokenHash {
public:
Tokenizer();
~Tokenizer();
Token* get(const char* word);
Token* get(const char* word);
// 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,
//
Token* add(const char* word, uint32_t count = 1);
// 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,
//
Token* add(const char* word, uint32_t count = 1);
Token* copyTokens();
Token* copyTokens();
void tokenize(const char* text);
void tokenize(const char* text);
/**
* Creates specific tokens based on the mime headers for the message being tokenized
*/
void tokenizeHeaders(nsIUTF8StringEnumerator * aHeaderNames, nsIUTF8StringEnumerator * aHeaderValues);
/**
* Creates specific tokens based on the mime headers for the message being
* tokenized
*/
void tokenizeHeaders(nsIUTF8StringEnumerator* aHeaderNames,
nsIUTF8StringEnumerator* aHeaderValues);
void tokenizeAttachment(const char * aContentType, const char * aFileName);
void tokenizeAttachment(const char* aContentType, const char* aFileName);
nsCString mBodyDelimiters; // delimiters for body tokenization
nsCString mHeaderDelimiters; // delimiters for header tokenization
nsCString mBodyDelimiters; // delimiters for body tokenization
nsCString mHeaderDelimiters; // delimiters for header tokenization
// arrays of extra headers to tokenize / to not tokenize
nsTArray<nsCString> mEnabledHeaders;
nsTArray<nsCString> mDisabledHeaders;
// Delimiters used in tokenizing a particular header.
// Parallel array to mEnabledHeaders
nsTArray<nsCString> mEnabledHeadersDelimiters;
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;
// arrays of extra headers to tokenize / to not tokenize
nsTArray<nsCString> mEnabledHeaders;
nsTArray<nsCString> mDisabledHeaders;
// Delimiters used in tokenizing a particular header.
// Parallel array to mEnabledHeaders
nsTArray<nsCString> mEnabledHeadersDelimiters;
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);
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);
RefPtr<mozilla::intl::WordBreaker> mWordBreaker;
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);
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);
RefPtr<mozilla::intl::WordBreaker> mWordBreaker;
};
/**
@ -158,244 +160,243 @@ private:
* a corpus of classified messages
*/
class CorpusStore: public TokenHash {
public:
CorpusStore();
~CorpusStore();
class CorpusStore : public TokenHash {
public:
CorpusStore();
~CorpusStore();
/**
* retrieve the token structure for a particular string
*
* @param word the character representation of the token
*
* @return token structure containing counts, null if not found
*/
CorpusToken* get(const char* word);
/**
* retrieve the token structure for a particular string
*
* @param word the character representation of the token
*
* @return token structure containing counts, null if not found
*/
CorpusToken* get(const char* word);
/**
* add tokens to the storage, or increment counts if already exists.
*
* @param aTokenizer tokenizer for the list of tokens to remember
* @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);
/**
* add tokens to the storage, or increment counts if already exists.
*
* @param aTokenizer tokenizer for the list of tokens to remember
* @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);
/**
* decrement counts for tokens in the storage, removing if all counts
* are zero
*
* @param aTokenizer tokenizer for the list of tokens to forget
* @param aTraitId id for the trait whose counts will be removed
* @param aCount number of messages represented by the token list
*/
void forgetTokens(Tokenizer& aTokenizer, uint32_t aTraitId, uint32_t aCount);
/**
* decrement counts for tokens in the storage, removing if all counts
* are zero
*
* @param aTokenizer tokenizer for the list of tokens to forget
* @param aTraitId id for the trait whose counts will be removed
* @param aCount number of messages represented by the token list
*/
void forgetTokens(Tokenizer& aTokenizer, uint32_t aTraitId, uint32_t aCount);
/**
* write the corpus information to file storage
*
* @param aMaximumTokenCount prune tokens if number of tokens exceeds
* this value. == 0 for no pruning
*/
void writeTrainingData(uint32_t aMaximumTokenCount);
/**
* write the corpus information to file storage
*
* @param aMaximumTokenCount prune tokens if number of tokens exceeds
* this value. == 0 for no pruning
*/
void writeTrainingData(uint32_t aMaximumTokenCount);
/**
* read the corpus information from file storage
*/
void readTrainingData();
/**
* read the corpus information from file storage
*/
void readTrainingData();
/**
* delete the local corpus storage file and data
*/
nsresult resetTrainingData();
/**
* delete the local corpus storage file and data
*/
nsresult resetTrainingData();
/**
* get the count of messages whose tokens are stored that are associated
* with a trait
*
* @param aTraitId identifier for the trait
* @return number of messages for that trait
*/
uint32_t getMessageCount(uint32_t aTraitId);
/**
* get the count of messages whose tokens are stored that are associated
* with a trait
*
* @param aTraitId identifier for the trait
* @return number of messages for that trait
*/
uint32_t getMessageCount(uint32_t aTraitId);
/**
* set the count of messages whose tokens are stored that are associated
* with a trait
*
* @param aTraitId identifier for the trait
* @param aCount number of messages for that trait
*/
void setMessageCount(uint32_t aTraitId, uint32_t aCount);
/**
* set the count of messages whose tokens are stored that are associated
* with a trait
*
* @param aTraitId identifier for the trait
* @param aCount number of messages for that trait
*/
void setMessageCount(uint32_t aTraitId, uint32_t aCount);
/**
* get the count of messages associated with a particular token and trait
*
* @param token the token string and associated counts
* @param aTraitId identifier for the trait
*/
uint32_t getTraitCount(CorpusToken *token, uint32_t aTraitId);
/**
* get the count of messages associated with a particular token and trait
*
* @param token the token string and associated counts
* @param aTraitId identifier for the trait
*/
uint32_t getTraitCount(CorpusToken* token, uint32_t aTraitId);
/**
* Add (or remove) data from a particular file to the corpus data.
*
* @param aFile the file with the data, in the format:
*
* Format of the trait file for version 1:
* [0xFCA93601] (the 01 is the version)
* for each trait to write:
* [id of trait to write] (0 means end of list)
* [number of messages per trait]
* for each token with non-zero count
* [count]
* [length of word]word
*
* @param aIsAdd should the data be added, or removed? true if adding,
* else removing.
*
* @param aRemapCount number of items in the parallel arrays aFromTraits,
* aToTraits. These arrays allow conversion of the
* trait id stored in the file (which may be originated
* externally) to the trait id used in the local corpus
* (which is defined locally using nsIMsgTraitService).
*
* @param aFromTraits array of trait ids used in aFile. If aFile contains
* trait ids that are not in this array, they are not
* remapped, but assumed to be local trait ids.
*
* @param aToTraits array of trait ids, corresponding to elements of
* aFromTraits, that represent the local trait ids to be
* 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);
/**
* Add (or remove) data from a particular file to the corpus data.
*
* @param aFile the file with the data, in the format:
*
* Format of the trait file for version 1:
* [0xFCA93601] (the 01 is the version)
* for each trait to write:
* [id of trait to write] (0 means end of list)
* [number of messages per trait]
* for each token with non-zero count
* [count]
* [length of word]word
*
* @param aIsAdd should the data be added, or removed? true if adding,
* else removing.
*
* @param aRemapCount number of items in the parallel arrays aFromTraits,
* aToTraits. These arrays allow conversion of the
* trait id stored in the file (which may be originated
* externally) to the trait id used in the local corpus
* (which is defined locally using nsIMsgTraitService).
*
* @param aFromTraits array of trait ids used in aFile. If aFile contains
* trait ids that are not in this array, they are not
* remapped, but assumed to be local trait ids.
*
* @param aToTraits array of trait ids, corresponding to elements of
* aFromTraits, that represent the local trait ids to be
* 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);
/**
* remove all counts (message and tokens) for a trait id
*
* @param aTrait trait id for the trait to remove
*/
nsresult ClearTrait(uint32_t aTrait);
/**
* remove all counts (message and tokens) for a trait id
*
* @param aTrait trait id for the trait to remove
*/
nsresult ClearTrait(uint32_t aTrait);
protected:
protected:
/**
* return the local corpus storage file for junk traits
*/
nsresult getTrainingFile(nsIFile** aFile);
/**
* return the local corpus storage file for junk traits
*/
nsresult getTrainingFile(nsIFile ** aFile);
/**
* return the local corpus storage file for non-junk traits
*/
nsresult getTraitFile(nsIFile** aFile);
/**
* return the local corpus storage file for non-junk traits
*/
nsresult getTraitFile(nsIFile ** aFile);
/**
* read token strings from the data file
*
* @param stream file stream with token data
* @param fileSize file size
* @param aTraitId id for the trait whose counts will be read
* @param aIsAdd true to add the counts, false to remove them
*
* @return true if successful, false if error
*/
bool readTokens(FILE* stream, int64_t fileSize, uint32_t aTraitId,
bool aIsAdd);
/**
* read token strings from the data file
*
* @param stream file stream with token data
* @param fileSize file size
* @param aTraitId id for the trait whose counts will be read
* @param aIsAdd true to add the counts, false to remove them
*
* @return true if successful, false if error
*/
bool readTokens(FILE* stream, int64_t fileSize, uint32_t aTraitId,
bool aIsAdd);
/**
* write token strings to the data file
*/
bool writeTokens(FILE* stream, bool shrink, uint32_t aTraitId);
/**
* write token strings to the data file
*/
bool writeTokens(FILE* stream, bool shrink, uint32_t aTraitId);
/**
* remove counts for a token string
*/
void remove(const char* word, uint32_t aTraitId, uint32_t aCount);
/**
* remove counts for a token string
*/
void remove(const char* word, uint32_t aTraitId, uint32_t aCount);
/**
* add counts for a token string, adding the token string if new
*/
CorpusToken* add(const char* word, uint32_t aTraitId, uint32_t aCount);
/**
* add counts for a token string, adding the token string if new
*/
CorpusToken* add(const char* word, uint32_t aTraitId, uint32_t aCount);
/**
* change counts in a trait in the traits array, adding the trait if needed
*/
nsresult updateTrait(CorpusToken* token, uint32_t aTraitId,
int32_t aCountChange);
nsCOMPtr<nsIFile> mTrainingFile; // file used to store junk training data
nsCOMPtr<nsIFile> mTraitFile; // file used to store non-junk
// training data
nsTArray<TraitPerToken> mTraitStore; // memory for linked-list of counts
uint32_t mNextTraitIndex; // index in mTraitStore to first empty
// 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
/**
* change counts in a trait in the traits array, adding the trait if needed
*/
nsresult updateTrait(CorpusToken* token, uint32_t aTraitId,
int32_t aCountChange);
nsCOMPtr<nsIFile> mTrainingFile; // file used to store junk training data
nsCOMPtr<nsIFile> mTraitFile; // file used to store non-junk
// training data
nsTArray<TraitPerToken> mTraitStore; // memory for linked-list of counts
uint32_t mNextTraitIndex; // index in mTraitStore to first empty
// 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
};
class nsBayesianFilter : public nsIJunkMailPlugin, nsIMsgCorpus,
nsIObserver, nsSupportsWeakReference {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGFILTERPLUGIN
NS_DECL_NSIJUNKMAILPLUGIN
NS_DECL_NSIMSGCORPUS
NS_DECL_NSIOBSERVER
class nsBayesianFilter : public nsIJunkMailPlugin,
nsIMsgCorpus,
nsIObserver,
nsSupportsWeakReference {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGFILTERPLUGIN
NS_DECL_NSIJUNKMAILPLUGIN
NS_DECL_NSIMSGCORPUS
NS_DECL_NSIOBSERVER
nsBayesianFilter();
nsBayesianFilter();
nsresult Init();
nsresult Init();
nsresult tokenizeMessage(const char* messageURI, nsIMsgWindow *aMsgWindow, TokenAnalyzer* analyzer);
void classifyMessage(Tokenizer& tokens, const char* messageURI,
nsIJunkMailClassificationListener* listener);
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,
nsTArray<uint32_t>& aProTraits,
nsTArray<uint32_t>& aAntiTraits,
nsIJunkMailClassificationListener* listener,
nsIMsgTraitClassificationListener* aTraitListener,
nsIMsgTraitDetailListener* aDetailListener);
void classifyMessage(Tokenizer& tokenizer, const char* messageURI,
nsTArray<uint32_t>& aProTraits,
nsTArray<uint32_t>& aAntiTraits,
nsIJunkMailClassificationListener* listener,
nsIMsgTraitClassificationListener* aTraitListener,
nsIMsgTraitDetailListener* aDetailListener);
void observeMessage(Tokenizer& tokens, const char* messageURI,
nsTArray<uint32_t>& oldClassifications,
nsTArray<uint32_t>& newClassifications,
nsIJunkMailClassificationListener* listener,
nsIMsgTraitClassificationListener* aTraitListener);
void observeMessage(Tokenizer& tokens, const char* messageURI,
nsTArray<uint32_t>& oldClassifications,
nsTArray<uint32_t>& newClassifications,
nsIJunkMailClassificationListener* listener,
nsIMsgTraitClassificationListener* aTraitListener);
protected:
virtual ~nsBayesianFilter();
protected:
virtual ~nsBayesianFilter();
static void TimerCallback(nsITimer* aTimer, void* aClosure);
static void TimerCallback(nsITimer* aTimer, void* aClosure);
CorpusStore mCorpus;
double mJunkProbabilityThreshold;
int32_t mMaximumTokenCount;
bool mTrainingDataDirty;
int32_t mMinFlushInterval; // in milliseconds, must be positive
// and not too close to 0
nsCOMPtr<nsITimer> mTimer;
CorpusStore mCorpus;
double mJunkProbabilityThreshold;
int32_t mMaximumTokenCount;
bool mTrainingDataDirty;
int32_t mMinFlushInterval; // in milliseconds, must be positive
//and not too close to 0
nsCOMPtr<nsITimer> mTimer;
// index in mAnalysisStore for first empty AnalysisPerToken
uint32_t mNextAnalysisIndex;
// memory for linked list of AnalysisPerToken objects
nsTArray<AnalysisPerToken> mAnalysisStore;
/**
* Determine the location in mAnalysisStore where the AnalysisPerToken
* object for a particular token and trait is stored
*/
uint32_t getAnalysisIndex(Token& token, uint32_t aTraitIndex);
/**
* Set the value of the AnalysisPerToken object for a particular
* token and trait
*/
nsresult setAnalysis(Token& token, uint32_t aTraitIndex,
double aDistance, double aProbability);
// index in mAnalysisStore for first empty AnalysisPerToken
uint32_t mNextAnalysisIndex;
// memory for linked list of AnalysisPerToken objects
nsTArray<AnalysisPerToken> mAnalysisStore;
/**
* Determine the location in mAnalysisStore where the AnalysisPerToken
* object for a particular token and trait is stored
*/
uint32_t getAnalysisIndex(Token& token, uint32_t aTraitIndex);
/**
* Set the value of the AnalysisPerToken object for a particular
* token and trait
*/
nsresult setAnalysis(Token& token, uint32_t aTraitIndex, double aDistance,
double aProbability);
};
#endif // _nsBayesianFilter_h__
#endif // _nsBayesianFilter_h__

Просмотреть файл

@ -8,9 +8,11 @@
#define NS_BAYESIANFILTER_CONTRACTID \
"@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 }}
#define NS_BAYESIANFILTER_CID \
{ /* F1070BFA-D539-11D6-90CA-00039310A47A */ \
0xF1070BFA, 0xD539, 0x11D6, { \
0x90, 0xCA, 0x00, 0x03, 0x93, 0x10, 0xA4, 0x7A \
} \
}
#endif /* nsBayesianFilterCID_h__ */

Просмотреть файл

@ -56,7 +56,7 @@
#include <float.h>
// the main routine
static double nsIncompleteGammaP (double a, double x, int *error);
static double nsIncompleteGammaP(double a, double x, int *error);
// nsLnGamma(z): either a wrapper around lgamma_r or the internal function.
// C_m = B[2*m]/(2*m*(2*m-1)) where B is a Bernoulli number
@ -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,9 +118,8 @@ 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}
};
#define FactTableLength (int)(sizeof(FactTable)/sizeof(FactTable[0]))
{6402373705728000., 3.6395445208033053576674e+01}};
#define FactTableLength (int)(sizeof(FactTable) / sizeof(FactTable[0]))
// for speed
static const double ln_2pi_2 = 0.918938533204672741803; // log(2*PI)/2
@ -127,133 +133,107 @@ 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)
{
int zi = (int)z_in;
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);
sum = lngamma_asymp(z);
result = (z - 0.5) * log(z) - z + ln_2pi_2 - log(scale);
result += sum;
return result;
}
// 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);
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);
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);
result = dom * Pseries(a, x, error);
else
result = 1.0 - dom * Qcontfrac (a, x, error);
}
else
{
result = 1.0 - dom * Qcontfrac(a, x, error);
} else {
if (x < a)
result = dom * Pseries (a, x, error);
result = dom * Pseries(a, x, error);
else
result = 1.0 - dom * Qcontfrac (a, x, error);
result = 1.0 - dom * Qcontfrac(a, x, 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

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -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,10 +72,9 @@ 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 */
const char *const*argv, /* Tokenizer argument strings */
sqlite3_tokenizer **ppTokenizer /* OUT: Created tokenizer */
int (*xCreate)(int argc, /* Size of argv array */
const char *const *argv, /* Tokenizer argument strings */
sqlite3_tokenizer **ppTokenizer /* OUT: Created tokenizer */
);
/*
@ -91,9 +89,9 @@ struct sqlite3_tokenizer_module {
** until the cursor is closed (using the xClose() method).
*/
int (*xOpen)(
sqlite3_tokenizer *pTokenizer, /* Tokenizer object */
const char *pInput, int nBytes, /* Input buffer */
sqlite3_tokenizer_cursor **ppCursor /* OUT: Created tokenizer cursor */
sqlite3_tokenizer *pTokenizer, /* Tokenizer object */
const char *pInput, int nBytes, /* Input buffer */
sqlite3_tokenizer_cursor **ppCursor /* OUT: Created tokenizer cursor */
);
/*
@ -127,21 +125,21 @@ struct sqlite3_tokenizer_module {
** should be converted to zInput.
*/
int (*xNext)(
sqlite3_tokenizer_cursor *pCursor, /* Tokenizer cursor */
const char **ppToken, int *pnBytes, /* OUT: Normalized text for token */
int *piStartOffset, /* OUT: Byte offset of token in input buffer */
int *piEndOffset, /* OUT: Byte offset of end of token in input buffer */
int *piPosition /* OUT: Number of tokens returned before this one */
sqlite3_tokenizer_cursor *pCursor, /* Tokenizer cursor */
const char **ppToken, int *pnBytes, /* OUT: Normalized text for token */
int *piStartOffset, /* OUT: Byte offset of token in input buffer */
int *piEndOffset, /* OUT: Byte offset of end of token in input buffer */
int *piPosition /* OUT: Number of tokens returned before this one */
);
};
struct sqlite3_tokenizer {
const sqlite3_tokenizer_module *pModule; /* The module for this tokenizer */
const sqlite3_tokenizer_module *pModule; /* The module for this tokenizer */
/* Tokenizer implementations will typically add additional fields */
};
struct sqlite3_tokenizer_cursor {
sqlite3_tokenizer *pTokenizer; /* Tokenizer for this cursor. */
sqlite3_tokenizer *pTokenizer; /* Tokenizer for this cursor. */
/* Tokenizer implementations will typically add additional fields */
};

Просмотреть файл

@ -13,45 +13,36 @@
#include "nsString.h"
extern "C" void sqlite3Fts3PorterTokenizerModule(
sqlite3_tokenizer_module const**ppModule);
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)
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)"),
getter_AddRefs(selectStatement));
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;
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"),
-1, // variable argument support
func
);
rv = connection->CreateFunction(NS_LITERAL_CSTRING("glodaRank"),
-1, // variable argument support
func);
NS_ENSURE_SUCCESS(rv, rv);
return rv;

Просмотреть файл

@ -13,13 +13,13 @@
extern const sqlite3_tokenizer_module* getWindowsTokenizer();
class nsFts3Tokenizer final : public nsIFts3Tokenizer {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFTS3TOKENIZER
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFTS3TOKENIZER
nsFts3Tokenizer();
nsFts3Tokenizer();
private:
private:
~nsFts3Tokenizer();
};

Просмотреть файл

@ -6,10 +6,12 @@
#ifndef nsFts3TokenizerCID_h__
#define nsFts3TokenizerCID_h__
#define NS_FTS3TOKENIZER_CONTRACTID \
"@mozilla.org/messenger/fts3tokenizer;1"
#define NS_FTS3TOKENIZER_CID \
{ 0xa67d724d, 0x0015, 0x4e2e, \
{ 0x8c, 0xad, 0xb8, 0x47, 0x75, 0x33, 0x09, 0x24 }}
#define NS_FTS3TOKENIZER_CONTRACTID "@mozilla.org/messenger/fts3tokenizer;1"
#define NS_FTS3TOKENIZER_CID \
{ \
0xa67d724d, 0x0015, 0x4e2e, { \
0x8c, 0xad, 0xb8, 0x47, 0x75, 0x33, 0x09, 0x24 \
} \
}
#endif /* nsFts3TokenizerCID_h__ */

Просмотреть файл

@ -12,18 +12,14 @@
#include "nsComponentManagerUtils.h"
#ifndef SQLITE_VERSION_NUMBER
#error "We need SQLITE_VERSION_NUMBER defined!"
# error "We need SQLITE_VERSION_NUMBER defined!"
#endif
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;
@ -69,12 +62,12 @@ nsGlodaRankerFunction::OnFunctionCall(mozIStorageValueArray *aArguments,
for (uint32_t iPhrase = 0; iPhrase < nPhrase; iPhrase++) {
// in SQ
for (uint32_t iCol = 0; iCol < nCol; iCol++) {
uint32_t nHitCount = aArgsData[2 + (iPhrase+1)*nCol + iCol];
double weight = aArguments->AsDouble(iCol+1);
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);
}
}
}
@ -90,14 +83,14 @@ nsGlodaRankerFunction::OnFunctionCall(mozIStorageValueArray *aArguments,
** the hit count and global hit counts for each column are found in
** aPhraseinfo[iCol*3] and aPhraseinfo[iCol*3+1], respectively.
*/
uint32_t *aPhraseinfo = &aArgsData[2 + iPhrase*nCol*3];
uint32_t *aPhraseinfo = &aArgsData[2 + iPhrase * nCol * 3];
for (uint32_t iCol = 0; iCol < nCol; iCol++) {
uint32_t nHitCount = aPhraseinfo[3 * iCol];
double weight = aArguments->AsDouble(iCol+1);
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,15 +11,15 @@
* 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
{
public:
class nsGlodaRankerFunction final : public mozIStorageFunction {
public:
NS_DECL_ISUPPORTS
NS_DECL_MOZISTORAGEFUNCTION
nsGlodaRankerFunction();
private:
private:
~nsGlodaRankerFunction();
};
#endif // _nsGlodaRankerFunction_h_
#endif // _nsGlodaRankerFunction_h_

Просмотреть файл

@ -24,287 +24,265 @@
#define kDefaultViewNotJunk "Not Junk"
#define kDefaultViewHasAttachments "Has Attachments"
nsMsgMailView::nsMsgMailView()
{
mViewSearchTerms = nsArray::Create();
NS_ASSERTION(mViewSearchTerms, "Failed to allocate a nsIMutableArray for mViewSearchTerms");
nsMsgMailView::nsMsgMailView() {
mViewSearchTerms = nsArray::Create();
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_ENSURE_ARG_POINTER(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) {
mName = aMailViewName;
return NS_OK;
}
NS_IMETHODIMP nsMsgMailView::GetPrettyName(char16_t **aMailViewName) {
NS_ENSURE_ARG_POINTER(aMailViewName);
nsresult rv = NS_OK;
if (!mBundle) {
nsCOMPtr<nsIStringBundleService> bundleService =
mozilla::services::GetStringBundleService();
NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
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
nsAutoString mailViewName;
if (mName.EqualsLiteral(kDefaultViewPeopleIKnow)) {
rv = mBundle->GetStringFromName("mailViewPeopleIKnow", mailViewName);
*aMailViewName = ToNewUnicode(mailViewName);
} else if (mName.EqualsLiteral(kDefaultViewRecent)) {
rv = mBundle->GetStringFromName("mailViewRecentMail", mailViewName);
*aMailViewName = ToNewUnicode(mailViewName);
} else if (mName.EqualsLiteral(kDefaultViewFiveDays)) {
rv = mBundle->GetStringFromName("mailViewLastFiveDays", mailViewName);
*aMailViewName = ToNewUnicode(mailViewName);
} else if (mName.EqualsLiteral(kDefaultViewNotJunk)) {
rv = mBundle->GetStringFromName("mailViewNotJunk", mailViewName);
*aMailViewName = ToNewUnicode(mailViewName);
} else if (mName.EqualsLiteral(kDefaultViewHasAttachments)) {
rv = mBundle->GetStringFromName("mailViewHasAttachments", mailViewName);
*aMailViewName = ToNewUnicode(mailViewName);
} else {
*aMailViewName = ToNewUnicode(mName);
return NS_OK;
}
return rv;
}
NS_IMETHODIMP nsMsgMailView::SetMailViewName(const char16_t * aMailViewName)
{
mName = aMailViewName;
return NS_OK;
NS_IMETHODIMP nsMsgMailView::GetSearchTerms(nsIMutableArray **aSearchTerms) {
NS_ENSURE_ARG_POINTER(aSearchTerms);
NS_IF_ADDREF(*aSearchTerms = mViewSearchTerms);
return NS_OK;
}
NS_IMETHODIMP nsMsgMailView::GetPrettyName(char16_t ** aMailViewName)
{
NS_ENSURE_ARG_POINTER(aMailViewName);
nsresult rv = NS_OK;
if (!mBundle)
{
nsCOMPtr<nsIStringBundleService> bundleService =
mozilla::services::GetStringBundleService();
NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
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
nsAutoString mailViewName;
if (mName.EqualsLiteral(kDefaultViewPeopleIKnow)) {
rv = mBundle->GetStringFromName("mailViewPeopleIKnow", mailViewName);
*aMailViewName = ToNewUnicode(mailViewName);
} else if (mName.EqualsLiteral(kDefaultViewRecent)) {
rv = mBundle->GetStringFromName("mailViewRecentMail", mailViewName);
*aMailViewName = ToNewUnicode(mailViewName);
} else if (mName.EqualsLiteral(kDefaultViewFiveDays)) {
rv = mBundle->GetStringFromName("mailViewLastFiveDays", mailViewName);
*aMailViewName = ToNewUnicode(mailViewName);
} else if (mName.EqualsLiteral(kDefaultViewNotJunk)) {
rv = mBundle->GetStringFromName("mailViewNotJunk", mailViewName);
*aMailViewName = ToNewUnicode(mailViewName);
} else if (mName.EqualsLiteral(kDefaultViewHasAttachments)) {
rv = mBundle->GetStringFromName("mailViewHasAttachments", mailViewName);
*aMailViewName = ToNewUnicode(mailViewName);
} else {
*aMailViewName = ToNewUnicode(mName);
}
return rv;
NS_IMETHODIMP nsMsgMailView::SetSearchTerms(nsIMutableArray *aSearchTerms) {
mViewSearchTerms = aSearchTerms;
return NS_OK;
}
NS_IMETHODIMP nsMsgMailView::GetSearchTerms(nsIMutableArray **aSearchTerms)
{
NS_ENSURE_ARG_POINTER(aSearchTerms);
NS_IF_ADDREF(*aSearchTerms = mViewSearchTerms);
return NS_OK;
NS_IMETHODIMP nsMsgMailView::AppendTerm(nsIMsgSearchTerm *aTerm) {
NS_ENSURE_TRUE(aTerm, NS_ERROR_NULL_POINTER);
return mViewSearchTerms->AppendElement(aTerm);
}
NS_IMETHODIMP nsMsgMailView::SetSearchTerms(nsIMutableArray *aSearchTerms)
{
mViewSearchTerms = aSearchTerms;
return NS_OK;
}
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_ENSURE_ARG_POINTER(aResult);
nsCOMPtr<nsIMsgSearchTerm> searchTerm = do_CreateInstance("@mozilla.org/messenger/searchTerm;1");
searchTerm.forget(aResult);
return NS_OK;
NS_IMETHODIMP nsMsgMailView::CreateTerm(nsIMsgSearchTerm **aResult) {
NS_ENSURE_ARG_POINTER(aResult);
nsCOMPtr<nsIMsgSearchTerm> searchTerm =
do_CreateInstance("@mozilla.org/messenger/searchTerm;1");
searchTerm.forget(aResult);
return NS_OK;
}
/////////////////////////////////////////////////////////////////////////////
// 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_ENSURE_ARG_POINTER(aCount);
*aCount = m_mailViews.Length();
return NS_OK;
}
NS_IMETHODIMP nsMsgMailViewList::GetMailViewCount(uint32_t * aCount)
{
NS_ENSURE_ARG_POINTER(aCount);
NS_IMETHODIMP nsMsgMailViewList::GetMailViewAt(uint32_t aMailViewIndex,
nsIMsgMailView **aMailView) {
NS_ENSURE_ARG_POINTER(aMailView);
*aCount = m_mailViews.Length();
return NS_OK;
uint32_t mailViewCount = m_mailViews.Length();
NS_ENSURE_ARG(mailViewCount > aMailViewIndex);
NS_IF_ADDREF(*aMailView = m_mailViews[aMailViewIndex]);
return NS_OK;
}
NS_IMETHODIMP nsMsgMailViewList::GetMailViewAt(uint32_t aMailViewIndex, nsIMsgMailView ** aMailView)
{
NS_ENSURE_ARG_POINTER(aMailView);
NS_IMETHODIMP nsMsgMailViewList::AddMailView(nsIMsgMailView *aMailView) {
NS_ENSURE_ARG_POINTER(aMailView);
uint32_t mailViewCount = m_mailViews.Length();
NS_ENSURE_ARG(mailViewCount > aMailViewIndex);
NS_IF_ADDREF(*aMailView = m_mailViews[aMailViewIndex]);
return NS_OK;
m_mailViews.AppendElement(aMailView);
return NS_OK;
}
NS_IMETHODIMP nsMsgMailViewList::AddMailView(nsIMsgMailView * aMailView)
{
NS_ENSURE_ARG_POINTER(aMailView);
NS_IMETHODIMP nsMsgMailViewList::RemoveMailView(nsIMsgMailView *aMailView) {
NS_ENSURE_ARG_POINTER(aMailView);
m_mailViews.AppendElement(aMailView);
return NS_OK;
m_mailViews.RemoveElement(aMailView);
return NS_OK;
}
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_ENSURE_ARG_POINTER(aMailView);
NS_ADDREF(*aMailView = new nsMsgMailView);
return NS_OK;
}
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
nsCOMPtr<nsIMsgFilter> msgFilter;
uint32_t numFilters = 0;
if (mFilterList) mFilterList->GetFilterCount(&numFilters);
while (numFilters) {
mFilterList->RemoveFilterAt(numFilters - 1);
numFilters--;
}
// now convert our mail view list into a filter list and save it
ConvertMailViewListToFilterList();
// now save the filters to our file
return mFilterList ? mFilterList->SaveToDefaultFile() : NS_ERROR_FAILURE;
}
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)
{
mFilterList->RemoveFilterAt(numFilters - 1);
numFilters--;
}
// now convert our mail view list into a filter list and save it
ConvertMailViewListToFilterList();
// now save the filters to our file
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++)
{
GetMailViewAt(index, getter_AddRefs(mailView));
if (!mailView)
continue;
mailView->GetMailViewName(getter_Copies(mailViewName));
mFilterList->CreateFilter(mailViewName, getter_AddRefs(newMailFilter));
if (!newMailFilter)
continue;
for (uint32_t index = 0; index < mailViewCount; index++) {
GetMailViewAt(index, getter_AddRefs(mailView));
if (!mailView) continue;
mailView->GetMailViewName(getter_Copies(mailViewName));
mFilterList->CreateFilter(mailViewName, getter_AddRefs(newMailFilter));
if (!newMailFilter) continue;
nsCOMPtr<nsIMutableArray> searchTerms;
mailView->GetSearchTerms(getter_AddRefs(searchTerms));
newMailFilter->SetSearchTerms(searchTerms);
mFilterList->InsertFilterAt(index, newMailFilter);
nsCOMPtr<nsIMutableArray> searchTerms;
mailView->GetSearchTerms(getter_AddRefs(searchTerms));
newMailFilter->SetSearchTerms(searchTerms);
mFilterList->InsertFilterAt(index, newMailFilter);
}
return NS_OK;
}
nsresult nsMsgMailViewList::LoadMailViews()
{
nsCOMPtr<nsIFile> file;
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file));
nsresult nsMsgMailViewList::LoadMailViews() {
nsCOMPtr<nsIFile> 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
bool exists = false;
file->Exists(&exists);
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 = defaultMessagesFile->AppendNative(nsDependentCString("mailViews.dat"));
rv = file->AppendNative(nsDependentCString("mailViews.dat"));
// get the profile directory
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(profileDir));
// 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);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFile> defaultMessagesFile;
nsCOMPtr<nsIFile> profileDir;
rv = mailSession->GetDataFilesDir("messenger", getter_AddRefs(defaultMessagesFile));
rv = defaultMessagesFile->AppendNative(nsDependentCString("mailViews.dat"));
// 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.
// get the profile directory
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir));
nsCOMPtr<nsIMsgFilterService> filterService =
do_GetService(NS_MSGFILTERSERVICE_CONTRACTID, &rv);
nsCOMPtr<nsIMsgFilterList> mfilterList;
// 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.
rv = filterService->OpenFilterList(file, nullptr, nullptr,
getter_AddRefs(mFilterList));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIMsgFilterService> filterService = do_GetService(NS_MSGFILTERSERVICE_CONTRACTID, &rv);
nsCOMPtr<nsIMsgFilterList> mfilterList;
rv = filterService->OpenFilterList(file, nullptr, nullptr, getter_AddRefs(mFilterList));
NS_ENSURE_SUCCESS(rv, rv);
return ConvertFilterListToMailViews();
return ConvertFilterListToMailViews();
}
/**
* Converts the filter list into our mail view objects,
* stripping out just the info we need.
*/
nsresult nsMsgMailViewList::ConvertFilterListToMailViews()
{
nsresult rv = NS_OK;
m_mailViews.Clear();
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++)
{
nsCOMPtr<nsIMsgFilter> msgFilter;
rv = mFilterList->GetFilterAt(index, getter_AddRefs(msgFilter));
if (NS_FAILED(rv) || !msgFilter)
continue;
// iterate over each filter in the list
uint32_t numFilters = 0;
mFilterList->GetFilterCount(&numFilters);
for (uint32_t index = 0; index < numFilters; index++) {
nsCOMPtr<nsIMsgFilter> msgFilter;
rv = mFilterList->GetFilterAt(index, getter_AddRefs(msgFilter));
if (NS_FAILED(rv) || !msgFilter) continue;
// create a new nsIMsgMailView for this item
nsCOMPtr<nsIMsgMailView> newMailView;
rv = CreateMailView(getter_AddRefs(newMailView));
NS_ENSURE_SUCCESS(rv, rv);
// create a new nsIMsgMailView for this item
nsCOMPtr<nsIMsgMailView> newMailView;
rv = CreateMailView(getter_AddRefs(newMailView));
NS_ENSURE_SUCCESS(rv, rv);
nsString filterName;
msgFilter->GetFilterName(filterName);
newMailView->SetMailViewName(filterName.get());
nsString filterName;
msgFilter->GetFilterName(filterName);
newMailView->SetMailViewName(filterName.get());
nsCOMPtr<nsIMutableArray> filterSearchTerms;
rv = msgFilter->GetSearchTerms(getter_AddRefs(filterSearchTerms));
NS_ENSURE_SUCCESS(rv, rv);
rv = newMailView->SetSearchTerms(filterSearchTerms);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIMutableArray> filterSearchTerms;
rv = msgFilter->GetSearchTerms(getter_AddRefs(filterSearchTerms));
NS_ENSURE_SUCCESS(rv, rv);
rv = newMailView->SetSearchTerms(filterSearchTerms);
NS_ENSURE_SUCCESS(rv, rv);
// now append this new mail view to our global list view
m_mailViews.AppendElement(newMailView);
}
// now append this new mail view to our global list view
m_mailViews.AppendElement(newMailView);
}
return rv;
return rv;
}

Просмотреть файл

@ -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,38 +16,37 @@
#include "nsIMsgFilterList.h"
// a mail View is just a name and an array of search terms
class nsMsgMailView : public nsIMsgMailView
{
public:
class nsMsgMailView : public nsIMsgMailView {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGMAILVIEW
nsMsgMailView();
protected:
protected:
virtual ~nsMsgMailView();
nsString mName;
nsCOMPtr<nsIStringBundle> mBundle;
nsCOMPtr<nsIMutableArray> mViewSearchTerms;
};
class nsMsgMailViewList : public nsIMsgMailViewList
{
public:
class nsMsgMailViewList : public nsIMsgMailViewList {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGMAILVIEWLIST
nsMsgMailViewList();
protected:
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 }}
#define NS_MSGMAILVIEWLIST_CID \
{ /* A0258267-44FD-4886-A858-8192615178EC */ \
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_CID \
{ /* ec917b13-8f73-4d4d-9146-d7f7aafe9076 */ \
0xec917b13, 0x8f73, 0x4d4d, \
{ 0x91, 0x46, 0xd7, 0xf7, 0xaa, 0xfe, 0x90, 0x76 }}
#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 \
} \
}
#endif /* nsMsgMdnCID_h__ */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -18,25 +18,24 @@
#include "nsString.h"
#include "MailNewsTypes2.h"
#define eNeverSendOp ((int32_t) 0)
#define eAutoSendOp ((int32_t) 1)
#define eAskMeOp ((int32_t) 2)
#define eDeniedOp ((int32_t) 3)
#define eNeverSendOp ((int32_t)0)
#define eAutoSendOp ((int32_t)1)
#define eAskMeOp ((int32_t)2)
#define eDeniedOp ((int32_t)3)
class nsMsgMdnGenerator : public nsIMsgMdnGenerator, public nsIUrlListener
{
public:
class nsMsgMdnGenerator : public nsIMsgMdnGenerator, public nsIUrlListener {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGMDNGENERATOR
NS_DECL_NSIURLLISTENER
nsMsgMdnGenerator();
private:
private:
virtual ~nsMsgMdnGenerator();
// Sanity Check methods
bool ProcessSendMode(); // must called prior ValidateReturnPath
bool ProcessSendMode(); // must called prior ValidateReturnPath
bool ValidateReturnPath();
bool NotInToOrCc();
bool MailAddrMatch(const char *addr1, const char *addr2);
@ -52,17 +51,16 @@ private:
nsresult SendMdnMsg();
// string bundle helper methods
nsresult GetStringFromName(const char *aName, nsAString& aResultString);
nsresult FormatStringFromName(const char *aName,
const char16_t *aString,
nsAString& aResultString);
nsresult GetStringFromName(const char *aName, nsAString &aResultString);
nsresult FormatStringFromName(const char *aName, const char16_t *aString,
nsAString &aResultString);
// other helper methods
nsresult InitAndProcess(bool *needToAskUser);
nsresult OutputAllHeaders();
nsresult WriteString(const char *str);
private:
private:
EDisposeType m_disposeType;
nsCOMPtr<nsIMsgWindow> m_window;
nsCOMPtr<nsIOutputStream> m_outputStream;
@ -86,5 +84,4 @@ private:
bool m_mdnEnabled;
};
#endif // _nsMsgMdnGenerator_H_
#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()),
const_cast<char*>(aUtf8NotYetValidString.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);
@ -142,16 +140,11 @@ FormatUIStrings(nsIX509Cert* cert, const nsAutoString& nickname,
}
nsAutoString firstEmail;
const char* aWalkAddr;
for (aWalkAddr = CERT_GetFirstEmailAddress(nssCert.get())
;
aWalkAddr
;
aWalkAddr = CERT_GetNextEmailAddress(nssCert.get(), aWalkAddr))
{
const char *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,21 +221,18 @@ 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;
*canceled = false;
nsCOMPtr<nsIDialogParamBlock> block =
do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID);
if (!block) return NS_ERROR_FAILURE;
block->SetNumberStrings(1+count*2);
block->SetNumberStrings(1 + count * 2);
for (i = 0; i < count; i++) {
rv = block->SetString(i, certNickList[i]);
@ -257,7 +240,7 @@ nsCertPicker::PickCertificate(nsIInterfaceRequestor *ctx,
}
for (i = 0; i < count; i++) {
rv = block->SetString(i+count, certDetailsList[i]);
rv = block->SetString(i + count, certDetailsList[i]);
if (NS_FAILED(rv)) return rv;
}
@ -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;
@ -277,7 +259,7 @@ nsCertPicker::PickCertificate(nsIInterfaceRequestor *ctx,
rv = block->GetInt(0, &status);
if (NS_FAILED(rv)) return rv;
*canceled = (status == 0)?true:false;
*canceled = (status == 0) ? true : false;
if (!*canceled) {
rv = block->GetInt(1, selectedIndex);
}
@ -286,34 +268,29 @@ 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;
char16_t **certDetailsList = nullptr;
CERTCertListNode* node = nullptr;
CERTCertListNode *node = nullptr;
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;
}
@ -334,7 +311,7 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx,
}
if (!match) {
/* doesn't contain the specified address, so remove from the list */
CERTCertListNode* freenode = node;
CERTCertListNode *freenode = node;
node = CERT_LIST_NEXT(node);
CERT_RemoveCertListNode(freenode);
continue;
@ -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);
@ -362,15 +341,13 @@ 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)
)
{
CertsToUse < nicknames->numnicknames;
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;
}
@ -410,8 +386,8 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx,
if (NS_SUCCEEDED(rv)) {
// Show the cert picker dialog and get the index of the selected cert.
rv = dialogs->PickCertificate(ctx, (const char16_t**)certNicknameList,
(const char16_t**)certDetailsList,
rv = dialogs->PickCertificate(ctx, (const char16_t **)certNicknameList,
(const char16_t **)certDetailsList,
CertsToUse, &selectedIndex, canceled);
}
}
@ -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) {

Просмотреть файл

@ -9,13 +9,15 @@
#include "nsICertPickDialogs.h"
#include "nsIUserCertPicker.h"
#define NS_CERT_PICKER_CID \
{ 0x735959a1, 0xaf01, 0x447e, { 0xb0, 0x2d, 0x56, 0xe9, 0x68, 0xfa, 0x52, 0xb4 } }
#define NS_CERT_PICKER_CID \
{ \
0x735959a1, 0xaf01, 0x447e, { \
0xb0, 0x2d, 0x56, 0xe9, 0x68, 0xfa, 0x52, 0xb4 \
} \
}
class nsCertPicker : public nsICertPickDialogs
, public nsIUserCertPicker
{
public:
class nsCertPicker : public nsICertPickDialogs, public nsIUserCertPicker {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICERTPICKDIALOGS
NS_DECL_NSIUSERCERTPICKER
@ -23,8 +25,8 @@ public:
nsCertPicker();
nsresult Init();
protected:
protected:
virtual ~nsCertPicker();
};
#endif // nsCertPicker_h
#endif // nsCertPicker_h

Просмотреть файл

@ -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,15 +9,14 @@
#include "nsTArray.h"
#include "nsString.h"
class nsEncryptedSMIMEURIsService : public nsIEncryptedSMIMEURIsService
{
public:
class nsEncryptedSMIMEURIsService : public nsIEncryptedSMIMEURIsService {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIENCRYPTEDSMIMEURISSERVICE
nsEncryptedSMIMEURIsService();
protected:
protected:
virtual ~nsEncryptedSMIMEURIsService();
nsTArray<nsCString> mEncryptedURIs;
};

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -23,7 +23,7 @@ namespace mozilla {
namespace mailnews {
class MimeEncoder;
}
}
} // namespace mozilla
typedef enum {
mime_crypto_none, /* normal unencapsulated MIME message */
@ -33,31 +33,36 @@ typedef enum {
mime_crypto_signed_encrypted /* application/x-pkcs7-mime */
} mimeDeliveryCryptoState;
class nsMsgComposeSecure : public nsIMsgComposeSecure
{
public:
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:
private:
virtual ~nsMsgComposeSecure();
typedef mozilla::mailnews::MimeEncoder MimeEncoder;
nsresult MimeInitMultipartSigned(bool aOuter, nsIMsgSendReport *sendReport);
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 MimeFinishMultipartSigned(bool aOuter, nsIMsgSendReport *sendReport);
nsresult MimeFinishEncryption(bool aSign, nsIMsgSendReport *sendReport);
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);
nsAString &outString);
nsresult ExtractEncryptionState(nsIMsgIdentity *aIdentity,
nsIMsgCompFields *aComposeFields,
bool *aSignMessage, bool *aEncrypt);
bool mSignMessage;
bool mAlwaysEncryptMessage;
@ -81,13 +86,14 @@ private:
nsAutoPtr<MimeEncoder> mCryptoEncoder;
bool mIsDraft;
enum {eBufferSize = 8192};
enum { eBufferSize = 8192 };
char *mBuffer;
uint32_t mBufferedBytes;
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

Просмотреть файл

@ -6,25 +6,31 @@
#ifndef nsMsgSMIMECID_h__
#define nsMsgSMIMECID_h__
#define NS_MSGCOMPOSESECURE_CID \
{ /* 54976882-7421-4286-8ecc-46373f15d7b5 */ \
0x54976882, 0x7421, 0x4286, \
{0x8e, 0xcc, 0x46, 0x37, 0x3f, 0x15, 0xd7, 0xb5 }}
#define NS_MSGCOMPOSESECURE_CID \
{ /* 54976882-7421-4286-8ecc-46373f15d7b5 */ \
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 }}
#define NS_SMIMEJSJELPER_CID \
{ /* d57d928c-60e4-4f81-999d-5c762e611205 */ \
0xd57d928c, 0x60e4, 0x4f81, { \
0x99, 0x9d, 0x5c, 0x76, 0x2e, 0x61, 0x12, 0x05 \
} \
}
#define NS_SMIMEENCRYPTURISERVICE_CONTRACTID \
#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 }}
#define NS_SMIMEENCRYPTURISERVICE_CID \
{ /* a0134d58-018f-4d40-a099-fa079e5024a6 */ \
0xa0134d58, 0x018f, 0x4d40, { \
0xa0, 0x99, 0xfa, 0x07, 0x9e, 0x50, 0x24, 0xa6 \
} \
}
#endif // nsMsgSMIMECID_h__
#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);
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,
uint32_t *count,
char16_t ***emailAddresses)
{
NS_IMETHODIMP nsSMimeJSHelper::GetNoCertAddresses(nsIMsgCompFields *compFields,
uint32_t *count,
char16_t ***emailAddresses) {
NS_ENSURE_ARG_POINTER(count);
*count = 0;
@ -198,30 +178,26 @@ NS_IMETHODIMP nsSMimeJSHelper::GetNoCertAddresses(
uint32_t mailbox_count = mailboxes.Length();
if (!mailbox_count)
{
if (!mailbox_count) {
*count = 0;
*emailAddresses = nullptr;
return NS_OK;
}
nsCOMPtr<nsIMsgComposeSecure> composeSecure =
do_CreateInstance(NS_MSGCOMPOSESECURE_CONTRACTID, &rv);
do_CreateInstance(NS_MSGCOMPOSESECURE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
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;
@ -229,37 +205,30 @@ NS_IMETHODIMP nsSMimeJSHelper::GetNoCertAddresses(
nsCOMPtr<nsIX509Cert> cert;
if (NS_SUCCEEDED(composeSecure->FindCertByEmailAddress(
email_lowercase, true, getter_AddRefs(cert))))
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,45 +241,36 @@ 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;
}
delete [] haveCert;
delete[] haveCert;
return rv;
}
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,11 +290,10 @@ 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));
UTF16ArrayAdapter<>(mailboxes));
}
return NS_OK;

Просмотреть файл

@ -8,18 +8,17 @@
#include "nsISMimeJSHelper.h"
#include "nsIMsgCompFields.h"
class nsSMimeJSHelper : public nsISMimeJSHelper
{
public:
class nsSMimeJSHelper : public nsISMimeJSHelper {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSISMIMEJSHELPER
nsSMimeJSHelper();
private:
private:
virtual ~nsSMimeJSHelper();
nsresult getMailboxList(nsIMsgCompFields *compFields,
nsTArray<nsCString> &mailboxes);
nsTArray<nsCString> &mailboxes);
};
#endif