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