summaryrefslogtreecommitdiffstats
path: root/libkmime/tests/test_mdn.cpp
blob: dd1702bb15e0b41b0d08ca1e17bf54d1d3cb129d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <kmime_mdn.h>
using namespace KMime::MDN;

#include <tqcstring.h>
#include <tqstring.h>
#include <tqvaluelist.h>

#include <iostream>
using std::cout;
using std::cerr;
#include <cstdlib>
using std::exit;
using std::endl;

#define _GNU_SOURCE 1
#include <getopt.h>

void usage( const char * msg=0 ) {
  if ( msg )
    cerr << msg << endl;
  cerr << "usage: test_mdn <options>\n"
    "where options include the following:" << endl
       << "FIXME" << endl;
  exit( 1 );
}

int main( int argc, char * argv[] ) {

  TQString finalRecipient;
  TQString originalRecipient;
  TQCString originalMessageId;
  ActionMode actionMode = ManualAction;
  SendingMode sendingMode = SentManually;
  DispositionType dispositionType = Displayed;
  TQValueList<DispositionModifier> dispositionModifiers;
  TQString special;

  while ( true ) {
    int option_index = 0;
    static const struct option long_options[] = {
      { "action-mode", 1, 0, 'a' },
      { "disposition-type", 1, 0, 'd' },
      { "final-recipient", 1, 0, 'f' },
      { "original-message-id", 1, 0, 'i' },
      { "disposition-modifiers", 1, 0, 'm' },
      { "original-recipient", 1, 0, 'o' },
      { "sending-mode", 1, 0, 's' },
      { 0, 0, 0, 0 }
    };

    int c = getopt_long( argc, argv, "a:d:f:i:m:o:s:",
			 long_options, &option_index );
    if ( c == -1 ) break;

#define ETQUALS(x) !qstricmp( optarg, x )

    switch ( c ) {

    case 'a': // --action-mode
      if ( ETQUALS( "manual-action" ) )
	actionMode = ManualAction;
      else if ( ETQUALS( "automatic-action" ) )
	actionMode = AutomaticAction;
      else
	usage( "unknown action mode!" );
      break;

    case 'd': // --disposition-type
      if ( ETQUALS( "displayed" ) )
	dispositionType = Displayed;
      else if ( ETQUALS( "deleted" ) )
	dispositionType = Deleted;
      else if ( ETQUALS( "dispatched" ) )
	dispositionType = Dispatched;
      else if ( ETQUALS( "processed" ) )
	dispositionType = Processed;
      else if ( ETQUALS( "denied" ) )
	dispositionType = Denied;
      else if ( ETQUALS( "failed" ) )
	dispositionType = Failed;
      else
	usage( "unknown disposition type!" );
      break;

    case 'f': // --final-recipient
      if ( optarg && *optarg )
	finalRecipient = TQString::fromUtf8( optarg );
      else
	usage( "--final-recipient is missing a value" );
      break;

    case 'i': // --original-message-id
      if ( optarg && *optarg )
	originalMessageId = optarg;
      else
	usage( "--original-message-id is missing a value" );
      break;

    case 'm': // --disposition-modifier
      if ( ETQUALS( "error" ) )
	dispositionModifiers << Error;
      else if ( ETQUALS( "warning" ) )
	dispositionModifiers << Warning;
      else if ( ETQUALS( "superseded" ) )
	dispositionModifiers << Superseded;
      else if ( ETQUALS( "expired" ) )
	dispositionModifiers << Expired;
      else if ( ETQUALS( "mailbox-terminated" ) )
	dispositionModifiers << MailboxTerminated;
      else
	usage( "unknwon disposition modifier!" );
      break;

    case 'o': // --original-recipient
      if ( optarg && *optarg )
	originalRecipient = TQString::fromUtf8( optarg );
      else
	usage( "--original-recipient is missing a value" );
      break;

    case 's': // --sending-mode
      if ( ETQUALS( "MDN-sent-manually" ) )
	sendingMode = SentManually;
      else if ( ETQUALS( "MDN-sent-automatically" ) )
	sendingMode = SentAutomatically;
      else
	usage( "unknown sending mode" );
      break;

    default:
      usage( "unknown option encountered!" );
    }
  }

  if ( optind < argc )
    special = TQString::fromUtf8( argv[optind++] );
  if ( optind < argc )
    usage( "too many arguments!" );

  TQCString result = dispositionNotificationBodyContent( finalRecipient,
						       originalRecipient.latin1(),
						       originalMessageId,
						       dispositionType,
						       actionMode,
						       sendingMode,
						       dispositionModifiers,
						       special );
  cout << "Result:\n" << result.data();

  return 0;
}