32 #include "kmime_mdn.h"
34 #include "kmime_version.h"
35 #include "kmime_util.h"
37 #include <tdelocale.h>
40 #include <tqcstring.h>
49 DispositionType dispositionType;
51 const char * description;
52 } dispositionTypes[] = {
53 { Displayed,
"displayed",
54 I18N_NOOP(
"The message sent on ${date} to ${to} with subject "
55 "\"${subject}\" has been displayed. This is no guarantee that "
56 "the message has been read or understood.") },
58 I18N_NOOP(
"The message sent on ${date} to ${to} with subject "
59 "\"${subject}\" has been deleted unseen. This is no guarantee "
60 "that the message will not be \"undeleted\" and nonetheless "
62 { Dispatched,
"dispatched",
63 I18N_NOOP(
"The message sent on ${date} to ${to} with subject "
64 "\"${subject}\" has been dispatched. This is no guarantee "
65 "that the message will not be read later on.") },
66 { Processed,
"processed",
67 I18N_NOOP(
"The message sent on ${date} to ${to} with subject "
68 "\"${subject}\" has been processed by some automatic means.") },
70 I18N_NOOP(
"The message sent on ${date} to ${to} with subject "
71 "\"${subject}\" has been acted upon. The sender does not wish "
72 "to disclose more details to you than that.") },
74 I18N_NOOP(
"Generation of a Message Disposition Notification for the "
75 "message sent on ${date} to ${to} with subject \"${subject}\" "
76 "failed. Reason is given in the Failure: header field below.") }
79 static const int numDispositionTypes
80 =
sizeof dispositionTypes /
sizeof *dispositionTypes;
83 static const char * stringFor( DispositionType d ) {
84 for (
int i = 0 ; i < numDispositionTypes ; ++i )
85 if ( dispositionTypes[i].dispositionType == d )
86 return dispositionTypes[i].string;
95 DispositionModifier dispositionModifier;
97 } dispositionModifiers[] = {
99 { Warning,
"warning" },
100 { Superseded,
"superseded" },
101 { Expired,
"expired" },
102 { MailboxTerminated,
"mailbox-terminated" }
105 static const int numDispositionModifiers
106 =
sizeof dispositionModifiers /
sizeof * dispositionModifiers;
109 static const char * stringFor( DispositionModifier m ) {
110 for (
int i = 0 ; i < numDispositionModifiers ; ++i )
111 if ( dispositionModifiers[i].dispositionModifier == m )
112 return dispositionModifiers[i].string;
120 static const struct {
121 ActionMode actionMode;
124 { ManualAction,
"manual-action" },
125 { AutomaticAction,
"automatic-action" }
128 static const int numActionModes =
sizeof actionModes /
sizeof *actionModes;
130 static const char * stringFor( ActionMode a ) {
131 for (
int i = 0 ; i < numActionModes ; ++i )
132 if ( actionModes[i].actionMode == a )
133 return actionModes[i].string;
142 static const struct {
143 SendingMode sendingMode;
146 { SentManually,
"MDN-sent-manually" },
147 { SentAutomatically,
"MDN-sent-automatically" }
150 static const int numSendingModes =
sizeof sendingModes /
sizeof *sendingModes;
152 static const char * stringFor( SendingMode s ) {
153 for (
int i = 0 ; i < numSendingModes ; ++i )
154 if ( sendingModes[i].sendingMode == s )
155 return sendingModes[i].string;
159 static TQCString dispositionField( DispositionType d, ActionMode a, SendingMode s,
160 const TQValueList<DispositionModifier> & m ) {
163 TQCString result =
"Disposition: ";
164 result += stringFor( a );
166 result += stringFor( s );
168 result += stringFor( d );
172 for ( TQValueList<DispositionModifier>::const_iterator mt = m.begin() ;
173 mt != m.end() ; ++mt ) {
180 result += stringFor( *mt );
182 return result +
"\n";
185 static TQCString finalRecipient(
const TQString & recipient ) {
186 if ( recipient.isEmpty() )
189 return "Final-Recipient: rfc822; "
190 + encodeRFC2047String( recipient,
"utf-8" ) +
"\n";
193 static TQCString orginalRecipient(
const TQCString & recipient ) {
194 if ( recipient.isEmpty() )
197 return "Original-Recipient: " + recipient +
"\n";
200 static TQCString originalMessageID(
const TQCString & msgid ) {
201 if ( msgid.isEmpty() )
204 return "Original-Message-ID: " + msgid +
"\n";
207 static TQCString reportingUAField() {
209 if ( gethostname( hostName, 255 ) )
212 hostName[255] =
'\0';
213 return TQCString(
"Reporting-UA: ") + hostName
214 +
"; KMime " KMIME_VERSION_STRING
"\n";
217 TQCString dispositionNotificationBodyContent(
const TQString & r,
219 const TQCString & omid,
223 const TQValueList<DispositionModifier> & m,
224 const TQString & special )
228 if ( special.endsWith(
"\n") )
229 spec = special.left( special.length() - 1 );
234 TQCString result = reportingUAField();
235 result += orginalRecipient( o );
236 result += finalRecipient( r );
237 result += originalMessageID( omid );
238 result += dispositionField( d, a, s, m );
242 result +=
"Failure: " + encodeRFC2047String( spec,
"utf-8" ) +
"\n";
243 else if ( m.contains( Error ) )
244 result +=
"Error: " + encodeRFC2047String( spec,
"utf-8" ) +
"\n";
245 else if ( m.contains( Warning ) )
246 result +=
"Warning: " + encodeRFC2047String( spec,
"utf-8" ) +
"\n";
251 TQString descriptionFor( DispositionType d,
252 const TQValueList<DispositionModifier> & ) {
253 for (
int i = 0 ; i < numDispositionTypes ; ++i )
254 if ( dispositionTypes[i].dispositionType == d )
255 return i18n( dispositionTypes[i].description );
256 kdWarning() <<
"KMime::MDN::descriptionFor(): No such disposition type: "