35#include "kmime_version.h"
36#include "kmime_util.h"
38#include <klocalizedstring.h>
41#include <QtCore/QByteArray>
42#include <QtCore/QList>
53 const char * description;
54} dispositionTypes[] = {
55 { Displayed,
"displayed",
56 I18N_NOOP(
"The message sent on ${date} to ${to} with subject "
57 "\"${subject}\" has been displayed. This is no guarantee that "
58 "the message has been read or understood." ) },
60 I18N_NOOP(
"The message sent on ${date} to ${to} with subject "
61 "\"${subject}\" has been deleted unseen. This is no guarantee "
62 "that the message will not be \"undeleted\" and nonetheless "
64 { Dispatched,
"dispatched",
65 I18N_NOOP(
"The message sent on ${date} to ${to} with subject "
66 "\"${subject}\" has been dispatched. This is no guarantee "
67 "that the message will not be read later on." ) },
68 { Processed,
"processed",
69 I18N_NOOP(
"The message sent on ${date} to ${to} with subject "
70 "\"${subject}\" has been processed by some automatic means." ) },
72 I18N_NOOP(
"The message sent on ${date} to ${to} with subject "
73 "\"${subject}\" has been acted upon. The sender does not wish "
74 "to disclose more details to you than that." ) },
76 I18N_NOOP(
"Generation of a Message Disposition Notification for the "
77 "message sent on ${date} to ${to} with subject \"${subject}\" "
78 "failed. Reason is given in the Failure: header field below." ) }
81static const int numDispositionTypes =
82 sizeof dispositionTypes /
sizeof *dispositionTypes;
84static const char *stringFor( DispositionType d )
86 for (
int i = 0 ; i < numDispositionTypes ; ++i ) {
87 if ( dispositionTypes[i].dispositionType == d ) {
88 return dispositionTypes[i].string;
100} dispositionModifiers[] = {
102 { Warning,
"warning" },
103 { Superseded,
"superseded" },
104 { Expired,
"expired" },
105 { MailboxTerminated,
"mailbox-terminated" }
108static const int numDispositionModifiers =
109 sizeof dispositionModifiers /
sizeof * dispositionModifiers;
111static const char *stringFor( DispositionModifier m ) {
112 for (
int i = 0 ; i < numDispositionModifiers ; ++i ) {
113 if ( dispositionModifiers[i].dispositionModifier == m ) {
114 return dispositionModifiers[i].string;
128 { ManualAction,
"manual-action" },
129 { AutomaticAction,
"automatic-action" }
132static const int numActionModes =
133 sizeof actionModes /
sizeof *actionModes;
135static const char *stringFor( ActionMode a ) {
136 for (
int i = 0 ; i < numActionModes ; ++i ) {
137 if ( actionModes[i].actionMode == a ) {
138 return actionModes[i].string;
152 { SentManually,
"MDN-sent-manually" },
153 { SentAutomatically,
"MDN-sent-automatically" }
156static const int numSendingModes =
157 sizeof sendingModes /
sizeof *sendingModes;
159static const char *stringFor( SendingMode s ) {
160 for (
int i = 0 ; i < numSendingModes ; ++i ) {
161 if ( sendingModes[i].sendingMode == s ) {
162 return sendingModes[i].string;
168static QByteArray dispositionField( DispositionType d, ActionMode a, SendingMode s,
169 const QList<DispositionModifier> & m ) {
172 QByteArray result =
"Disposition: ";
173 result += stringFor( a );
175 result += stringFor( s );
177 result += stringFor( d );
181 for ( QList<DispositionModifier>::const_iterator mt = m.begin();
182 mt != m.end() ; ++mt ) {
189 result += stringFor( *mt );
191 return result +
'\n';
194static QByteArray finalRecipient(
const QString &recipient )
196 if ( recipient.isEmpty() ) {
199 return "Final-Recipient: rfc822; "
200 + encodeRFC2047String( recipient,
"utf-8" ) +
'\n';
204static QByteArray orginalRecipient(
const QByteArray & recipient )
206 if ( recipient.isEmpty() ) {
209 return "Original-Recipient: " + recipient +
'\n';
213static QByteArray originalMessageID(
const QByteArray &msgid )
215 if ( msgid.isEmpty() ) {
218 return "Original-Message-ID: " + msgid +
'\n';
222static QByteArray reportingUAField() {
224 if ( gethostname( hostName, 255 ) ) {
227 hostName[255] =
'\0';
229 return QByteArray(
"Reporting-UA: " ) + QByteArray( hostName ) +
230 QByteArray(
"; KMime " KMIME_VERSION_STRING
"\n" );
235 const QByteArray &omid,
239 const QList<DispositionModifier> &m,
240 const QString &special )
244 if ( special.endsWith( QLatin1Char(
'\n' ) ) ) {
245 spec = special.left( special.length() - 1 );
251 QByteArray result = reportingUAField();
252 result += orginalRecipient( o );
253 result += finalRecipient( r );
254 result += originalMessageID( omid );
255 result += dispositionField( d, a, s, m );
259 result +=
"Failure: " + encodeRFC2047String( spec,
"utf-8" ) +
'\n';
260 }
else if ( m.contains( Error ) ) {
261 result +=
"Error: " + encodeRFC2047String( spec,
"utf-8" ) +
'\n';
262 }
else if ( m.contains( Warning ) ) {
263 result +=
"Warning: " + encodeRFC2047String( spec,
"utf-8" ) +
'\n';
269QString descriptionFor( DispositionType d,
270 const QList<DispositionModifier> & )
272 for (
int i = 0 ; i < numDispositionTypes ; ++i ) {
273 if ( dispositionTypes[i].dispositionType == d ) {
274 return i18n( dispositionTypes[i].description );
277 kWarning() <<
"KMime::MDN::descriptionFor(): No such disposition type:"
QByteArray dispositionNotificationBodyContent(const QString &r, const QByteArray &o, const QByteArray &omid, DispositionType d, ActionMode a, SendingMode s, const QList< DispositionModifier > &m, const QString &special)
Generates the content of the message/disposition-notification body part.
This file is part of the API for handling MIME data and provides functions for supporting Message Dis...
DispositionModifier
The following disposition modifiers are defined:
ActionMode
The following disposition modes are defined:
DispositionType
The following disposition-types are defined: