Summary: Isode provides a number of APIs which allow integrators and product developers to build components that access the Isode Messaging server products or other products supporting the same protocols.
x400_mssend.c
1 /*
2  * Copyright (c) 2003-2013, Isode Limited, London, England.
3  * All rights reserved.
4  *
5  * Acquisition and use of this software and related materials for any
6  * purpose requires a written licence agreement from Isode Limited,
7  * or a written licence from an organisation licenced by Isode Limited
8  * to grant such a licence.
9  */
10 
11 /*
12  * @VERSION@
13  * Simple example program for submitting a message via a message store.
14  */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <sys/stat.h>
20 #include <sys/types.h>
21 #ifndef _WIN32
22 #include <unistd.h>
23 #endif
24 #include <fcntl.h>
25 #include <errno.h>
26 
27 #include <x400_msapi.h>
28 #include <seclabel_api.h> /* For security labels */
29 #include "example.h"
30 #include "ms_example.h"
31 #include "time.h"
32 
33 
34 static char *optstr = "u371m:d:p:w:M:D:P:W:r:o:O:r:g:G:c:l:R:y:C:iaqsAvf:kK:B:";
35 
36 /* These are the data items used to construct the message for submission */
37 static char *default_recip = "/CN=P7User1/O=attlee/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
38 char *recip;
39 static const char text[] = "First line\r\nSecond line\r\n";
40 static char *binary_data;
41 
42 static char *fwd_subject = "Forwarded message subject";
43 
44 static int add_binary_attachment (
45  struct X400msMessage *mp,
46  char * filename_to_send
47 );
48 static int add_fwd_bp (
49  struct X400msMessage *mp,
50  char *recip_orn,
51  char *recip_dn
52 ) ;
53 static void usage(void) ;
54 
55 
56 int main (
57  int argc,
58  char **argv
59 )
60 {
61  char buffer[BUFSIZ];
62  char pa[BUFSIZ];
63  char orn[BUFSIZ];
64  char tmp[BUFSIZ];
65  int status;
66  struct X400msSession *sp;
67  struct X400msMessage *mp;
68  struct X400Recipient *rp;
69  int contype;
70  char *def_oraddr;
71  char *def_dn;
72  char *def_pa;
73 
74  if (get_args(argc, argv, optstr)) {
75  usage();
76  exit(-1);
77  }
78 
79  printf("Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
80  contype = ic_fgetc(x400_contype, stdin);
81  if (contype != 10)
82  ic_fgetc(x400_contype, stdin);
83 
84  if ( contype < '0' || '2' < contype )
85  contype = x400_contype;
86  else
87  contype -= '0';
88 
89  if (contype == 0) {
90  def_oraddr = x400_ms_user_addr;
91  def_dn = x400_ms_user_dn;
92  def_pa = x400_ms_presentation_address;
93  } else {
94  def_oraddr = x400_mta_user_addr;
95  def_dn = x400_mta_user_dn;
96  def_pa = x400_mta_presentation_address;
97  }
98 
99  printf("Your ORAddress [%s] > ", def_oraddr);
100  ic_fgets (orn, sizeof orn, stdin);
101 
102  if ( orn[strlen(orn)-1] == '\n' )
103  orn[strlen(orn)-1] = '\0';
104 
105  if (orn[0] == '\0')
106  strcpy(orn, def_oraddr);
107 
108  /* Prompt for password; note: reflected. */
109  printf ("Password [%s]: ",
110  contype == 0 ? x400_p7_password : x400_p3_password);
111  if ( ic_fgets (buffer, sizeof buffer, stdin) == NULL )
112  exit (1);
113 
114  if (buffer[strlen(buffer)-1] == '\n' )
115  buffer[strlen(buffer)-1] = '\0';
116  if (buffer[0] == '\0')
117  strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
118 
119  /* Presentation Address */
120  printf("Presentation Address [%s] > ", def_pa);
121  ic_fgets (pa, sizeof pa, stdin);
122 
123  if ( pa[strlen(pa)-1] == '\n' )
124  pa[strlen(pa)-1] = '\0';
125 
126  if (pa[0] == '\0')
127  strcpy(pa, def_pa);
128 
129  if (talking_to_marben_ms)
131 
132  /* we've got what we need - now open an API session */
133  status = X400msOpen (contype, orn, def_dn, buffer, pa, NULL, &sp);
134  if ( status != X400_E_NOERROR ) {
135  fprintf (stderr, "Error in Open: %s\n", X400msError (status));
136  exit (status);
137  }
138 
139  if (talking_to_marben_ms)
141 
142  /* setup logging */
143  X400msSetStrDefault(sp, X400_S_LOG_CONFIGURATION_FILE, "x400api.xml", 0);
144 
145  /* Turn on generation of extended-subject heading extension */
147 
148  /* Configure the character sets to be used for Teletex syntax fields
149  (X400_S_FREE_FORM_NAME, X400_T_TELETEX, X400_S_SUBJECT). If not
150  explicitly configured, the default set of 102, 103, 106, 107
151  will be assumed. The string below adds Cyrillic (8859-5) into the list. */
152  X400msSetStrDefault(sp, X400_S_TELETEX_CHARSETS, "102 103 106 107 144", -1);
153 
154  /* Configure the character sets to be used for Graphic string syntax fields
155  (X400_S_FTBP_APPLICATION_REFERENCE_STR, X400_S_FTBP_CONTENT_DESCRIPTION,
156  X400_S_FTBP_FILENAME). If not explicitly configured, a default of
157  character set 6 (US-ASCII) will be assumed.
158  The string below adds Cyrillic (8859-5) into the list. */
160 
161  if (x400_default_recipient != NULL)
162  recip = x400_default_recipient;
163  else
164  recip = default_recip;
165 
166  printf("Message recipient [%s]: ", recip);
167  ic_fgets (tmp, sizeof tmp, stdin);
168 
169  if ( tmp[strlen(tmp)-1] == '\n' )
170  tmp[strlen(tmp)-1] = '\0';
171  if (strlen(tmp) != 0)
172  recip = strdup(tmp);
173 
174  printf("Subject [%s]: ", subject);
175  ic_fgets (tmp, sizeof tmp, stdin);
176 
177  if ( tmp[strlen(tmp)-1] == '\n' )
178  tmp[strlen(tmp)-1] = '\0';
179  if (strlen(tmp) != 0)
180  subject = strdup(tmp);
181 
182  status = X400msMsgNew (sp, X400_MSG_MESSAGE, &mp);
183  if ( status != X400_E_NOERROR ) {
184  fprintf (stderr, "x400msMsgNew returned error: %s\n", X400msError (status));
185  exit (status);
186  }
187 
188  status = X400msRecipNew (mp, X400_RECIP_STANDARD, &rp);
189  if ( status != X400_E_NOERROR ) {
190  fprintf (stderr, "x400msRecipNew returned error: %s\n", X400msError (status));
191  exit (status);
192  }
193 
194  status = X400msRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
195  if ( status != X400_E_NOERROR ) {
196  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
197  exit (status);
198  }
199 
200  status = X400msRecipAddStrParam (rp, X400_S_DIRECTORY_NAME, "CN=recipient;c=gb", -1);
201  if ( status != X400_E_NOERROR ) {
202  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
203  exit (status);
204  }
205 
206  status = X400msMsgAddStrParam (mp, X400_S_OR_ADDRESS, orn, -1);
207  if ( status != X400_E_NOERROR ) {
208  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
209  exit (status);
210  }
211 
212  status = X400msMsgAddStrParam (mp, X400_S_DIRECTORY_NAME, "CN=originator;c=gb", -1);
213  if ( status != X400_E_NOERROR ) {
214  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
215  exit (status);
216  }
217 
218  /* Ask for delivery reports */
219  printf("delivery report request %d ( 1 - No, 2 - Yes)\n", x400_dr_req);
220  status = X400msRecipAddIntParam (rp, X400_N_REPORT_REQUEST, x400_dr_req);
221  if ( status != X400_E_NOERROR ) {
222  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
223  exit (status);
224  }
225 
226  /* Ask for read receipts */
227  printf("read notification request %d ( 1 - RN, 2 - NRN, 4 - return of IPM with NRN )\n", x400_rn_req);
228  status = X400msRecipAddIntParam (rp, X400_N_NOTIFICATION_REQUEST, x400_rn_req);
229  if ( status != X400_E_NOERROR ) {
230  fprintf (stderr, "x400msRecipAddIntParam returned error: %s\n", X400msError (status));
231  exit (status);
232  }
233 
234  if (1) {
235  char *contid = "ContID00001";
236 
237  /* Content identifier so we can correlate with submission result */
238  status = X400msMsgAddStrParam(mp, X400_S_CONTENT_IDENTIFIER, contid, -1);
239  if ( status != X400_E_NOERROR ) {
240  fprintf (stderr, "X400msMsgAddIntParam %d returned error: %s\n",
242  exit (status);
243  }
244  }
245 
246  /* content return request on report - 0 = no */
248  if ( status != X400_E_NOERROR ) {
249  fprintf (stderr, "X400msMsgAddIntParam %d returned error: %s\n",
251  exit (status);
252  }
253 
254  /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
255  printf("message priority is %d ( 0 - normal, 1 - non-urgent, 2 - urgent)\n",
256  x400_default_priority);
257  status = X400msMsgAddIntParam (mp, X400_N_PRIORITY, x400_default_priority);
258  if ( status != X400_E_NOERROR ) return (status);
259 
260  /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
261  printf("military message priority is %d ( 0 - low, 1 - high)\n",
262  x400_default_priority);
264  if ( status != X400_E_NOERROR ) return (status);
265 
266  /* subject */
267  {
268  time_t t;
269  time(&t);
270  char tmp_buffer[255];
271  // NB strip newline from ctime result
272  snprintf(tmp_buffer, 244, "%s '%s' '%.19s'",
273  subject, get_x400_pty_str_from_4406(x400_default_priority), ctime(&t));
274  printf("Subject is '%s'\n", tmp_buffer);
275  status = X400msMsgAddStrParam (mp, X400_S_SUBJECT, tmp_buffer, -1);
276  if ( status != X400_E_NOERROR ) {
277  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n",
278  X400msError (status));
279  exit (status);
280  }
281  }
282 
283  /* content type */
284  status = X400msMsgAddStrParam (mp, X400_S_EXTERNAL_CONTENT_TYPE, "1.3.26.0.4406.0.4.1", -1);
285  if ( status != X400_E_NOERROR ) {
286  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
287  exit (status);
288  }
289  /* 8859-1 attachment */
290  status = X400msMsgAddStrParam (mp, X400_T_ISO8859_1, text, -1);
291  if ( status != X400_E_NOERROR ) {
292  fprintf (stderr, "x400ms returned error: %s\n", X400msError (status));
293  exit (status);
294  }
295 
296  /* now an IA5 body part using the bodypart func */
297  status = X400msMsgAddAttachment (mp, X400_T_IA5TEXT, text, strlen(text));
298  if ( status != X400_E_NOERROR ) {
299  printf("failed to add X400_T_IA5TEXT BP\n");
300  return (status);
301  }
302 
303  /* or a Binary body part using the bodypart func */
304  if (filename_to_send != NULL) {
305  status = add_binary_attachment (mp, filename_to_send);
306  if ( status != X400_E_NOERROR ) {
307  printf("failed to add X400_T_BINARY BP\n");
308  return (status);
309  }
310  status = add_fwd_bp (mp, orn, def_dn);
311  if ( status != X400_E_NOERROR ) {
312  printf("failed to add forwarded BP\n");
313  return (status);
314  }
315  } else {
316  printf("no binary file set - not sending X400_T_BINARY\n");
317  printf("no binary file set - not sending forwarded BP\n");
318  }
319 
320 
321 #ifdef USE_SEC_LABEL
322  {
323 #define XML_BUFSIZE 1024
324 #define STRING_BUFSIZE 1024
325 
326  const char* xml_filename = "seclabel.xml";
327  char xml_content[XML_BUFSIZE];
328  char str_content[STRING_BUFSIZE];
329  int str_len = STRING_BUFSIZE;
330  FILE *fd = NULL;
331 
332  /* Read in the security label XML file */
333  fd = fopen(xml_filename,"r");
334  if(fd == NULL) {
335  fprintf(stderr,"Failed to open %s : %s\n",
336  xml_filename,strerror(errno));
337  }
338 
339  fread(&xml_content,XML_BUFSIZE,1,fd);
340 
341  fclose(fd);
342 
343  status = SecLabelInit("Example program");
344  if (status != SECLABEL_E_NOERROR) {
345  fprintf(stderr, "SecLabelInit returned error %d\n", status);
346  exit(1);
347  }
348 
349  /* Use SecLabelParse to turn the XML into an octet string */
350  status = SecLabelParse(xml_content,
351  str_content,
352  STRING_BUFSIZE,
353  &str_len);
354 
355  if (status != SECLABEL_E_NOERROR) {
356  fprintf(stderr, "SecLabelParse returned error %d\n", status);
357  exit(1);
358  }
359 
360  /* Add the octet string to the message pointer */
362  str_content,str_len);
363  if ( status != X400_E_NOERROR ) {
364  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
365  exit (status);
366  }
367 
368  }
369 #endif
370 
371  status = X400msMsgSend (mp);
372  if ( status != X400_E_NOERROR ) {
373  fprintf (stderr, "x400msMsgSend returned error: %s\n", X400msError (status));
374 
375  if (status == X400_E_RECIPIENT_ERROR) {
376  int n = 1;
377  struct X400Recipient *irp;
378  int ss = X400_E_NOERROR;
379 
380  while (ss == X400_E_NOERROR) {
381  ss = X400msRecipGet(mp, X400_RECIP_INVALID, n, &irp);
382  if (ss == X400_E_NOERROR) {
383  char buf[1024];
384  size_t retlen;
385  int s;
386 
387  fprintf(stderr, "A recipient with ");
388 
389  s = X400msRecipGetStrParam(irp, X400_S_OR_ADDRESS, buf, 1024, &retlen);
390  if (s == X400_E_NOERROR) {
391  buf[retlen] = '\0';
392  fprintf (stderr, "ORAddress %s ", buf);
393  }
394 
395  s = X400msRecipGetStrParam(irp, X400_S_DIRECTORY_NAME, buf, 1024, &retlen);
396  if (s == X400_E_NOERROR) {
397  buf[retlen] = '\0';
398  fprintf (stderr, " and DN %s", buf);
399  }
400  fprintf (stderr, " was rejected\n");
401  n++;
402  }
403  }
404  }
405 
406  } else {
407  char buf[1024];
408  size_t retlen;
409 
410  printf("Message submitted successfully\n");
411 
412  status = X400msMsgGetStrParam(mp, X400_S_MESSAGE_IDENTIFIER, buf, 1024, &retlen);
413  if (status != X400_E_NOERROR) {
414  fprintf(stderr, "No MessageId present from submission result: error %d\n", status);
415  } else {
416  buf [retlen] = '\0';
417  printf("MessageId from Submission Result = %s\n", buf);
418  }
419 
420  status = X400msMsgGetStrParam(mp, X400_S_MESSAGE_SUBMISSION_TIME, buf, 1024, &retlen);
421  if (status != X400_E_NOERROR) {
422  fprintf(stderr, "No MessageSubmissionTime present from submission result: error %d\n", status);
423  } else {
424  buf [retlen] = '\0';
425  printf("MessageSubmissionTime from Submission Result = %s\n", buf);
426  }
427 
428  status = X400msMsgGetStrParam(mp, X400_S_CONTENT_IDENTIFIER, buf, 1024, &retlen);
429  if (status != X400_E_NOERROR) {
430  fprintf(stderr, "No ContentIdentifier present from submission result: error %d\n", status);
431  } else {
432  buf [retlen] = '\0';
433  printf("ContentIdentifier from Submission Result = %s\n", buf);
434  }
435  }
436 
437  status = X400msMsgDelete (mp, 0);
438  if ( status != X400_E_NOERROR ) {
439  fprintf (stderr, "x400msMsgDelete returned error: %s\n", X400msError (status));
440  exit (status);
441  }
442 
443  mp = NULL;
444  rp = NULL;
445 
446  status = X400msClose (sp);
447  exit (status);
448  /* NOTREACHED */
449 }
450 
451 static int add_binary_attachment (
452  struct X400msMessage *mp,
453  char * filename
454 )
455 {
456  int fd;
457  int file_size;
458  struct stat buf;
459  int fs=0;
460  int status;
461 
462  printf("sending file %s\n", filename);
463  if ((fd = open (filename_to_send, O_RDONLY)) == -1) {
464  printf("Failed to open content file %s", filename);
465  return X400_E_BADPARAM;
466  }
467 
468 
469  if (fstat(fd, &buf) != 0) {
470  close(fd);
471  printf("Can't fstat file %s %d", filename, errno);
472  return X400_E_BADPARAM;
473  }
474 
475  file_size = buf.st_size;
476  printf("Content file size = %d\n", file_size);
477 
478  binary_data = (char *) malloc(file_size);
479  if ( binary_data == NULL )
480  return X400_E_NOMEMORY;
481  if ((fs = read(fd, binary_data, file_size) ) == -1) {
482  printf("Cannot read from binary file %d\n", errno);
483  return (X400_E_SYSERROR);
484  }
485  close(fd);
486 
487  status = X400msMsgAddAttachment (mp, X400_T_BINARY, binary_data, fs);
488  if ( status != X400_E_NOERROR ) {
489  printf("failed to add X400_T_BINARY BP\n");
490  return (status);
491  }
492  return (status);
493 }
494 
495 static int add_fwd_bp (
496  struct X400msMessage *mp,
497  char *orig_orn,
498  char *orig_dn
499 )
500 {
501  struct X400Message *x400_mp;
502  struct X400Recipient *rp;
503  int status;
504  int num_atts = 0;
505 
506  printf("sending fwd bp \n");
507 
508  status = X400MsgNew (X400_MSG_MESSAGE, &x400_mp);
509  if ( status != X400_E_NOERROR ) {
510  fprintf (stderr, "x400MsgNew returned error: %s\n", X400msError (status));
511  exit (status);
512  }
513 
515  "090909090909Z", (size_t)-1);
516  if ( status != X400_E_NOERROR ) {
517  fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
518  exit (status);
519  }
520 
522  "090909090909Z", (size_t)-1);
523  if ( status != X400_E_NOERROR ) {
524  fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
525  exit (status);
526  }
527 
528  /* envelope originator OR address */
529  status = X400MsgAddStrParam (x400_mp, X400_S_OR_ADDRESS, orig_orn, (size_t)-1);
530  if ( status != X400_E_NOERROR ) {
531  fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
532  exit (status);
533  }
534  status = X400MsgAddStrParam (x400_mp, X400_S_DIRECTORY_NAME, orig_dn, (size_t)-1);
535  if ( status != X400_E_NOERROR ) {
536  fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
537  exit (status);
538  }
539 
540  /* add originator into headers */
541  status = X400RecipNew (X400_ORIGINATOR, &rp);
542  if ( status != X400_E_NOERROR ) {
543  fprintf (stderr, "x400RecipNew returned error: %s\n", X400msError (status));
544  exit (status);
545  }
546 
547  /* put in OR Address part of OR Name */
548  status = X400RecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
549  if ( status != X400_E_NOERROR ) {
550  fprintf (stderr, "x400RecipAddStrParam returned error: %s\n", X400msError (status));
551  exit (status);
552  }
553 
554  /* put in DN part of OR Name */
555  status = X400RecipAddStrParam (rp, X400_S_DIRECTORY_NAME, orig_dn, -1);
556  if ( status != X400_E_NOERROR ) {
557  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
558  exit (status);
559  }
560 
561  /* put originator into message */
562  status = X400MsgAddRecip (x400_mp, X400_ORIGINATOR, rp);
563  if ( status != X400_E_NOERROR ) {
564  fprintf (stderr, "X400MsgAddRecip returned error: %s\n", X400msError (status));
565  exit (status);
566  }
567  printf("Put %s in as originator\n", orig_orn);
568 
569  /* add a recipient */
570  status = X400RecipNew (X400_RECIP_STANDARD, &rp);
571  if ( status != X400_E_NOERROR ) {
572  fprintf (stderr, "x400RecipNew returned error: %s\n", X400msError (status));
573  exit (status);
574  }
575 
576  status = X400RecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
577  if ( status != X400_E_NOERROR ) {
578  fprintf (stderr, "x400RecipAddStrParam returned error: %s\n", X400msError (status));
579  exit (status);
580  }
581 
582  status = X400RecipAddStrParam (rp, X400_S_DIRECTORY_NAME, "CN=recipient;c=gb", -1);
583  if ( status != X400_E_NOERROR ) {
584  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
585  exit (status);
586  }
587 
588  status = X400MsgAddRecip (x400_mp, X400_RECIP_STANDARD, rp);
589  if ( status != X400_E_NOERROR ) {
590  fprintf (stderr, "X400MsgAddRecip returned error: %s\n", X400msError (status));
591  exit (status);
592  }
593  printf("Put %s in as reipient\n", recip);
594 
595 
596  /* Add 2nd recipient */
597  status = X400RecipNew (X400_RECIP_STANDARD, &rp);
598  if ( status != X400_E_NOERROR ) {
599  fprintf (stderr, "x400RecipNew returned error: %s\n", X400msError (status));
600  exit (status);
601  }
602 
603  status = X400RecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
604  if ( status != X400_E_NOERROR ) {
605  fprintf (stderr, "x400RecipAddStrParam returned error: %s\n", X400msError (status));
606  exit (status);
607  }
608 
609  status = X400RecipAddStrParam (rp, X400_S_DIRECTORY_NAME, "CN=second recipient;c=gb", -1);
610  if ( status != X400_E_NOERROR ) {
611  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
612  exit (status);
613  }
614 
615 
616  /* put recipient into message */
617  status = X400MsgAddRecip (x400_mp, X400_RECIP_STANDARD, rp);
618  if ( status != X400_E_NOERROR ) {
619  fprintf (stderr, "X400MsgAddRecip returned error: %s\n", X400msError (status));
620  exit (status);
621  }
622  printf("Put %s in as reipient\n", recip);
623 
624 
625  /* envelope */
626 
627  /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
628  printf("message priority is %d ( 0 - normal, 1 - non-urgent, 2 - urgent)\n",
629  x400_default_priority);
630  status = X400MsgAddIntParam (x400_mp, X400_N_PRIORITY, x400_default_priority);
631  if ( status != X400_E_NOERROR ) return (status);
632 
633  /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
634  printf("military message priority is %d ( 0 - low, 1 - high)\n",
635  x400_default_priority);
636  status = X400MsgAddIntParam (x400_mp, X400_N_MMTS_PRIORITY_QUALIFIER, 1);
637  if ( status != X400_E_NOERROR ) return (status);
638 
639  /* content */
640  /* subject */
641  status = X400MsgAddStrParam (x400_mp, X400_S_SUBJECT, fwd_subject, (size_t)-1);
642  if ( status != X400_E_NOERROR ) {
643  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
644  exit (status);
645  }
646 
647  /* now an IA5 body part using the bodypart func */
648  status = X400MsgAddAttachment (x400_mp, X400_T_IA5TEXT, text, strlen(text));
649  if ( status != X400_E_NOERROR ) {
650  printf("failed to add X400_T_IA5TEXT BP\n");
651  return (status);
652  }
653  num_atts++;
654 
655  /* 8859-1 attachment */
656  status = X400MsgAddStrParam (x400_mp, X400_T_ISO8859_1, text, (size_t)-1);
657  if ( status != X400_E_NOERROR ) {
658  fprintf (stderr, "x400ms returned error: %s\n", X400msError (status));
659  exit (status);
660  }
661  num_atts++;
662 
663  status = X400MsgAddIntParam (x400_mp, X400_N_NUM_ATTACHMENTS, num_atts);
664  if (status != X400_E_NOERROR )
665  return (status);
666 
667  status = X400msMsgAddMessageBody (mp, x400_mp);
668  if (status != X400_E_NOERROR ) {
669  fprintf (stderr, "X400msMsgAddMessageBody returned error: %s\n", X400msError (status));
670  return (status);
671  }
672 
673  return X400_E_NOERROR;
674 }
675 
676 static void usage(void) {
677  printf("usage: %s\n", optstr);
678  printf("\t where:\n");
679  printf("\t -u : Don't prompt to override defaults \n");
680  printf("\t -3 : Use P3 connection \n");
681  printf("\t -7 : Use P7 connection \n");
682  printf("\t -m : OR Address in P7 bind arg \n");
683  printf("\t -d : DN in P7 bind arg \n");
684  printf("\t -p : Presentation Address of P7 Store \n");
685  printf("\t -w : P7 password of P7 user \n");
686  printf("\t -M : OR Address in P3 bind arg \n");
687  printf("\t -D : DN in P3 bind arg \n");
688  printf("\t -P : Presentation Address of P3 server\n");
689  printf("\t -W : P3 password of P3 user \n");
690  printf("\t -o : Originator \n");
691  printf("\t -O : Originator Return Address \n");
692  printf("\t -r : Recipient\n");
693  printf("\t -l : Logline\n");
694  printf("\t -y : Military Priority \n");
695  printf("\t\t 0 - deferred, 1 - routine, 2 - priority \n");
696  printf("\t\t 3 - immediate, 4 - flash, 5 - override \n");
697  printf("\t -C : Content Type (2/22/772/OID) \n");
698  printf("\t -i : Implicit conversion prohibited = TRUE \n");
699  printf("\t -a : Alternate Recipient Prohibited = TRUE \n");
700  printf("\t -q : Content Return Request = TRUE \n");
701  printf("\t -s : Disclosure of Recipient = FALSE \n");
702  printf("\t -A : Recipient Reassignment Prohibited = FALSE \n");
703  printf("\t -v : Conversion with Loss Prohibited = FALSE \n");
704  printf("\t -f : Filename to transfer as binary bp\n");
705  printf("\t -k : Request Delivery Report\n");
706  printf("\t -K : Request Read Notification ( 1 - RN, 2 - NRN, 4 - return of IPM with NRN )\n");
707  return;
708 }
#define X400_S_DIRECTORY_NAME
Definition: x400_att.h:394
#define X400_MSG_MESSAGE
Definition: x400_att.h:29
#define X400_S_EXTERNAL_CONTENT_TYPE
Definition: x400_att.h:444
#define X400_S_TELETEX_CHARSETS
Definition: x400_att.h:1139
#define X400_E_SYSERROR
Definition: x400_att.h:49
#define X400_S_LOG_CONFIGURATION_FILE
Definition: x400_att.h:1080
int X400msSetStrDefault(struct X400msSession *sp, int paramtype, const char *value, size_t length)
Set a default string parameter value in a session.
int X400MsgNew(int type, struct X400Message **mpp)
Creates new message.
#define X400_S_CONTENT_IDENTIFIER
Definition: x400_att.h:411
int X400msMsgAddStrParam(struct X400msMessage *mp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
int X400msMsgAddMessageBody(struct X400msMessage *mp, struct X400Message *mbp)
void X400msSetConfigRequest(int val)
Disable and enable configuration requests in MS Bind operations.
int X400MsgAddStrParam(struct X400Message *mp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
int X400MsgAddIntParam(struct X400Message *mp, int paramtype, int value)
Add integer-valued parameter to the message.
int X400msRecipAddIntParam(struct X400Recipient *rp, int paramtype, int value)
Add integer-valued parameter to the message.
#define X400_N_STRICT_P7_1988
Definition: x400_att.h:1257
int X400RecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the recipient.
#define X400_S_GRAPHIC_CHARSETS
Definition: x400_att.h:1132
#define X400_E_RECIPIENT_ERROR
Definition: x400_att.h:154
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
int X400msMsgNew(struct X400msSession *sp, int type, struct X400msMessage **mpp)
Creates new message.
int X400msClose(struct X400msSession *sp)
Close a X400 Session.
#define X400_T_ISO8859_1
Definition: x400_att.h:805
int X400MsgAddAttachment(struct X400Message *mp, int type, const char *string, size_t length)
Add an attachment to the message.
#define X400_N_NOTIFICATION_REQUEST
Definition: x400_att.h:672
int X400msMsgAddAttachment(struct X400msMessage *mp, int type, const char *string, size_t length)
Add attachment to the message.
int X400msRecipGet(struct X400msMessage *mp, int type, int number, struct X400Recipient **rpp)
Get recipient object from message.
int X400msRecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
#define X400_S_MESSAGE_SUBMISSION_TIME
Definition: x400_att.h:436
#define X400_T_IA5TEXT
Definition: x400_att.h:795
#define X400_E_NOERROR
Definition: x400_att.h:46
int X400msOpen(int type, const char *oraddr, const char *dirname, const char *credentials, const char *pa, int *messages, struct X400msSession **spp)
Open a session to a Message Store (P7) or MTA (P3) in synchronous mode.
#define X400_ORIGINATOR
Definition: x400_att.h:302
int X400RecipNew(int type, struct X400Recipient **rpp)
Create a new recipient object.
#define X400_N_NUM_ATTACHMENTS
Definition: x400_att.h:792
#define X400_S_OR_ADDRESS
Definition: x400_att.h:346
#define X400_S_MESSAGE_IDENTIFIER
Definition: x400_att.h:402
int X400msMsgGetStrParam(struct X400msMessage *mp, int paramtype, char *buffer, size_t buflen, size_t *paramlenp)
Return a string-valued parameter from the message object.
#define X400_RECIP_STANDARD
Definition: x400_att.h:338
#define X400_T_BINARY
Definition: x400_att.h:821
int X400MsgAddRecip(struct X400Message *mp, int reciptype, struct X400Recipient *recip)
Add a recipient object to the message.
#define X400_E_BADPARAM
Definition: x400_att.h:55
#define X400_S_SECURITY_LABEL
Definition: x400_att.h:1319
#define X400_N_REPORT_REQUEST
Definition: x400_att.h:650
#define X400_RECIP_INVALID
Definition: x400_att.h:335
int X400msMsgSend(struct X400msMessage *mp)
Send message object.
int X400msRecipGetStrParam(struct X400Recipient *rp, int paramtype, char *buffer, size_t buflen, size_t *paramlenp)
Return a string-valued parameter from the recipient object.
X400 MA/MS (P3/P7) Interface.
#define X400_N_PRIORITY
Definition: x400_att.h:419
int X400msRecipNew(struct X400msMessage *mp, int type, struct X400Recipient **rpp)
Add new recipient to a message.
#define X400_N_USE_EXTENDED_SUBJECT
Definition: x400_att.h:1264
int X400msSetIntDefault(struct X400msSession *sp, int paramtype, int value)
Set a default integer parameter value in a session.
#define X400_E_NOMEMORY
Definition: x400_att.h:52
#define X400_S_SUBJECT
Definition: x400_att.h:719
#define X400_N_MMTS_PRIORITY_QUALIFIER
Definition: x400_att.h:470
#define X400_N_CONTENT_RETURN_REQUEST
Definition: x400_att.h:433
int X400msMsgAddIntParam(struct X400msMessage *mp, int paramtype, int value)
Add integer-valued parameter to the message.
int X400msMsgDelete(struct X400msMessage *mp, int retain)
Delete message object.
#define X400_S_MESSAGE_DELIVERY_TIME
Definition: x400_att.h:439