10 #include <libtdepim/tdefileio.h>
11 #include <libtdepim/collectingprocess.h>
14 #include <tdelocale.h>
15 #include <tdemessagebox.h>
16 #include <tdeconfig.h>
19 #include <tqfileinfo.h>
21 #include <sys/types.h>
45 mType( isExecutable ? FromCommand : FromFile )
50 if ( mType != other.mType )
return false;
52 case Inlined:
return mText == other.mText;
54 case FromCommand:
return mUrl == other.mUrl;
56 case Disabled:
return true;
70 return textFromFile( ok );
72 return textFromCommand( ok );
74 kdFatal( 5006 ) <<
"Signature::type() returned unknown value!" << endl;
78 TQString Signature::textFromCommand(
bool * ok )
const
80 assert( mType == FromCommand );
83 if ( mUrl.isEmpty() ) {
89 CollectingProcess proc;
90 proc.setUseShell(
true);
95 if ( !proc.start( TDEProcess::Block, TDEProcess::Stdout ) )
98 rc = ( proc.normalExit() ) ? proc.exitStatus() : -1 ;
102 if ( ok ) *ok =
false;
103 TQString wmsg = i18n(
"<qt>Failed to execute signature script<br><b>%1</b>:<br>%2</qt>")
104 .arg( mUrl ).arg( strerror(rc) );
105 KMessageBox::error(0, wmsg);
110 if ( ok ) *ok =
true;
113 TQByteArray output = proc.collectedStdout();
116 return TQString::fromLocal8Bit( output.data(), output.size() );
119 TQString Signature::textFromFile(
bool * ok )
const
121 assert( mType == FromFile );
124 if ( !KURL(mUrl).isLocalFile() && !(TQFileInfo(mUrl).isRelative()
125 && TQFileInfo(mUrl).exists()) ) {
126 kdDebug( 5006 ) <<
"Signature::textFromFile: non-local URLs are unsupported" << endl;
127 if ( ok ) *ok =
false;
130 if ( ok ) *ok =
true;
132 return TQString::fromLocal8Bit( kFileToString( mUrl,
false ) );
137 bool internalOK =
false;
138 TQString signature =
rawText( &internalOK );
140 if ( ok ) *ok =
false;
143 if ( ok ) *ok =
true;
144 if ( signature.isEmpty() )
return signature;
145 if ( signature.startsWith( TQString::fromLatin1(
"-- \n") ) )
147 return TQString::fromLatin1(
"\n") += signature;
148 else if ( signature.find( TQString::fromLatin1(
"\n-- \n") ) != -1 )
154 return TQString::fromLatin1(
"\n-- \n") + signature;
161 mType = isExecutable ? FromCommand : FromFile ;
165 static const char sigTypeKey[] =
"Signature Type";
166 static const char sigTypeInlineValue[] =
"inline";
167 static const char sigTypeFileValue[] =
"file";
168 static const char sigTypeCommandValue[] =
"command";
169 static const char sigTypeDisabledValue[] =
"disabled";
170 static const char sigTextKey[] =
"Inline Signature";
171 static const char sigFileKey[] =
"Signature File";
172 static const char sigCommandKey[] =
"Signature Command";
174 void Signature::readConfig(
const TDEConfigBase * config )
176 TQString sigType = config->readEntry( sigTypeKey );
177 if ( sigType == sigTypeInlineValue ) {
179 }
else if ( sigType == sigTypeFileValue ) {
181 mUrl = config->readPathEntry( sigFileKey );
182 }
else if ( sigType == sigTypeCommandValue ) {
184 mUrl = config->readPathEntry( sigCommandKey );
188 mText = config->readEntry( sigTextKey );
191 void Signature::writeConfig( TDEConfigBase * config )
const
195 config->writeEntry( sigTypeKey, sigTypeInlineValue );
198 config->writeEntry( sigTypeKey, sigTypeFileValue );
199 config->writePathEntry( sigFileKey, mUrl );
202 config->writeEntry( sigTypeKey, sigTypeCommandValue );
203 config->writePathEntry( sigCommandKey, mUrl );
206 config->writeEntry( sigTypeKey, sigTypeDisabledValue );
209 config->writeEntry( sigTextKey, mText );
212 TQDataStream & KPIM::operator<<( TQDataStream & stream,
const KPIM::Signature & sig ) {
213 return stream << static_cast<TQ_UINT8>(sig.mType)
218 TQDataStream & KPIM::operator>>( TQDataStream & stream,
KPIM::Signature & sig ) {
233 return *identityNull;
236 bool Identity::isNull()
const {
237 return mIdentity.isEmpty() && mFullName.isEmpty() && mEmailAddr.isEmpty() &&
238 mEmailAliases.empty() &&
239 mOrganization.isEmpty() && mReplyToAddr.isEmpty() && mBcc.isEmpty() &&
240 mVCardFile.isEmpty() &&
241 mFcc.isEmpty() && mDrafts.isEmpty() && mTemplates.isEmpty() &&
242 mPGPEncryptionKey.isEmpty() && mPGPSigningKey.isEmpty() &&
243 mSMIMEEncryptionKey.isEmpty() && mSMIMESigningKey.isEmpty() &&
244 mTransport.isEmpty() && mDictionary.isEmpty() &&
245 mPreferredCryptoMessageFormat == Kleo::AutoFormat &&
246 mSignature.
type() == Signature::Disabled &&
251 bool same = mUoid == other.mUoid &&
252 mIdentity == other.mIdentity && mFullName == other.mFullName &&
253 mEmailAddr == other.mEmailAddr && mOrganization == other.mOrganization &&
254 mEmailAliases == other.mEmailAliases &&
255 mReplyToAddr == other.mReplyToAddr && mBcc == other.mBcc &&
256 mVCardFile == other.mVCardFile &&
257 mFcc == other.mFcc &&
258 mPGPEncryptionKey == other.mPGPEncryptionKey &&
259 mPGPSigningKey == other.mPGPSigningKey &&
260 mSMIMEEncryptionKey == other.mSMIMEEncryptionKey &&
261 mSMIMESigningKey == other.mSMIMESigningKey &&
262 mPreferredCryptoMessageFormat == other.mPreferredCryptoMessageFormat &&
263 mDrafts == other.mDrafts && mTemplates == other.mTemplates &&
264 mTransport == other.mTransport &&
265 mDictionary == other.mDictionary && mSignature == other.mSignature &&
266 mXFace == other.mXFace && mXFaceEnabled == other.mXFaceEnabled;
271 if ( mUoid != other.mUoid ) kdDebug() <<
"mUoid differs : " << mUoid <<
" != " << other.mUoid << endl;
272 if ( mIdentity != other.mIdentity ) kdDebug() <<
"mIdentity differs : " << mIdentity <<
" != " << other.mIdentity << endl;
273 if ( mFullName != other.mFullName ) kdDebug() <<
"mFullName differs : " << mFullName <<
" != " << other.mFullName << endl;
274 if ( mEmailAddr != other.mEmailAddr ) kdDebug() <<
"mEmailAddr differs : " << mEmailAddr <<
" != " << other.mEmailAddr << endl;
275 if ( mEmailAliases != other.mEmailAliases ) kdDebug() <<
"mEmailAliases differs : " << mEmailAliases.join(
";") <<
" != " << other.mEmailAliases.join(
";") << endl;
276 if ( mOrganization != other.mOrganization ) kdDebug() <<
"mOrganization differs : " << mOrganization <<
" != " << other.mOrganization << endl;
277 if ( mReplyToAddr != other.mReplyToAddr ) kdDebug() <<
"mReplyToAddr differs : " << mReplyToAddr <<
" != " << other.mReplyToAddr << endl;
278 if ( mBcc != other.mBcc ) kdDebug() <<
"mBcc differs : " << mBcc <<
" != " << other.mBcc << endl;
279 if ( mVCardFile != other.mVCardFile ) kdDebug() <<
"mVCardFile differs : " << mVCardFile <<
" != " << other.mVCardFile << endl;
280 if ( mFcc != other.mFcc ) kdDebug() <<
"mFcc differs : " << mFcc <<
" != " << other.mFcc << endl;
281 if ( mPGPEncryptionKey != other.mPGPEncryptionKey ) kdDebug() <<
"mPGPEncryptionKey differs : " << mPGPEncryptionKey <<
" != " << other.mPGPEncryptionKey << endl;
282 if ( mPGPSigningKey != other.mPGPSigningKey ) kdDebug() <<
"mPGPSigningKey differs : " << mPGPSigningKey <<
" != " << other.mPGPSigningKey << endl;
283 if ( mSMIMEEncryptionKey != other.mSMIMEEncryptionKey ) kdDebug() <<
"mSMIMEEncryptionKey differs : '" << mSMIMEEncryptionKey <<
"' != '" << other.mSMIMEEncryptionKey <<
"'" << endl;
284 if ( mSMIMESigningKey != other.mSMIMESigningKey ) kdDebug() <<
"mSMIMESigningKey differs : " << mSMIMESigningKey <<
" != " << other.mSMIMESigningKey << endl;
285 if ( mPreferredCryptoMessageFormat != other.mPreferredCryptoMessageFormat ) kdDebug() <<
"mPreferredCryptoMessageFormat differs : " << mPreferredCryptoMessageFormat <<
" != " << other.mPreferredCryptoMessageFormat << endl;
286 if ( mDrafts != other.mDrafts ) kdDebug() <<
"mDrafts differs : " << mDrafts <<
" != " << other.mDrafts << endl;
287 if ( mTemplates != other.mTemplates ) kdDebug() <<
"mTemplates differs : " << mTemplates <<
" != " << other.mTemplates << endl;
288 if ( mTransport != other.mTransport ) kdDebug() <<
"mTransport differs : " << mTransport <<
" != " << other.mTransport << endl;
289 if ( mDictionary != other.mDictionary ) kdDebug() <<
"mDictionary differs : " << mDictionary <<
" != " << other.mDictionary << endl;
290 if ( ! ( mSignature == other.mSignature ) ) kdDebug() <<
"mSignature differs" << endl;
296 const TQString & emailAddr,
const TQString & organization,
297 const TQString & replyToAddr )
298 : mUoid( 0 ), mIdentity( id ), mFullName( fullName ),
299 mEmailAddr( emailAddr ), mOrganization( organization ),
300 mReplyToAddr( replyToAddr ),
303 mBcc(
"" ), mVCardFile(
"" ), mPGPEncryptionKey(
"" ), mPGPSigningKey(
"" ),
304 mSMIMEEncryptionKey(
"" ), mSMIMESigningKey(
"" ), mFcc(
"" ),
305 mDrafts(
"" ), mTemplates(
"" ), mTransport(
"" ),
307 mXFace(
"" ), mXFaceEnabled( false ),
309 mPreferredCryptoMessageFormat( Kleo::AutoFormat )
320 mUoid = config->readUnsignedNumEntry(
"uoid",0);
322 mIdentity = config->readEntry(
"Identity");
323 mFullName = config->readEntry(
"Name");
324 mEmailAddr = config->readEntry(
"Email Address");
325 mEmailAliases = config->readListEntry(
"Email Aliases");
326 mVCardFile = config->readPathEntry(
"VCardFile");
327 mOrganization = config->readEntry(
"Organization");
328 mPGPSigningKey = config->readEntry(
"PGP Signing Key").latin1();
329 mPGPEncryptionKey = config->readEntry(
"PGP Encryption Key").latin1();
330 mSMIMESigningKey = config->readEntry(
"SMIME Signing Key").latin1();
331 mSMIMEEncryptionKey = config->readEntry(
"SMIME Encryption Key").latin1();
332 mPreferredCryptoMessageFormat = Kleo::stringToCryptoMessageFormat( config->readEntry(
"Preferred Crypto Message Format",
"none" ) );
333 mReplyToAddr = config->readEntry(
"Reply-To Address" );
334 mBcc = config->readEntry(
"Bcc" );
335 mFcc = config->readEntry(
"Fcc",
"sent-mail" );
338 mDrafts = config->readEntry(
"Drafts",
"drafts" );
339 if( mDrafts.isEmpty() )
341 mTemplates = config->readEntry(
"Templates",
"templates" );
342 if( mTemplates.isEmpty() )
343 mTemplates =
"templates";
344 mTransport = config->readEntry(
"Transport" );
345 mDictionary = config->readEntry(
"Dictionary" );
346 mXFace = config->readEntry(
"X-Face" );
347 mXFaceEnabled = config->readBoolEntry(
"X-FaceEnabled",
false );
349 mSignature.readConfig( config );
350 kdDebug(5006) <<
"Identity::readConfig(): UOID = " << mUoid
351 <<
" for identity named \"" << mIdentity <<
"\"" << endl;
357 config->writeEntry(
"uoid", mUoid);
359 config->writeEntry(
"Identity", mIdentity);
360 config->writeEntry(
"Name", mFullName);
361 config->writeEntry(
"Organization", mOrganization);
362 config->writeEntry(
"PGP Signing Key", mPGPSigningKey.data());
363 config->writeEntry(
"PGP Encryption Key", mPGPEncryptionKey.data());
364 config->writeEntry(
"SMIME Signing Key", mSMIMESigningKey.data());
365 config->writeEntry(
"SMIME Encryption Key", mSMIMEEncryptionKey.data());
366 config->writeEntry(
"Preferred Crypto Message Format", Kleo::cryptoMessageFormatToString( mPreferredCryptoMessageFormat ) );
367 config->writeEntry(
"Email Address", mEmailAddr);
368 config->writeEntry(
"Email Aliases", mEmailAliases);
369 config->writeEntry(
"Reply-To Address", mReplyToAddr);
370 config->writeEntry(
"Bcc", mBcc);
371 config->writePathEntry(
"VCardFile", mVCardFile);
372 config->writeEntry(
"Transport", mTransport);
373 config->writeEntry(
"Fcc", mFcc);
374 config->writeEntry(
"Drafts", mDrafts);
375 config->writeEntry(
"Templates", mTemplates);
376 config->writeEntry(
"Dictionary", mDictionary );
377 config->writeEntry(
"X-Face", mXFace );
378 config->writeEntry(
"X-FaceEnabled", mXFaceEnabled );
380 mSignature.writeConfig( config );
383 TQDataStream & KPIM::operator<<( TQDataStream & stream,
const KPIM::Identity & i ) {
384 return stream << static_cast<TQ_UINT32>(i.
uoid())
404 << TQString( Kleo::cryptoMessageFormatToString( i.mPreferredCryptoMessageFormat ) );
407 TQDataStream & KPIM::operator>>( TQDataStream & stream,
KPIM::Identity & i ) {
415 >> i.mPGPEncryptionKey
416 >> i.mSMIMESigningKey
417 >> i.mSMIMEEncryptionKey
432 i.mPreferredCryptoMessageFormat = Kleo::stringToCryptoMessageFormat( format.latin1() );
440 return !mEmailAddr.isEmpty();
448 void Identity::setIdentityName(
const TQString & name ) {
452 void Identity::setFullName(
const TQString &str)
459 void Identity::setOrganization(
const TQString &str)
464 void Identity::setPGPSigningKey(
const TQCString &str)
466 mPGPSigningKey = str;
467 if ( mPGPSigningKey.isNull() )
471 void Identity::setPGPEncryptionKey(
const TQCString &str)
473 mPGPEncryptionKey = str;
474 if ( mPGPEncryptionKey.isNull() )
475 mPGPEncryptionKey =
"";
478 void Identity::setSMIMESigningKey(
const TQCString &str)
480 mSMIMESigningKey = str;
481 if ( mSMIMESigningKey.isNull() )
482 mSMIMESigningKey =
"";
485 void Identity::setSMIMEEncryptionKey(
const TQCString &str)
487 mSMIMEEncryptionKey = str;
488 if ( mSMIMEEncryptionKey.isNull() )
489 mSMIMEEncryptionKey =
"";
493 void Identity::setPrimaryEmailAddress(
const TQString & str )
498 void Identity::setEmailAliases(
const TQStringList & list )
500 mEmailAliases = list;
503 bool Identity::matchesEmailAddress(
const TQString & addr )
const
505 const TQString lower = addr.lower();
506 if ( lower == mEmailAddr.lower() )
508 for ( TQStringList::const_iterator it = mEmailAliases.begin(), end = mEmailAliases.end() ; it != end ; ++it )
509 if ( (*it).lower() == lower )
515 void Identity::setVCardFile(
const TQString &str)
524 if (mFullName.isEmpty())
return mEmailAddr;
526 const TQString specials(
"()<>@,.;:[]");
531 bool needsQuotes=
false;
532 for (
unsigned int i=0; i < mFullName.length(); i++) {
533 if ( specials.contains( mFullName[i] ) )
535 else if ( mFullName[i] ==
'\\' || mFullName[i] ==
'"' ) {
539 result += mFullName[i];
543 result.insert(0,
'"');
547 result +=
" <" + mEmailAddr +
'>';
553 void Identity::setReplyToAddr(
const TQString& str)
560 void Identity::setSignatureFile(
const TQString &str)
567 void Identity::setSignatureInlineText(
const TQString &str )
574 void Identity::setTransport(
const TQString &str )
577 if ( mTransport.isNull() )
582 void Identity::setFcc(
const TQString &str )
590 void Identity::setDrafts(
const TQString &str )
593 if ( mDrafts.isNull() )
598 void Identity::setTemplates(
const TQString &str )
601 if ( mTemplates.isNull() )
606 void Identity::setDictionary(
const TQString &str )
609 if ( mDictionary.isNull() )
615 void Identity::setXFace(
const TQString &str )
618 mXFace.remove(
" " );
619 mXFace.remove(
"\n" );
620 mXFace.remove(
"\r" );
625 void Identity::setXFaceEnabled(
const bool on )
634 bool internalOK =
false;
644 if ( ok ) *ok =
false;
648 if (mSignatureFile.endsWith(
"|"))
User identity information.
TQString signatureText(bool *ok=0) const
Returns the signature.
bool signatureIsCommand() const
TQString xface() const
a X-Face header for this identity
void writeConfig(TDEConfigBase *) const
Write configuration to config.
uint uoid() const
Unique Object Identifier for this identity.
TQString organization() const
The user's organization (optional)
bool operator==(const Identity &other) const
used for comparison
TQCString smimeEncryptionKey() const
The user's S/MIME encryption key.
bool mailingAllowed() const
Tests if there are enough values set to allow mailing.
TQCString smimeSigningKey() const
The user's S/MIME signing key.
void setIsDefault(bool flag)
Set whether this identity is the default identity.
void readConfig(const TDEConfigBase *)
Read configuration from config.
TQString identityName() const
Identity/nickname for this collection.
TQString fcc() const
The folder where sent messages from this identity will be stored by default.
Identity(const TQString &id=TQString(), const TQString &realName=TQString(), const TQString &emailAddr=TQString(), const TQString &organization=TQString(), const TQString &replyToAddress=TQString())
Constructor.
TQString fullEmailAddr() const
email address in the format "username <name@host>" suitable for the "From:" field of email messages.
TQString bcc() const
email addresses for the BCC: field
TQString fullName() const
Full name of the user.
TQString dictionary() const
dictionary which should be used for spell checking
TQString primaryEmailAddress() const
primary email address (without the user name - only name@host).
TQString transport() const
The transport that is set for this identity.
TQString replyToAddr() const
email address for the ReplyTo: field
TQCString pgpEncryptionKey() const
The user's OpenPGP encryption key.
const TQStringList & emailAliases() const
email address aliases
TQString drafts() const
The folder where draft messages from this identity will be stored by default.
TQString templates() const
The folder where template messages from this identity will be stored by default.
TQString vCardFile() const
vCard to attach to outgoing emails
TQCString pgpSigningKey() const
The user's OpenPGP signing key.
abstraction of a signature (aka "footer").
bool operator==(const Signature &other) const
Used for comparison.
void setUrl(const TQString &url, bool isExecutable=false)
Set the signature URL and mark this signature as being of "from file" resp.
Type
Type of signature (ie.
void setText(const TQString &text)
Set the signature text and mark this signature as being of "inline text" type.
Signature()
Constructor for disabled signature.
TQString withSeparator(bool *ok=0) const
TQString rawText(bool *ok=0) const