38#include <QtCore/QFile>
39#include <QtCore/QDateTime>
40#include <QtCore/QDataStream>
41#include <QtCore/QList>
42#include <QtCore/QByteArray>
53class KTnef::KTNEFWriter::PrivateData
56 PrivateData() { mFirstAttachNum = QDateTime::currentDateTime().toTime_t(); }
58 quint16 mFirstAttachNum;
66 QVariant v(0x00010000);
70 QVariant v1( (quint32)0x4e4 );
71 QVariant v2( (quint32)0x0 );
86 d->properties.addProperty( tag, type, value );
90void addToChecksum( quint32 i, quint16 &checksum )
93 checksum += ( i >> 8 ) & 0xff;
94 checksum += ( i >> 16 ) & 0xff;
95 checksum += ( i >> 24 ) & 0xff;
98void addToChecksum( QByteArray &cs, quint16 &checksum )
100 int len = cs.length();
101 for (
int i=0; i<len; i++ ) {
102 checksum += (quint8)cs[i];
106void writeCString( QDataStream &stream, QByteArray &str )
108 stream.writeRawData( str.data(), str.length() );
112quint32 mergeTagAndType( quint32 tag, quint32 type )
114 return ( ( type & 0xffff ) << 16 ) | ( tag & 0xffff );
127 QMap<int,KTNEFProperty*>& properties = d->properties.properties();
128 QMap<int,KTNEFProperty*>::Iterator it = properties.find( tag );
130 if ( it == properties.end() ) {
137 quint16 checksum = 0;
138 QList<QVariant> list;
147 i =
property->
value().toUInt() & 0xff;
150 stream << (quint8)LVL_MESSAGE;
151 stream << mergeTagAndType( tag, property->type() );
152 stream << (quint32)1;
161 i =
property->value().toUInt() & 0xffff;
162 addToChecksum( i, checksum );
164 stream << (quint8)LVL_MESSAGE;
165 stream << mergeTagAndType( tag, property->type() );
166 stream << (quint32)2;
167 stream << (quint16)i;
174 i =
property->value().toUInt();
175 addToChecksum( i, checksum );
177 stream << (quint8)LVL_MESSAGE;
178 stream << mergeTagAndType( tag, property->type() );
179 stream << (quint32)4;
180 stream << (quint32)i;
187 list =
property->value().toList();
188 assert( list.count() == 2 );
190 stream << (quint8)LVL_MESSAGE;
191 stream << mergeTagAndType( tag, property->type() );
192 stream << (quint32)8;
195 addToChecksum( i, checksum );
196 stream << (quint32)i;
198 addToChecksum( i, checksum );
199 stream << (quint32)i;
209 cs =
property->value().toString().toLocal8Bit();
210 addToChecksum( cs, checksum );
212 stream << (quint8)LVL_MESSAGE;
213 stream << mergeTagAndType( tag, property->type() );
214 stream << (quint32)cs.length()+1;
215 writeCString( stream, cs );
217 bytes += 9 + cs.length()+1;
222 list =
property->value().toList();
223 assert( list.count() == 2 );
225 cs = list[0].toString().toLocal8Bit();
226 cs2 = QString( QLatin1String(
"smtp:" ) + list[1].toString() ).toLocal8Bit();
227 i = 18 + cs.length() + cs2.length();
229 stream << (quint8)LVL_MESSAGE;
230 stream << mergeTagAndType( tag, property->type() );
231 stream << (quint32)i;
237 stream << (quint16)4;
238 stream << (quint16)i;
239 stream << (quint16)( cs.length() + 1 );
240 stream << (quint16)( cs2.length() + 1 );
246 writeCString( stream, cs );
247 writeCString( stream, cs2 );
250 stream << (quint32)0 << (quint32)0;
252 addToChecksum( 4, checksum );
253 addToChecksum( i, checksum );
254 addToChecksum( cs.length()+1, checksum );
255 addToChecksum( cs2.length()+1, checksum );
256 addToChecksum( cs, checksum );
257 addToChecksum( cs2, checksum );
264 case attDATEMODIFIED:
266 dt =
property->value().toDateTime();
270 stream << (quint8)LVL_MESSAGE;
271 stream << mergeTagAndType( tag, property->type() );
272 stream << (quint32)14;
274 i = (quint16)date.year();
275 addToChecksum( i, checksum );
276 stream << (quint16)i;
277 i = (quint16)date.month();
278 addToChecksum( i, checksum );
279 stream << (quint16)i;
280 i = (quint16)date.day();
281 addToChecksum( i, checksum );
282 stream << (quint16)i;
283 i = (quint16)time.hour();
284 addToChecksum( i, checksum );
285 stream << (quint16)i;
286 i = (quint16)time.minute();
287 addToChecksum( i, checksum );
288 stream << (quint16)i;
289 i = (quint16)time.second();
290 addToChecksum( i, checksum );
291 stream << (quint16)i;
292 i = (quint16)date.dayOfWeek();
293 addToChecksum( i, checksum );
294 stream << (quint16)i;
321 kDebug() <<
"Unknown TNEF tag:" << tag;
325 stream << (quint16)checksum;
331 if ( !file.open( QIODevice::WriteOnly ) ) {
335 QDataStream stream( &file );
341 stream.setByteOrder( QDataStream::LittleEndian );
344 stream << TNEF_SIGNATURE;
348 stream << d->mFirstAttachNum;
352 int bytesWritten = 0;
372 assert( !name.isEmpty() );
373 assert( !email.isEmpty() );
376 QVariant v2( email );
378 QList<QVariant> list;
394 v = QVariant( QString(
"IPM.Appointment" ) );
398 v = QVariant( QString(
"IPM.Schedule.Meeting.Cancelled" ) );
402 v = QVariant( QString(
"IPM.Schedule.Meeting.Request" ) );
406 v = QVariant( QString(
"IPM.Schedule.Meeting.Resp.Neg" ) );
410 v = QVariant( QString(
"IPM.Schedule.Meeting.Resp.Pos" ) );
415 v = QVariant( QString(
"IPM.Schedule.Meeting.Resp.Tent" ) );
437 const QString &mailto )
450 int i = organizer.indexOf(
'<' );
456 QString name = organizer.left( i ).trimmed();
458 QString email = organizer.right( i+1 );
459 email = email.left( email.length()-1 ).trimmed();
466 QVariant v( dtStart );
490 QVariant v( dtStamp );
516 QVariant v( (quint32)p );
522 const QDateTime &wakeBefore )
524 Q_UNUSED( description );
526 Q_UNUSED( wakeBefore );
Interface for setting MAPI properties and TNEF attributes.
Interface for setting MAPI properties.
QVariant value() const
Returns the value of the property.
Manages the writing of TNEF attachments.
void setPriority(Priority priority)
Sets the priority to priority.
AlarmAction
The different alarm actions.
void setAlarm(const QString &description, AlarmAction action, const QDateTime &wakeBefore)
Sets the alarm.
void setOrganizer(const QString &organizer)
Sets the name of the organizer to organizer.
void clearAttendees()
Clears the attendees list.
KTNEFWriter()
Constructs a TNEF writer object.
Role
The different types of meeting roles.
void setDtStamp(const QDateTime &dtStamp)
Sets the timestamp to dtStamp.
void setCategories(const QStringList &categories)
Sets the category list to categories.
MessageType
The different types of messages.
@ MeetingTent
Tentative affirmative to a meeting request.
@ MeetingNo
Negative response to a meeting request.
@ MeetingRequest
Meeting request.
@ Appointment
Appointment.
@ MeetingYes
Affirmative response to a meeting request.
@ MeetingCancelled
The meeting is cancelled.
Priority
The different priorities.
~KTNEFWriter()
Destroys the TNEF writer object.
bool writeFile(QIODevice &file) const
Writes the attachment to the #QIODevice specified by file.
void setMethod(Method method)
Sets the Method to method.
void setLocation(const QString &location)
Sets the Location to location.
void addProperty(int tag, int type, const QVariant &value)
Adds a TNEF property.
bool writeProperty(QDataStream &stream, int &bytes, int tag) const
Writes a TNEF property to the #QDataStream specified by stream.
void setSummary(const QString &summary)
Sets the summary to summary.
Method
The different types of message statuses.
PartStat
The different types of participant statuses.
void setDtEnd(const QDateTime &dtEnd)
Sets the Ending Date and Time to dtEnd.
void setDtStart(const QDateTime &dtStart)
Sets the Starting Date and Time to dtStart.
void setDescription(const QString &description)
Sets the description to description.
void setSender(const QString &name, const QString &email)
Sets the sender's name and email address.
void setMessageType(MessageType methodType)
Sets the MessageType to methodType.
void addAttendee(const QString &name, Role role, PartStat partstat, bool rsvp, const QString &email)
Adds a meeting participant (attendee).
void setUID(const QString &uid)
Sets the UID to uid.
This file is part of the API for handling TNEF data and provides some basic definitions for general u...
This file is part of the API for handling TNEF data and defines the KTNEFProperty class.
This file is part of the API for handling TNEF data and defines the KTNEFPropertySet class.
This file is part of the API for handling TNEF data and defines the KTNEFWriter class.