28 #include <tdelocale.h>
29 #include <kstandarddirs.h>
31 #include <tdemessagebox.h>
33 #include <tdeapplication.h>
34 #include <dcopclient.h>
35 #include <tdeprocess.h>
37 #include <libemailfunctions/email.h>
39 #include <libkpimidentities/identity.h>
40 #include <libkpimidentities/identitymanager.h>
42 #include <libkcal/event.h>
43 #include <libkcal/todo.h>
44 #include <libkcal/incidenceformatter.h>
50 #include "komailclient.h"
52 KOMailClient::KOMailClient()
56 KOMailClient::~KOMailClient()
60 bool KOMailClient::mailAttendees( IncidenceBase *incidence, const TQString &attachment)
62 Attendee::List attendees = incidence-> attendees();
63 if ( attendees.count() == 0 ) {
67 const TQString from = incidence->organizer().fullName();
68 const TQString organizerEmail = incidence->organizer().email();
72 for ( uint i=0; i<attendees.count(); ++i ) {
75 const TQString email = a->email();
76 if ( email.isEmpty() ) {
83 if ( organizerEmail == email ) {
88 TQString tname, temail;
89 const TQString username = KPIM::quoteNameIfNecessary( a->name() );
90 KPIM::getNameAndMail( username, tname, temail );
92 tname += " <" + email + '>';
96 if ( a-> role() == Attendee::OptParticipant ||
97 a-> role() == Attendee::NonParticipant ) {
104 if( toList.count() == 0 && ccList.count() == 0 ) {
109 if ( toList.count() > 0 ) {
110 to = toList.join( ", " );
113 if ( ccList.count() > 0 ) {
114 cc = ccList.join( ", " );
118 if(incidence->type()!= "FreeBusy") {
122 subject = "Free Busy Object";
125 TQString body = IncidenceFormatter::mailBodyString(incidence);
127 bool bcc = KOPrefs::instance()->mBcc;
129 return send(from,to,cc,subject,body,bcc,attachment);
132 bool KOMailClient::mailOrganizer( IncidenceBase *incidence, const TQString &attachment, const TQString &sub)
134 TQString to = incidence->organizer().fullName();
136 TQString from = KOPrefs::instance()->email();
138 TQString subject = sub;
139 if(incidence->type()!= "FreeBusy") {
141 if ( subject.isEmpty() )
144 subject = "Free Busy Message";
147 TQString body = IncidenceFormatter::mailBodyString(incidence);
149 bool bcc = KOPrefs::instance()->mBcc;
151 return send(from,to,TQString(),subject,body,bcc,attachment);
154 bool KOMailClient::mailTo( IncidenceBase *incidence, const TQString &recipients,
155 const TQString &attachment)
157 TQString from = KOPrefs::instance()->email();
159 if(incidence->type()!= "FreeBusy") {
163 subject = "Free Busy Message";
165 TQString body = IncidenceFormatter::mailBodyString(incidence);
166 bool bcc = KOPrefs::instance()->mBcc;
167 kdDebug () << "KOMailClient::mailTo " << recipients << endl;
168 return send(from,recipients,TQString(),subject,body,bcc,attachment);
171 bool KOMailClient::send( const TQString &from, const TQString &_to, const TQString &cc,
172 const TQString &subject, const TQString &body, bool bcc,
173 const TQString &attachment)
178 if ( to.isEmpty() ) {
182 kdDebug(5850) << "KOMailClient::sendMail():\nFrom: " << from
185 << "\nSubject: " << subject << "\nBody: \n" << body
186 << "\nAttachment:\n" << attachment << endl;
188 if (KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail) {
189 bool needHeaders = true;
191 TQString command = TDEStandardDirs::findExe(TQString::fromLatin1( "sendmail"),
192 TQString::fromLatin1( "/sbin:/usr/sbin:/usr/lib"));
193 if (!command.isNull()) command += TQString::fromLatin1( " -oi -t");
195 command = TDEStandardDirs::findExe(TQString::fromLatin1( "mail"));
196 if (command.isNull()) return false;
198 command.append(TQString::fromLatin1( " -s "));
199 command.append(TDEProcess::quote(subject));
202 command.append(TQString::fromLatin1( " -b "));
203 command.append(TDEProcess::quote(from));
206 if ( !cc.isEmpty() ) {
207 command.append( " -c ");
208 command.append(TDEProcess::quote(cc));
212 command.append(TDEProcess::quote(to));
217 FILE * fd = popen(command.local8Bit(), "w");
220 kdError() << "Unable to open a pipe to " << command << endl;
224 TQString textComplete;
227 textComplete += TQString::fromLatin1( "From: ") + from + '\n';
228 textComplete += TQString::fromLatin1( "To: ") + to + '\n';
229 if ( !cc.isEmpty() ) {
230 textComplete += TQString::fromLatin1( "Cc: " ) + cc + '\n';
232 if (bcc) textComplete += TQString::fromLatin1( "Bcc: ") + from + '\n';
233 textComplete += TQString::fromLatin1( "Subject: ") + subject + '\n';
234 textComplete += TQString::fromLatin1( "X-Mailer: KOrganizer") + korgVersion + '\n';
236 textComplete += '\n';
237 textComplete += body;
238 textComplete += '\n';
239 textComplete += attachment;
241 fwrite(textComplete.local8Bit(),textComplete.length(),1,fd);
245 if (!kapp->dcopClient()->isApplicationRegistered( "kmail")) {
246 if (TDEApplication::startServiceByDesktopName( "kmail")) {
247 KMessageBox::error(0,i18n( "No running instance of KMail found."));
252 if (attachment.isEmpty()) {
253 if (!kMailOpenComposer(to,cc,bcc ? from : "",subject,body,0,KURL())) return false;
256 int idx = attachment.find( "METHOD");
258 idx = attachment.find( ':',idx)+1;
259 const int newline = attachment.find( '\n',idx);
260 meth = attachment.mid(idx, newline - idx - 1);
261 meth = meth.lower().stripWhiteSpace();
265 if (!kMailOpenComposer(to,cc,bcc ? from : "",subject,body,0, "cal.ics", "7bit",
266 attachment.utf8(), "text", "calendar", "method",meth,
267 "attachment", "utf-8",
268 KOCore::self()->identityManager()->identityForAddress( from ).uoid())) {
276 int KOMailClient::kMailOpenComposer( const TQString& arg0, const TQString& arg1,
277 const TQString& arg2, const TQString& arg3, const TQString& arg4, int arg5,
285 TQByteArray data, replyData;
287 TQDataStream arg( data, IO_WriteOnly );
295 #if KDE_IS_VERSION( 3, 2, 90 )
296 kapp->updateRemoteUserTimestamp( "kmail" );
298 if (kapp->dcopClient()->call( "kmail", "KMailIface", "openComposer(TQString,TQString,TQString,TQString,TQString,int,KURL)", data, replyType, replyData ) ) {
299 if ( replyType == "int" ) {
300 TQDataStream _reply_stream( replyData, IO_ReadOnly );
301 _reply_stream >> result;
303 kdDebug(5850) << "kMailOpenComposer() call failed." << endl;
306 kdDebug(5850) << "kMailOpenComposer() call failed." << endl;
311 int KOMailClient::kMailOpenComposer( const TQString& arg0, const TQString& arg1,
312 const TQString& arg2, const TQString& arg3,
313 const TQString& arg4, int arg5, const TQString& arg6,
314 const TQCString& arg7, const TQCString& arg8,
315 const TQCString& arg9, const TQCString& arg10,
316 const TQCString& arg11, const TQString& arg12,
317 const TQCString& arg13, const TQCString& arg14, uint identity )
328 TQByteArray data, replyData;
330 TQDataStream arg( data, IO_WriteOnly );
347 #if KDE_IS_VERSION( 3, 2, 90 )
348 kapp->updateRemoteUserTimestamp( "kmail");
350 if ( kapp->dcopClient()->call( "kmail", "KMailIface",
351 "openComposer(TQString,TQString,TQString,TQString,TQString,int,TQString,TQCString,TQCString,TQCString,TQCString,TQCString,TQString,TQCString,TQCString,uint)", data, replyType, replyData ) ) {
352 if ( replyType == "int" ) {
353 TQDataStream _reply_stream( replyData, IO_ReadOnly );
354 _reply_stream >> result;
356 kdDebug(5850) << "kMailOpenComposer() call failed." << endl;
359 kdDebug(5850) << "kMailOpenComposer() call failed." << endl;
const Attendee::List & attendees() const
|