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  /* Turn on error on duplicate string attribute setting */
150 
151  /* Configure the character sets to be used for Teletex syntax fields
152  (X400_S_FREE_FORM_NAME, X400_T_TELETEX, X400_S_SUBJECT). If not
153  explicitly configured, the default set of 102, 103, 106, 107
154  will be assumed. The string below adds Cyrillic (8859-5) into the list. */
155  X400msSetStrDefault(sp, X400_S_TELETEX_CHARSETS, "102 103 106 107 144", -1);
156 
157  /* Configure the character sets to be used for Graphic string syntax fields
158  (X400_S_FTBP_APPLICATION_REFERENCE_STR, X400_S_FTBP_CONTENT_DESCRIPTION,
159  X400_S_FTBP_FILENAME). If not explicitly configured, a default of
160  character set 6 (US-ASCII) will be assumed.
161  The string below adds Cyrillic (8859-5) into the list. */
163 
164  if (x400_default_recipient != NULL)
165  recip = x400_default_recipient;
166  else
167  recip = default_recip;
168 
169  printf("Message recipient [%s]: ", recip);
170  ic_fgets (tmp, sizeof tmp, stdin);
171 
172  if ( tmp[strlen(tmp)-1] == '\n' )
173  tmp[strlen(tmp)-1] = '\0';
174  if (strlen(tmp) != 0)
175  recip = strdup(tmp);
176 
177  printf("Subject [%s]: ", subject);
178  ic_fgets (tmp, sizeof tmp, stdin);
179 
180  if ( tmp[strlen(tmp)-1] == '\n' )
181  tmp[strlen(tmp)-1] = '\0';
182  if (strlen(tmp) != 0)
183  subject = strdup(tmp);
184 
185  status = X400msMsgNew (sp, X400_MSG_MESSAGE, &mp);
186  if ( status != X400_E_NOERROR ) {
187  fprintf (stderr, "x400msMsgNew returned error: %s\n", X400msError (status));
188  exit (status);
189  }
190 
191  status = X400msRecipNew (mp, X400_RECIP_STANDARD, &rp);
192  if ( status != X400_E_NOERROR ) {
193  fprintf (stderr, "x400msRecipNew returned error: %s\n", X400msError (status));
194  exit (status);
195  }
196 
197  status = X400msRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
198  if ( status != X400_E_NOERROR ) {
199  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
200  exit (status);
201  }
202 
203  status = X400msRecipAddStrParam (rp, X400_S_DIRECTORY_NAME, "CN=recipient;c=gb", -1);
204  if ( status != X400_E_NOERROR ) {
205  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
206  exit (status);
207  }
208 
209  status = X400msMsgAddStrParam (mp, X400_S_OR_ADDRESS, orn, -1);
210  if ( status != X400_E_NOERROR ) {
211  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
212  exit (status);
213  }
214 
215  status = X400msMsgAddStrParam (mp, X400_S_DIRECTORY_NAME, "CN=originator;c=gb", -1);
216  if ( status != X400_E_NOERROR ) {
217  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
218  exit (status);
219  }
220 
221  /* Ask for delivery reports */
222  printf("delivery report request %d ( 1 - No, 2 - Yes)\n", x400_dr_req);
223  status = X400msRecipAddIntParam (rp, X400_N_REPORT_REQUEST, x400_dr_req);
224  if ( status != X400_E_NOERROR ) {
225  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
226  exit (status);
227  }
228 
229  /* Ask for read receipts */
230  printf("read notification request %d ( 1 - RN, 2 - NRN, 4 - return of IPM with NRN )\n", x400_rn_req);
231  status = X400msRecipAddIntParam (rp, X400_N_NOTIFICATION_REQUEST, x400_rn_req);
232  if ( status != X400_E_NOERROR ) {
233  fprintf (stderr, "x400msRecipAddIntParam returned error: %s\n", X400msError (status));
234  exit (status);
235  }
236 
237  if (1) {
238  char *contid = "ContID00001";
239 
240  /* Content identifier so we can correlate with submission result */
241  status = X400msMsgAddStrParam(mp, X400_S_CONTENT_IDENTIFIER, contid, -1);
242  if ( status != X400_E_NOERROR ) {
243  fprintf (stderr, "X400msMsgAddIntParam %d returned error: %s\n",
245  exit (status);
246  }
247  }
248 
249  /* content return request on report - 0 = no */
251  if ( status != X400_E_NOERROR ) {
252  fprintf (stderr, "X400msMsgAddIntParam %d returned error: %s\n",
254  exit (status);
255  }
256 
257  /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
258  printf("message priority is %d ( 0 - normal, 1 - non-urgent, 2 - urgent)\n",
259  x400_default_priority);
260  status = X400msMsgAddIntParam (mp, X400_N_PRIORITY, x400_default_priority);
261  if ( status != X400_E_NOERROR ) return (status);
262 
263  /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
264  printf("military message priority is %d ( 0 - low, 1 - high)\n",
265  x400_default_priority);
267  if ( status != X400_E_NOERROR ) return (status);
268 
269  /* subject */
270  {
271  time_t t;
272  time(&t);
273  char tmp_buffer[255];
274  // NB strip newline from ctime result
275  snprintf(tmp_buffer, 244, "%s '%s' '%.19s'",
276  subject, get_x400_pty_str_from_4406(x400_default_priority), ctime(&t));
277  printf("Subject is '%s'\n", tmp_buffer);
278  status = X400msMsgAddStrParam (mp, X400_S_SUBJECT, tmp_buffer, -1);
279  if ( status != X400_E_NOERROR ) {
280  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n",
281  X400msError (status));
282  exit (status);
283  }
284  }
285 
286  /* content type */
287  status = X400msMsgAddStrParam (mp, X400_S_EXTERNAL_CONTENT_TYPE, "1.3.26.0.4406.0.4.1", -1);
288  if ( status != X400_E_NOERROR ) {
289  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
290  exit (status);
291  }
292  /* 8859-1 attachment */
293  status = X400msMsgAddStrParam (mp, X400_T_ISO8859_1, text, -1);
294  if ( status != X400_E_NOERROR ) {
295  fprintf (stderr, "x400ms returned error: %s\n", X400msError (status));
296  exit (status);
297  }
298 
299  /* now an IA5 body part using the bodypart func */
300  status = X400msMsgAddAttachment (mp, X400_T_IA5TEXT, text, strlen(text));
301  if ( status != X400_E_NOERROR ) {
302  printf("failed to add X400_T_IA5TEXT BP\n");
303  return (status);
304  }
305 
306  /* or a Binary body part using the bodypart func */
307  if (filename_to_send != NULL) {
308  status = add_binary_attachment (mp, filename_to_send);
309  if ( status != X400_E_NOERROR ) {
310  printf("failed to add X400_T_BINARY BP\n");
311  return (status);
312  }
313  status = add_fwd_bp (mp, orn, def_dn);
314  if ( status != X400_E_NOERROR ) {
315  printf("failed to add forwarded BP\n");
316  return (status);
317  }
318  } else {
319  printf("no binary file set - not sending X400_T_BINARY\n");
320  printf("no binary file set - not sending forwarded BP\n");
321  }
322 
323 
324 #ifdef USE_SEC_LABEL
325  {
326 #define XML_BUFSIZE 1024
327 #define STRING_BUFSIZE 1024
328 
329  const char* xml_filename = "seclabel.xml";
330  char xml_content[XML_BUFSIZE];
331  char str_content[STRING_BUFSIZE];
332  int str_len = STRING_BUFSIZE;
333  FILE *fd = NULL;
334 
335  /* Read in the security label XML file */
336  fd = fopen(xml_filename,"r");
337  if(fd == NULL) {
338  fprintf(stderr,"Failed to open %s : %s\n",
339  xml_filename,strerror(errno));
340  }
341 
342  fread(&xml_content,XML_BUFSIZE,1,fd);
343 
344  fclose(fd);
345 
346  status = SecLabelInit("Example program");
347  if (status != SECLABEL_E_NOERROR) {
348  fprintf(stderr, "SecLabelInit returned error %d\n", status);
349  exit(1);
350  }
351 
352  /* Use SecLabelParse to turn the XML into an octet string */
353  status = SecLabelParse(xml_content,
354  str_content,
355  STRING_BUFSIZE,
356  &str_len);
357 
358  if (status != SECLABEL_E_NOERROR) {
359  fprintf(stderr, "SecLabelParse returned error %d\n", status);
360  exit(1);
361  }
362 
363  /* Add the octet string to the message pointer */
365  str_content,str_len);
366  if ( status != X400_E_NOERROR ) {
367  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
368  exit (status);
369  }
370 
371  }
372 #endif
373 
374  status = X400msMsgSend (mp);
375  if ( status != X400_E_NOERROR ) {
376  fprintf (stderr, "x400msMsgSend returned error: %s\n", X400msError (status));
377 
378  if (status == X400_E_RECIPIENT_ERROR) {
379  int n = 1;
380  struct X400Recipient *irp;
381  int ss = X400_E_NOERROR;
382 
383  while (ss == X400_E_NOERROR) {
384  ss = X400msRecipGet(mp, X400_RECIP_INVALID, n, &irp);
385  if (ss == X400_E_NOERROR) {
386  char buf[1024];
387  size_t retlen;
388  int s;
389 
390  fprintf(stderr, "A recipient with ");
391 
392  s = X400msRecipGetStrParam(irp, X400_S_OR_ADDRESS, buf, 1024, &retlen);
393  if (s == X400_E_NOERROR) {
394  buf[retlen] = '\0';
395  fprintf (stderr, "ORAddress %s ", buf);
396  }
397 
398  s = X400msRecipGetStrParam(irp, X400_S_DIRECTORY_NAME, buf, 1024, &retlen);
399  if (s == X400_E_NOERROR) {
400  buf[retlen] = '\0';
401  fprintf (stderr, " and DN %s", buf);
402  }
403  fprintf (stderr, " was rejected\n");
404  n++;
405  }
406  }
407  }
408 
409  } else {
410  char buf[1024];
411  size_t retlen;
412 
413  printf("Message submitted successfully\n");
414 
415  status = X400msMsgGetStrParam(mp, X400_S_MESSAGE_IDENTIFIER, buf, 1024, &retlen);
416  if (status != X400_E_NOERROR) {
417  fprintf(stderr, "No MessageId present from submission result: error %d\n", status);
418  } else {
419  buf [retlen] = '\0';
420  printf("MessageId from Submission Result = %s\n", buf);
421  }
422 
423  status = X400msMsgGetStrParam(mp, X400_S_MESSAGE_SUBMISSION_TIME, buf, 1024, &retlen);
424  if (status != X400_E_NOERROR) {
425  fprintf(stderr, "No MessageSubmissionTime present from submission result: error %d\n", status);
426  } else {
427  buf [retlen] = '\0';
428  printf("MessageSubmissionTime from Submission Result = %s\n", buf);
429  }
430 
431  status = X400msMsgGetStrParam(mp, X400_S_CONTENT_IDENTIFIER, buf, 1024, &retlen);
432  if (status != X400_E_NOERROR) {
433  fprintf(stderr, "No ContentIdentifier present from submission result: error %d\n", status);
434  } else {
435  buf [retlen] = '\0';
436  printf("ContentIdentifier from Submission Result = %s\n", buf);
437  }
438  }
439 
440  status = X400msMsgDelete (mp, 0);
441  if ( status != X400_E_NOERROR ) {
442  fprintf (stderr, "x400msMsgDelete returned error: %s\n", X400msError (status));
443  exit (status);
444  }
445 
446  mp = NULL;
447  rp = NULL;
448 
449  status = X400msClose (sp);
450  exit (status);
451  /* NOTREACHED */
452 }
453 
454 static int add_binary_attachment (
455  struct X400msMessage *mp,
456  char * filename
457 )
458 {
459  int fd;
460  int file_size;
461  struct stat buf;
462  int fs=0;
463  int status;
464 
465  printf("sending file %s\n", filename);
466  if ((fd = open (filename_to_send, O_RDONLY)) == -1) {
467  printf("Failed to open content file %s", filename);
468  return X400_E_BADPARAM;
469  }
470 
471 
472  if (fstat(fd, &buf) != 0) {
473  close(fd);
474  printf("Can't fstat file %s %d", filename, errno);
475  return X400_E_BADPARAM;
476  }
477 
478  file_size = buf.st_size;
479  printf("Content file size = %d\n", file_size);
480 
481  binary_data = (char *) malloc(file_size);
482  if ( binary_data == NULL )
483  return X400_E_NOMEMORY;
484  if ((fs = read(fd, binary_data, file_size) ) == -1) {
485  printf("Cannot read from binary file %d\n", errno);
486  return (X400_E_SYSERROR);
487  }
488  close(fd);
489 
490  status = X400msMsgAddAttachment (mp, X400_T_BINARY, binary_data, fs);
491  if ( status != X400_E_NOERROR ) {
492  printf("failed to add X400_T_BINARY BP\n");
493  return (status);
494  }
495  return (status);
496 }
497 
498 static int add_fwd_bp (
499  struct X400msMessage *mp,
500  char *orig_orn,
501  char *orig_dn
502 )
503 {
504  struct X400Message *x400_mp;
505  struct X400Recipient *rp;
506  int status;
507  int num_atts = 0;
508 
509  printf("sending fwd bp \n");
510 
511  status = X400MsgNew (X400_MSG_MESSAGE, &x400_mp);
512  if ( status != X400_E_NOERROR ) {
513  fprintf (stderr, "x400MsgNew returned error: %s\n", X400msError (status));
514  exit (status);
515  }
516 
518  "090909090909Z", (size_t)-1);
519  if ( status != X400_E_NOERROR ) {
520  fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
521  exit (status);
522  }
523 
525  "090909090909Z", (size_t)-1);
526  if ( status != X400_E_NOERROR ) {
527  fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
528  exit (status);
529  }
530 
531  /* envelope originator OR address */
532  status = X400MsgAddStrParam (x400_mp, X400_S_OR_ADDRESS, orig_orn, (size_t)-1);
533  if ( status != X400_E_NOERROR ) {
534  fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
535  exit (status);
536  }
537  status = X400MsgAddStrParam (x400_mp, X400_S_DIRECTORY_NAME, orig_dn, (size_t)-1);
538  if ( status != X400_E_NOERROR ) {
539  fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
540  exit (status);
541  }
542 
543  /* add originator into headers */
544  status = X400RecipNew (X400_ORIGINATOR, &rp);
545  if ( status != X400_E_NOERROR ) {
546  fprintf (stderr, "x400RecipNew returned error: %s\n", X400msError (status));
547  exit (status);
548  }
549 
550  /* put in OR Address part of OR Name */
551  status = X400RecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
552  if ( status != X400_E_NOERROR ) {
553  fprintf (stderr, "x400RecipAddStrParam returned error: %s\n", X400msError (status));
554  exit (status);
555  }
556 
557  /* put in DN part of OR Name */
558  status = X400RecipAddStrParam (rp, X400_S_DIRECTORY_NAME, orig_dn, -1);
559  if ( status != X400_E_NOERROR ) {
560  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
561  exit (status);
562  }
563 
564  /* put originator into message */
565  status = X400MsgAddRecip (x400_mp, X400_ORIGINATOR, rp);
566  if ( status != X400_E_NOERROR ) {
567  fprintf (stderr, "X400MsgAddRecip returned error: %s\n", X400msError (status));
568  exit (status);
569  }
570  printf("Put %s in as originator\n", orig_orn);
571 
572  /* add a recipient */
573  status = X400RecipNew (X400_RECIP_STANDARD, &rp);
574  if ( status != X400_E_NOERROR ) {
575  fprintf (stderr, "x400RecipNew returned error: %s\n", X400msError (status));
576  exit (status);
577  }
578 
579  status = X400RecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
580  if ( status != X400_E_NOERROR ) {
581  fprintf (stderr, "x400RecipAddStrParam returned error: %s\n", X400msError (status));
582  exit (status);
583  }
584 
585  status = X400RecipAddStrParam (rp, X400_S_DIRECTORY_NAME, "CN=recipient;c=gb", -1);
586  if ( status != X400_E_NOERROR ) {
587  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
588  exit (status);
589  }
590 
591  status = X400MsgAddRecip (x400_mp, X400_RECIP_STANDARD, rp);
592  if ( status != X400_E_NOERROR ) {
593  fprintf (stderr, "X400MsgAddRecip returned error: %s\n", X400msError (status));
594  exit (status);
595  }
596  printf("Put %s in as reipient\n", recip);
597 
598 
599  /* Add 2nd recipient */
600  status = X400RecipNew (X400_RECIP_STANDARD, &rp);
601  if ( status != X400_E_NOERROR ) {
602  fprintf (stderr, "x400RecipNew returned error: %s\n", X400msError (status));
603  exit (status);
604  }
605 
606  status = X400RecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
607  if ( status != X400_E_NOERROR ) {
608  fprintf (stderr, "x400RecipAddStrParam returned error: %s\n", X400msError (status));
609  exit (status);
610  }
611 
612  status = X400RecipAddStrParam (rp, X400_S_DIRECTORY_NAME, "CN=second recipient;c=gb", -1);
613  if ( status != X400_E_NOERROR ) {
614  fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
615  exit (status);
616  }
617 
618 
619  /* put recipient into message */
620  status = X400MsgAddRecip (x400_mp, X400_RECIP_STANDARD, rp);
621  if ( status != X400_E_NOERROR ) {
622  fprintf (stderr, "X400MsgAddRecip returned error: %s\n", X400msError (status));
623  exit (status);
624  }
625  printf("Put %s in as reipient\n", recip);
626 
627 
628  /* envelope */
629 
630  /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
631  printf("message priority is %d ( 0 - normal, 1 - non-urgent, 2 - urgent)\n",
632  x400_default_priority);
633  status = X400MsgAddIntParam (x400_mp, X400_N_PRIORITY, x400_default_priority);
634  if ( status != X400_E_NOERROR ) return (status);
635 
636  /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
637  printf("military message priority is %d ( 0 - low, 1 - high)\n",
638  x400_default_priority);
639  status = X400MsgAddIntParam (x400_mp, X400_N_MMTS_PRIORITY_QUALIFIER, 1);
640  if ( status != X400_E_NOERROR ) return (status);
641 
642  /* content */
643  /* subject */
644  status = X400MsgAddStrParam (x400_mp, X400_S_SUBJECT, fwd_subject, (size_t)-1);
645  if ( status != X400_E_NOERROR ) {
646  fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
647  exit (status);
648  }
649 
650  /* now an IA5 body part using the bodypart func */
651  status = X400MsgAddAttachment (x400_mp, X400_T_IA5TEXT, text, strlen(text));
652  if ( status != X400_E_NOERROR ) {
653  printf("failed to add X400_T_IA5TEXT BP\n");
654  return (status);
655  }
656  num_atts++;
657 
658  /* 8859-1 attachment */
659  status = X400MsgAddStrParam (x400_mp, X400_T_ISO8859_1, text, (size_t)-1);
660  if ( status != X400_E_NOERROR ) {
661  fprintf (stderr, "x400ms returned error: %s\n", X400msError (status));
662  exit (status);
663  }
664  num_atts++;
665 
666  status = X400MsgAddIntParam (x400_mp, X400_N_NUM_ATTACHMENTS, num_atts);
667  if (status != X400_E_NOERROR )
668  return (status);
669 
670  status = X400msMsgAddMessageBody (mp, x400_mp);
671  if (status != X400_E_NOERROR ) {
672  fprintf (stderr, "X400msMsgAddMessageBody returned error: %s\n", X400msError (status));
673  return (status);
674  }
675 
676  return X400_E_NOERROR;
677 }
678 
679 static void usage(void) {
680  printf("usage: %s\n", optstr);
681  printf("\t where:\n");
682  printf("\t -u : Don't prompt to override defaults \n");
683  printf("\t -3 : Use P3 connection \n");
684  printf("\t -7 : Use P7 connection \n");
685  printf("\t -m : OR Address in P7 bind arg \n");
686  printf("\t -d : DN in P7 bind arg \n");
687  printf("\t -p : Presentation Address of P7 Store \n");
688  printf("\t -w : P7 password of P7 user \n");
689  printf("\t -M : OR Address in P3 bind arg \n");
690  printf("\t -D : DN in P3 bind arg \n");
691  printf("\t -P : Presentation Address of P3 server\n");
692  printf("\t -W : P3 password of P3 user \n");
693  printf("\t -o : Originator \n");
694  printf("\t -O : Originator Return Address \n");
695  printf("\t -r : Recipient\n");
696  printf("\t -l : Logline\n");
697  printf("\t -y : Military Priority \n");
698  printf("\t\t 0 - deferred, 1 - routine, 2 - priority \n");
699  printf("\t\t 3 - immediate, 4 - flash, 5 - override \n");
700  printf("\t -C : Content Type (2/22/772/OID) \n");
701  printf("\t -i : Implicit conversion prohibited = TRUE \n");
702  printf("\t -a : Alternate Recipient Prohibited = TRUE \n");
703  printf("\t -q : Content Return Request = TRUE \n");
704  printf("\t -s : Disclosure of Recipient = FALSE \n");
705  printf("\t -A : Recipient Reassignment Prohibited = FALSE \n");
706  printf("\t -v : Conversion with Loss Prohibited = FALSE \n");
707  printf("\t -f : Filename to transfer as binary bp\n");
708  printf("\t -k : Request Delivery Report\n");
709  printf("\t -K : Request Read Notification ( 1 - RN, 2 - NRN, 4 - return of IPM with NRN )\n");
710  return;
711 }
#define X400_S_DIRECTORY_NAME
Definition: x400_att.h:397
#define X400_MSG_MESSAGE
Definition: x400_att.h:29
#define X400_S_EXTERNAL_CONTENT_TYPE
Definition: x400_att.h:447
#define X400_S_TELETEX_CHARSETS
Definition: x400_att.h:1142
#define X400_E_SYSERROR
Definition: x400_att.h:49
#define X400_S_LOG_CONFIGURATION_FILE
Definition: x400_att.h:1083
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:414
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:1260
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:1135
#define X400_E_RECIPIENT_ERROR
Definition: x400_att.h:157
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:808
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:675
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:439
#define X400_T_IA5TEXT
Definition: x400_att.h:798
#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:305
int X400RecipNew(int type, struct X400Recipient **rpp)
Create a new recipient object.
#define X400_N_NUM_ATTACHMENTS
Definition: x400_att.h:795
#define X400_S_OR_ADDRESS
Definition: x400_att.h:349
#define X400_N_ERROR_DUPLICATE_ATTRIBUTE
Definition: x400_att.h:1274
#define X400_S_MESSAGE_IDENTIFIER
Definition: x400_att.h:405
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:341
#define X400_T_BINARY
Definition: x400_att.h:824
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:1330
#define X400_N_REPORT_REQUEST
Definition: x400_att.h:653
#define X400_RECIP_INVALID
Definition: x400_att.h:338
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:422
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:1267
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:722
#define X400_N_MMTS_PRIORITY_QUALIFIER
Definition: x400_att.h:473
#define X400_N_CONTENT_RETURN_REQUEST
Definition: x400_att.h:436
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:442