24 static char *optstr =
"u37m:d:p:w:M:D:P:W:r:o:O:r:g:G:c:l:R:y:C:iaqsAve:x:b:f:";
27 static char *default_recip =
"/CN=lppt1/OU=lppt/O=attlee/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
30 static char *content_id =
"030924.140212";
31 static const char text[] =
"First line\r\nSecond line\r\n";
32 static char *binary_data;
34 static int setup_msg_sec_env = 1;
38 static void usage(
void) ;
46 static int submit_msg(
48 struct X400msSession *sp
51 static int setup_default_new_sec_env(
52 struct X400msSession *sp,
53 char *identity_filename,
57 static int setup_default_old_sec_env(
58 struct X400msSession *sp,
64 static int setup_msg_new_sec_env(
65 struct X400msMessage *mp,
66 char *identity_filename,
70 static int setup_msg_old_sec_env(
71 struct X400msMessage *mp,
90 char password[BUFSIZ];
93 if (get_args(argc, argv, optstr)) {
98 printf(
"Connection type (0 = P7, 1 = P3) [%d]: ", x400_contype);
99 contype = ic_fgetc(x400_contype, stdin);
101 ic_fgetc(x400_contype, stdin);
103 if ((contype !=
'0') && (contype !=
'1'))
104 contype = x400_contype;
109 def_oraddr = x400_ms_user_addr;
110 def_dn = x400_ms_user_dn;
111 def_pa = x400_ms_presentation_address;
113 def_oraddr = x400_mta_user_addr;
114 def_dn = x400_mta_user_dn;
115 def_pa = x400_mta_presentation_address;
118 printf(
"Your ORAddress [%s] > ", def_oraddr);
119 ic_fgets (orn,
sizeof orn, stdin);
121 if ( orn[strlen(orn)-1] ==
'\n' )
122 orn[strlen(orn)-1] =
'\0';
125 strcpy(orn, def_oraddr);
128 printf (
"Password [%s]: ",
129 contype == 0 ? x400_p7_password : x400_p3_password);
130 if ( ic_fgets (password,
sizeof password, stdin) == NULL )
133 if (password[strlen(password)-1] ==
'\n' )
134 password[strlen(password)-1] =
'\0';
135 if (password[0] ==
'\0')
136 strcpy(password, contype == 0 ? x400_p7_password : x400_p3_password);
139 printf(
"Presentation Address [%s] > ", def_pa);
140 ic_fgets (pa,
sizeof pa, stdin);
142 if ( pa[strlen(pa)-1] ==
'\n' )
143 pa[strlen(pa)-1] =
'\0';
149 if ((status = send_msg(contype, orn, def_dn, pa, password))
151 fprintf (stderr,
"Error in sending message\n");
166 struct X400msSession *sp;
172 status =
X400msOpen (contype, orn, def_dn, password, pa, NULL, &sp);
174 fprintf (stderr,
"Error in Open: %s\n",
X400msError (status));
175 fprintf (stderr,
"%s %s %s\n", orn, def_dn, pa);
194 if (use_new_sec_env) {
195 status = setup_default_new_sec_env(sp, identity_filename, passphrase);
197 status = setup_default_old_sec_env(sp, security_id, identity_dn,
201 fprintf (stderr,
"Can't setup security environment\n");
205 printf(
"sending message 1\n");
206 status = submit_msg(orn, sp);
208 fprintf (stderr,
"Can't submit\n");
214 printf(
"sending message 2\n");
215 status = submit_msg(orn, sp);
217 fprintf (stderr,
"Can't submit\n");
221 printf(
"sending message 3\n");
222 status = submit_msg(orn, sp);
224 fprintf (stderr,
"Can't submit\n");
230 fprintf (stderr,
"X400msClose returned error: %s\n",
X400msError (status));
237 static int submit_msg(
239 struct X400msSession *sp
242 struct X400msMessage *mp;
243 struct X400Recipient *rp;
249 if (x400_default_recipient != NULL)
250 recip = x400_default_recipient;
252 recip = default_recip;
254 printf(
"Message recipient [%s]: ", recip);
255 ic_fgets (tmp,
sizeof tmp, stdin);
257 if ( tmp[strlen(tmp)-1] ==
'\n' )
258 tmp[strlen(tmp)-1] =
'\0';
259 if (strlen(tmp) != 0)
262 printf(
"Subject [%s]: ", subject);
263 ic_fgets (tmp,
sizeof tmp, stdin);
265 if ( tmp[strlen(tmp)-1] ==
'\n' )
266 tmp[strlen(tmp)-1] =
'\0';
267 if (strlen(tmp) != 0)
268 subject = strdup(tmp);
272 fprintf (stderr,
"x400msMsgNew returned error: %s\n",
X400msError (status));
289 if (setup_msg_sec_env) {
290 if (use_new_sec_env) {
291 status = setup_msg_new_sec_env(mp, identity_filename, passphrase);
293 fprintf (stderr,
"Can't setup new security environment\n");
297 status = setup_msg_old_sec_env(mp, security_id, identity_dn2,
300 fprintf (stderr,
"Can't setup old security environment\n");
314 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
320 fprintf (stderr,
"x400msRecipNew returned error: %s\n",
X400msError (status));
326 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
332 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
338 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
344 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
351 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
358 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
365 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
371 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
377 fprintf (stderr,
"x400ms returned error: %s\n",
X400msError (status));
384 printf(
"failed to add X400_T_IA5TEXT BP\n");
389 if (filename_to_send != NULL) {
390 binary_data = (
char *) malloc(100000);
391 if ( binary_data == NULL )
393 fp = fopen(filename_to_send,
"r");
394 if (fp == (FILE *)NULL) {
395 printf(
"Cannot open binary file\n");
398 if ((fs = fread (binary_data,
sizeof(
char), 100000/
sizeof(
char), fp) ) == -1) {
399 printf(
"Cannot read from binary file\n");
406 printf(
"failed to add X400_T_BINARY BP\n");
410 printf(
"no binary file set - not sending X400_T_BINARY\n");
415 fprintf (stderr,
"x400msMsgSend returned error: %s\n",
X400msError (status));
418 printf(
"Message submitted successfully\n");
423 fprintf (stderr,
"x400msMsgDelete returned error: %s\n",
X400msError (status));
433 static int setup_default_new_sec_env(
434 struct X400msSession *sp,
445 fprintf (stderr,
"X400msSetStrDefault returned error: %s\n",
453 fprintf (stderr,
"X400msSetStrDefault returned error: %s\n",
461 fprintf (stderr,
"X400msTestSecurityEnv returned error: %s\n",
469 static int setup_default_old_sec_env(
470 struct X400msSession *sp,
487 fprintf (stderr,
"X400msSetStrDefault returned error: %s\n",
495 fprintf (stderr,
"X400msSetStrDefault returned error: %s\n",
503 static int setup_msg_new_sec_env(
504 struct X400msMessage *mp,
515 fprintf (stderr,
"X400msMsgAddStrParam returned error: %s\n",
523 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
530 static int setup_msg_old_sec_env(
531 struct X400msMessage *mp,
545 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
553 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
561 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
568 static void usage(
void) {
569 printf(
"usage: %s\n", optstr);
570 printf(
"\t where:\n");
571 printf(
"\t -u : Don't prompt to override defaults \n");
572 printf(
"\t -3 : Use P3 connection \n");
573 printf(
"\t -7 : Use P7 connection \n");
574 printf(
"\t -m : OR Address in P7 bind arg \n");
575 printf(
"\t -d : DN in P7 bind arg \n");
576 printf(
"\t -p : Presentation Address of P7 Store \n");
577 printf(
"\t -w : P7 password of P7 user \n");
578 printf(
"\t -M : OR Address in P3 bind arg \n");
579 printf(
"\t -D : DN in P3 bind arg \n");
580 printf(
"\t -P : Presentation Address of P3 server\n");
581 printf(
"\t -W : P3 password of P3 user \n");
582 printf(
"\t -o : Originator \n");
583 printf(
"\t -O : Originator Return Address \n");
584 printf(
"\t -r : Recipient\n");
585 printf(
"\t -l : Logline\n");
586 printf(
"\t -y : Priority (0 - normal, 1 - non-urgent, 2 - urgent \n");
587 printf(
"\t -C : Content Type (2/22/772/OID) \n");
588 printf(
"\t -i : Implicit conversion prohibited = TRUE \n");
589 printf(
"\t -a : Alternate Recipient Prohibited = TRUE \n");
590 printf(
"\t -q : Content Return Request = TRUE \n");
591 printf(
"\t -s : Disclosure of Recipient = FALSE \n");
592 printf(
"\t -A : Recipient Reassignment Prohibited = FALSE \n");
593 printf(
"\t -v : Conversion with Loss Prohibited = FALSE \n");
594 printf(
"\t -e : Security Environment (dir with x509 subdir): obsolete, use -Y <p12file>\n");
595 printf(
"\t -x : DN of X.509 Digital Identity\n");
596 printf(
"\t -b : Passphrase for private key in PKCS12 file\n");
597 printf(
"\t -f : Filename to transfer as binary bp\n");
598 printf(
"\t -Y : Filename of PKCS12 file containing Digital Identity\n");
#define X400_S_LOG_CONFIGURATION_FILE
int X400msMsgSend(struct X400msMessage *mp)
Send message object.
int X400msMsgAddAttachment(struct X400msMessage *mp, int type, const char *string, size_t length)
Add attachment to the message.
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_S_SEC_IDENTITY
int X400msSetStrDefault(struct X400msSession *sp, int paramtype, const char *value, size_t length)
Set a default string parameter value in a session.
int X400msClose(struct X400msSession *sp)
Close a X400 Session.
int X400msMsgAddIntParam(struct X400msMessage *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.
int X400msRecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
#define X400_S_DIRECTORY_NAME
int X400msRecipNew(struct X400msMessage *mp, int type, struct X400Recipient **rpp)
Add new recipient to a message.
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
#define X400_S_SEC_IDENTITY_DN
#define X400_RECIP_STANDARD
int X400msMsgNew(struct X400msSession *sp, int type, struct X400msMessage **mpp)
Creates new message.
#define X400_S_CONTENT_IDENTIFIER
#define X400_S_SEC_IDENTITY_PASSPHRASE
#define X400_N_REPORT_REQUEST
X400 MA/MS (P3/P7) Interface.
#define X400_S_SEC_IDENTITY_FILE
#define X400_N_NOTIFICATION_REQUEST
int X400msTestSecurityEnv(struct X400msSession *sp)
Test the default Security Environment.
int X400msMsgAddStrParam(struct X400msMessage *mp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
#define X400_B_SEC_GEN_MOAC
#define X400_S_OR_ADDRESS
int X400msMsgDelete(struct X400msMessage *mp, int retain)
Delete message object.