x400_mssend.c

00001 /*  Copyright (c) 2003-2007, Isode Limited, London, England.
00002  *  All rights reserved.
00003  *                                                                       
00004  *  Acquisition and use of this software and related materials for any      
00005  *  purpose requires a written licence agreement from Isode Limited,
00006  *  or a written licence from an organisation licenced by Isode Limited
00007  *  to grant such a licence.
00008  *
00009  */
00010 
00011 /* $RCSfile: x400_mssend.c,v $ $Revision: 1.38 $ $Date: 2007/09/25 14:16:13 $ $State: Exp $
00012  *
00013  * $Log: x400_mssend.c,v $
00014  * Revision 1.38  2007/09/25 14:16:13  paga
00015  * T070925E - #define out dl expansion history and security label code.
00016  *
00017  * Revision 1.37  2007/09/04 11:57:10  paga
00018  * T070904F - Remove confusing dl exp history code block
00019  *
00020  * Revision 1.36  2007/08/31 12:52:56  ir
00021  * T070831G - Correctly send all of file as binary attachment.
00022  *            Add add_fwd_bp() to construct a message to be forwared as a message body
00023  *            part.
00024  *
00025  * Revision 1.35  2007/08/29 15:35:49  paga
00026  * T070829J - Add in security label examples.
00027  *
00028  * Revision 1.34  2007/08/28 15:29:54  paga
00029  * T070828E - Add DL Expansion list to submitted message.
00030  *
00031  * Revision 1.33  2007/08/21 16:38:33  ldv
00032  * T070821K - Correct typo in Usage message, for the -7 flag
00033  *
00034  * Revision 1.32  2007/07/17 08:46:38  dbw
00035  * T070716H - Fix warnings
00036  *
00037  * Revision 1.31  2007/07/11 11:02:44  kurt
00038  * T070615E - Remove unused variable
00039  *
00040  * Revision 1.30  2007/05/15 13:11:07  dbw
00041  * T070515D - Update/Add copyright
00042  *
00043  * Revision 1.29  2007/05/09 15:57:08  ir
00044  * T070509P - Add call to set X400_N_CONTENT_RETURN_REQUEST to false.
00045  *            Add call to set priority and military priority.
00046  *            Correctly get all of large binary file as binary attachment.
00047  *
00048  * Revision 1.28  2007/04/27 14:50:30  dbw
00049  * T070427F - Three possible connection types
00050  *
00051  * Revision 1.27  2007/04/05 12:45:58  brs
00052  * T070405A - Fix some warnings.
00053  *
00054  * Revision 1.26  2006/09/11 09:43:28  ir
00055  * T060825A - Add switch which accepts defaults (as overridden on the command line)
00056  *            stopping the prompts so that the programs can be run unattended.
00057  *
00058  * Revision 1.25  2006/07/28 09:05:18  ir
00059  * T060728A - Add -u switch to example progs to accept cmd line args without
00060  *            prompting.
00061  *
00062  * Revision 1.24  2006/01/17 15:54:03  ir
00063  * T060117E - Make filename to attach configurable.
00064  *
00065  * Revision 1.23  2006/01/17 13:56:37  ir
00066  * T060117B - Remove signing code into x400_mssend_sign.c
00067  *
00068  * Revision 1.22  2005/12/21 14:53:11  ir
00069  * T051219B - Add in calls to sign messages
00070  *
00071  * Revision 1.21  2005/12/14 11:24:33  tc
00072  * T051214C - Add directory names to message recipients.
00073  *
00074  * Revision 1.20  2005/11/25 11:50:41  ldv
00075  * T051125A - Correct the meaning of the -W flag in the usage message
00076  *
00077  * Revision 1.19  2005/11/03 11:55:04  tc
00078  * T051103A - Delete unnecessary Doxygen text.
00079  *
00080  * Revision 1.18  2005/10/17 15:59:33  ir
00081  * T051017D - Open binary file using argv[0].
00082  *
00083  * Revision 1.17  2005/10/12 10:43:00  ir
00084  * T051012A - Remove unused variable.
00085  *            Include <stdlib.h> for exit() prototype.
00086  *
00087  * Revision 1.16  2005/10/10 07:57:13  ir
00088  * T051007C - Call get_args() to parse cmdline args.
00089  *
00090  * Revision 1.15  2005/09/23 12:30:14  ldv
00091  * T050922E - Set up logging from the file x400api.xml
00092  *
00093  * Revision 1.14  2005/09/08 16:02:28  ldv
00094  * T050908G - Show how to create a text and binary bodyparts
00095  *
00096  * Revision 1.13  2005/05/25 16:23:35  dbw
00097  * T050525C - Files updated in 2004
00098  *
00099  * Revision 1.12  2004/07/09 09:20:26  ldv
00100  * T040708C - Request Read Receipts (IPNs)
00101  *
00102  * Revision 1.11  2004/06/30 09:31:16  ldv
00103  * T040625G - Improve the examples to use the new API functionality
00104  *
00105  * Revision 1.10  2004/05/27 12:01:41  dbw
00106  * T040527A - user_name becomes user_addr and user_dn
00107  *            Change in X400msOpen argument.
00108  *
00109  * Revision 1.9  2004/05/11 10:24:00  tc
00110  * T040511B - Set the X400_N_REPORT_REQUEST attribute in each recipient when building
00111  *            a message for submission.
00112  *
00113  * Revision 1.8  2004/05/06 09:26:34  tc
00114  * T040505C - Replace use of X400Message with X400msMessage.
00115  *            Call common 'do_tailoring' function to get data from x400tailor file.
00116  *            Rearrange data input code.
00117  *            Call common 'set_defaults' routine.
00118  *
00119  * Revision 1.7  2004/02/19 15:09:16  tc
00120  * T040219A - Update X400msOpen call to include user orname parameter. Add code
00121  *            to read user orname from stdin. Improve output messages. Report
00122  *            error codes returned from API functions. Allow default message
00123  *            recipient oraddress to be overridden with stdin.
00124  *
00125  * Revision 1.6  2004/01/08 15:27:14  tc
00126  * T040108A - Correct call to exit().
00127  *
00128  * Revision 1.5  2003/10/20 09:14:50  tc-local
00129  * T031017B - Rename amhs->x400 throughout.
00130  *
00131  * Revision 1.4  2003/09/26 13:31:16  tc-local
00132  * T030925E - Add code to allow choice of P7 or P3 connection and option of specifying
00133  *            presentation address.
00134  *
00135  * Revision 1.3  2003/09/11 11:01:18  ir
00136  * T030911A - Use AMHSMessage and AMHSRecipient over AMHS API.
00137  *
00138  * Revision 1.2  2003/09/10 15:59:17  tc-local
00139  * T030910C - Change AMHSmsRecipient to AMHSRecipient.
00140  *
00141  * Revision 1.1  2003/08/27 15:22:03  ir
00142  * T030819A - Initial checkin of AMHS module.
00143  *
00144  *
00145  * Simple example program for submitting a message via a message store.
00146  */
00147 
00148 #include <stdio.h>
00149 #include <stdlib.h>
00150 #include <string.h>
00151 #include <sys/stat.h>
00152 #include <sys/types.h>
00153 #ifndef _WIN32
00154 #include <unistd.h>
00155 #endif
00156 #include <fcntl.h>
00157 #include <errno.h>
00158 
00159 #include <x400_msapi.h>
00160 #include <seclabel_api.h> /* For security labels */
00161 #include "example.h"
00162 
00163 
00164 static char *optstr = "u371m:d:p:w:M:D:P:W:r:o:O:r:g:G:c:l:R:y:C:iaqsAvf:";
00165 
00166 /* These are the data items used to construct the message for submission */
00167 static char *default_recip = "/CN=P7User1/O=attlee/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
00168 char *recip;
00169 static char *subject = "A Test Message from X.400 C API";
00170 static const char text[] = "First line\r\nSecond line\r\n";
00171 static char *binary_data;
00172 
00173 static char *fwd_subject = "Forwarded message subject";
00174 
00175 static int add_binary_attachment (
00176     struct X400msMessage *mp,
00177     char * filename_to_send
00178 );
00179 static int add_fwd_bp (
00180     struct X400msMessage        *mp,
00181     char                        *recip_orn,
00182     char                        *recip_dn
00183 ) ;
00184 static void usage(void) ;
00185 
00186 
00187 int main (
00188     int         argc,
00189     char      **argv
00190 ) 
00191 {
00192     char buffer[BUFSIZ];
00193     char pa[BUFSIZ];
00194     char orn[BUFSIZ];
00195     char tmp[BUFSIZ];
00196     int status;
00197     int nummsg;
00198     struct X400msSession *sp;
00199     struct X400msMessage *mp;
00200     struct X400Recipient *rp;
00201     int contype;
00202     char *def_oraddr;
00203     char *def_dn;
00204     char *def_pa;
00205 
00206     if (get_args(argc, argv, optstr)) {
00207         usage();
00208         exit(-1);
00209     }
00210 
00211     printf("Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
00212     contype = ic_fgetc(x400_contype, stdin); 
00213     if (contype != 10)
00214         ic_fgetc(x400_contype, stdin);
00215 
00216     if ( contype < '0' || '2' < contype )
00217       contype = x400_contype;
00218     else 
00219         contype -= '0';
00220 
00221     if (contype == 0) {
00222         def_oraddr = x400_ms_user_addr;
00223         def_dn = x400_ms_user_dn;
00224         def_pa = x400_ms_presentation_address;
00225     } else {
00226         def_oraddr = x400_mta_user_addr;
00227         def_dn = x400_mta_user_dn;
00228         def_pa = x400_mta_presentation_address;
00229     }
00230 
00231     printf("Your ORAddress [%s] > ", def_oraddr);
00232     ic_fgets (orn, sizeof orn, stdin);
00233 
00234     if ( orn[strlen(orn)-1] == '\n' )
00235         orn[strlen(orn)-1] = '\0';
00236         
00237     if (orn[0] == '\0') 
00238         strcpy(orn, def_oraddr);
00239 
00240     /* Prompt for password; note: reflected. */
00241     printf ("Password [%s]: ", 
00242             contype == 0 ? x400_p7_password : x400_p3_password);
00243     if ( ic_fgets (buffer, sizeof buffer, stdin) == NULL )
00244         exit (1);
00245 
00246     if (buffer[strlen(buffer)-1] == '\n' )
00247         buffer[strlen(buffer)-1] = '\0';
00248     if (buffer[0] == '\0') 
00249         strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
00250 
00251     /* Presentation Address */
00252     printf("Presentation Address [%s] > ", def_pa);
00253     ic_fgets (pa, sizeof pa, stdin);
00254 
00255     if ( pa[strlen(pa)-1] == '\n' )
00256         pa[strlen(pa)-1] = '\0';
00257 
00258     if (pa[0] == '\0') 
00259         strcpy(pa, def_pa);
00260 
00261     if (talking_to_marben_ms)
00262         X400msSetConfigRequest(0);
00263 
00264     /* we've got what we need - now open an API session */
00265     status = X400msOpen (contype, orn, def_dn, buffer, pa, &nummsg, &sp);
00266     if ( status != X400_E_NOERROR ) {
00267         fprintf (stderr, "Error in Open: %s\n", X400msError (status));
00268         exit (status);
00269     }
00270 
00271     if (talking_to_marben_ms)
00272         X400msSetIntDefault(sp, X400_N_STRICT_P7_1988, 1);
00273 
00274     /* setup logging */
00275     X400msSetStrDefault(sp, X400_S_LOG_CONFIGURATION_FILE, "x400api.xml", 0);
00276 
00277     if (x400_default_recipient != NULL) 
00278         recip = x400_default_recipient;
00279     else 
00280         recip = default_recip;
00281 
00282     printf("Message recipient [%s]: ", recip);
00283     ic_fgets (tmp, sizeof tmp, stdin);
00284 
00285     if ( tmp[strlen(tmp)-1] == '\n' )
00286         tmp[strlen(tmp)-1] = '\0';
00287     if (strlen(tmp) != 0)
00288         recip = strdup(tmp);
00289 
00290     printf("Subject [%s]: ", subject);
00291     ic_fgets (tmp, sizeof tmp, stdin);
00292 
00293     if ( tmp[strlen(tmp)-1] == '\n' )
00294         tmp[strlen(tmp)-1] = '\0';
00295     if (strlen(tmp) != 0)
00296         subject = strdup(tmp);
00297 
00298     status = X400msMsgNew (sp, X400_MSG_MESSAGE, &mp);
00299     if ( status != X400_E_NOERROR ) {
00300         fprintf (stderr, "x400msMsgNew returned error: %s\n", X400msError (status));
00301         exit (status);
00302     }
00303 
00304     status = X400msRecipNew (mp, X400_RECIP_STANDARD, &rp);
00305     if ( status != X400_E_NOERROR ) {
00306         fprintf (stderr, "x400msRecipNew returned error: %s\n", X400msError (status));
00307         exit (status);
00308     }
00309 
00310     status = X400msRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
00311     if ( status != X400_E_NOERROR ) {
00312         fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
00313         exit (status);
00314     }
00315 
00316     status = X400msRecipAddStrParam (rp, X400_S_DIRECTORY_NAME, "CN=recipient;c=gb", -1);
00317     if ( status != X400_E_NOERROR ) {
00318         fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
00319         exit (status);
00320     }
00321 
00322     status = X400msMsgAddStrParam (mp, X400_S_OR_ADDRESS, orn, -1);
00323     if ( status != X400_E_NOERROR ) {
00324         fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
00325         exit (status);
00326     }
00327  
00328     status = X400msMsgAddStrParam (mp, X400_S_DIRECTORY_NAME, "CN=originator;c=gb", -1);
00329     if ( status != X400_E_NOERROR ) {
00330         fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
00331         exit (status);
00332     }
00333 
00334     /* Ask for +ve and -ve delivery reports : 2 */
00335     status = X400msRecipAddIntParam (rp, X400_N_REPORT_REQUEST, 1);
00336     if ( status != X400_E_NOERROR ) {
00337         fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
00338         exit (status);
00339     }
00340 
00341     /* Ask for +ve and -ve read receipts : 7*/
00342     status = X400msRecipAddIntParam (rp, X400_N_NOTIFICATION_REQUEST, 2);
00343     if ( status != X400_E_NOERROR ) {
00344         fprintf (stderr, "x400msRecipAddIntParam returned error: %s\n", X400msError (status));
00345         exit (status);
00346     }
00347 
00348     /* content return request on report - 0 = no */
00349     status = X400msMsgAddIntParam (mp, X400_N_CONTENT_RETURN_REQUEST, 0);
00350     if ( status != X400_E_NOERROR ) {
00351         fprintf (stderr, "X400msMsgAddIntParam %d returned error: %s\n", 
00352             X400_N_CONTENT_RETURN_REQUEST, X400msError (status));
00353         exit (status);
00354     }
00355 
00356     /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
00357     printf("message priority is %d ( 0 - normal, 1 - non-urgent, 2 - urgent)\n", 
00358             x400_default_priority);
00359     status = X400msMsgAddIntParam (mp, X400_N_PRIORITY, x400_default_priority);
00360     if ( status != X400_E_NOERROR ) return (status);
00361 
00362     /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
00363     printf("military message priority is %d ( 0 - low, 1 - high)\n", 
00364             x400_default_priority);
00365     status = X400msMsgAddIntParam (mp, X400_N_MMTS_PRIORITY_QUALIFIER, 1);
00366     if ( status != X400_E_NOERROR ) return (status);
00367 
00368     /* subject */
00369     status = X400msMsgAddStrParam (mp, X400_S_SUBJECT, subject, -1);
00370     if ( status != X400_E_NOERROR ) {
00371         fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
00372         exit (status);
00373     }
00374 
00375     /* 8859-1 attachment */
00376     status = X400msMsgAddStrParam (mp, X400_T_ISO8859_1, text, -1);
00377     if ( status != X400_E_NOERROR ) {
00378         fprintf (stderr, "x400ms returned error: %s\n", X400msError (status));
00379         exit (status);
00380     }
00381 
00382     /* now an IA5 body part using the bodypart func  */
00383     status = X400msMsgAddAttachment (mp, X400_T_IA5TEXT, text, strlen(text));
00384     if ( status != X400_E_NOERROR ) {
00385         printf("failed to add X400_T_IA5TEXT BP\n");
00386         return (status);
00387     }
00388 
00389         
00390     /*  or a Binary body part using the bodypart func */
00391     if (filename_to_send != NULL) {
00392         status = add_binary_attachment (mp, filename_to_send); 
00393         if ( status != X400_E_NOERROR ) {
00394             printf("failed to add X400_T_BINARY BP\n");
00395             return (status);
00396         }
00397         status = add_fwd_bp (mp, orn, def_dn); 
00398         if ( status != X400_E_NOERROR ) {
00399             printf("failed to add forwarded BP\n");
00400             return (status);
00401         }
00402     } else {
00403         printf("no binary file set - not sending X400_T_BINARY\n");
00404         printf("no binary file set - not sending forwarded BP\n");
00405     }
00406 
00407 
00408 #ifdef USE_SEC_LABEL
00409     {
00410 #define XML_BUFSIZE 1024
00411 #define STRING_BUFSIZE 1024
00412         
00413         const char* xml_filename = "seclabel.xml";
00414         char xml_content[XML_BUFSIZE];
00415         char str_content[STRING_BUFSIZE];
00416         int str_len = STRING_BUFSIZE;
00417         FILE *fd = NULL;
00418         
00419         /* Read in the security label XML file */
00420         fd = fopen(xml_filename,"r");
00421         if(fd == NULL) {
00422             fprintf(stderr,"Failed to open %s : %s\n",
00423                     xml_filename,strerror(errno));
00424         }
00425         
00426         fread(&xml_content,XML_BUFSIZE,1,fd);
00427 
00428         fclose(fd);
00429 
00430         status = SecLabelInit("Example program");
00431         if (status != SECLABEL_E_NOERROR) {
00432             fprintf(stderr, "SecLabelInit returned error %d\n", status);
00433             exit(1);
00434         }
00435         
00436         /* Use SecLabelParse to turn the XML into an octect string */
00437         status = SecLabelParse(xml_content,
00438                                str_content,
00439                                STRING_BUFSIZE,
00440                                &str_len);
00441         
00442         if (status != SECLABEL_E_NOERROR) {
00443             fprintf(stderr, "SecLabelParse returned error %d\n", status);
00444             exit(1);
00445         }
00446             
00447         /* Add the octect string to the message pointer */
00448         status = X400msMsgAddStrParam (mp, X400_S_SECURITY_LABEL,
00449                                        str_content,str_len);
00450         if ( status != X400_E_NOERROR ) {
00451             fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
00452             exit (status);
00453         }
00454         
00455     }
00456 #endif
00457     
00458     status = X400msMsgSend (mp);
00459     if ( status != X400_E_NOERROR ) {
00460         fprintf (stderr, "x400msMsgSend returned error: %s\n", X400msError (status));
00461         exit (status);
00462     } else {
00463         printf("Message submitted successfully\n");
00464     }
00465 
00466     status = X400msMsgDelete (mp, 0);
00467     if ( status != X400_E_NOERROR ) {
00468         fprintf (stderr, "x400msMsgDelete returned error: %s\n", X400msError (status));
00469         exit (status);
00470     }
00471 
00472     mp = NULL;
00473     rp = NULL;
00474 
00475     status = X400msClose (sp);
00476     exit (status);
00477     /* NOTREACHED */
00478 }
00479 
00480 static int add_binary_attachment (
00481     struct X400msMessage *mp,
00482     char * filename_to_send
00483 ) 
00484 {
00485     int         fd;
00486     int         file_size;
00487     struct stat buf;
00488     int         fs=0;
00489     int         status;
00490 
00491     printf("sending file %s\n", filename_to_send);
00492     if ((fd = open (filename_to_send, O_RDONLY)) == -1) {
00493         printf("Failed to open content file %s", filename_to_send);
00494         return X400_E_BADPARAM;
00495     }
00496 
00497 
00498     if (fstat(fd, &buf) != 0) {
00499             close(fd);
00500             printf("Can't fstat file %s %d",  filename_to_send, errno);
00501             return X400_E_BADPARAM;
00502     }
00503 
00504     file_size = buf.st_size;
00505     printf("Content file size = %d\n", file_size);
00506 
00507     binary_data = (char *) malloc(file_size);
00508     if ( binary_data == NULL )
00509         return X400_E_NOMEMORY;
00510     if ((fs = read(fd, binary_data, file_size) ) == -1) {
00511         printf("Cannot read from binary file %d\n", errno);
00512         return (X400_E_SYSERROR);
00513     }
00514     close(fd);
00515 
00516     status = X400msMsgAddAttachment (mp, X400_T_BINARY, binary_data, fs);
00517     if ( status != X400_E_NOERROR ) {
00518         printf("failed to add X400_T_BINARY BP\n");
00519         return (status);
00520     }
00521     return (status);
00522 }
00523 
00524 static int add_fwd_bp (
00525     struct X400msMessage        *mp,
00526     char                        *orig_orn,
00527     char                        *orig_dn
00528 ) 
00529 {
00530     struct X400Message          *x400_mp;
00531     struct X400Recipient        *rp;
00532     int                         status;
00533     int                         num_atts = 0;
00534 
00535     printf("sending fwd bp \n");
00536 
00537     status = X400MsgNew (X400_MSG_MESSAGE, &x400_mp);
00538     if ( status != X400_E_NOERROR ) {
00539         fprintf (stderr, "x400MsgNew returned error: %s\n", X400msError (status));
00540         exit (status);
00541     }
00542 
00543     /* envelope originator OR address */
00544     status = X400MsgAddStrParam (x400_mp, X400_S_OR_ADDRESS, orig_orn, -1);
00545     if ( status != X400_E_NOERROR ) {
00546         fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
00547         exit (status);
00548     }
00549     status = X400MsgAddStrParam (x400_mp, X400_S_DIRECTORY_NAME, orig_dn, -1);
00550     if ( status != X400_E_NOERROR ) {
00551         fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
00552         exit (status);
00553     }
00554 
00555     /* add originator into headers */
00556     status = X400RecipNew (X400_ORIGINATOR, &rp);
00557     if ( status != X400_E_NOERROR ) {
00558         fprintf (stderr, "x400RecipNew returned error: %s\n", X400msError (status));
00559         exit (status);
00560     }
00561 
00562     /* put in OR Address part of OR Name */
00563     status = X400RecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
00564     if ( status != X400_E_NOERROR ) {
00565         fprintf (stderr, "x400RecipAddStrParam returned error: %s\n", X400msError (status));
00566         exit (status);
00567     }
00568 
00569     /* put in DN part of OR Name */
00570     status = X400RecipAddStrParam (rp, X400_S_DIRECTORY_NAME, orig_dn, -1);
00571     if ( status != X400_E_NOERROR ) {
00572         fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
00573         exit (status);
00574     }
00575 
00576     /* put originator into message */
00577     status = X400MsgAddRecip (x400_mp, X400_ORIGINATOR, rp);
00578     if ( status != X400_E_NOERROR ) {
00579         fprintf (stderr, "X400MsgAddRecip returned error: %s\n", X400msError (status));
00580         exit (status);
00581     }
00582     printf("Put %s in as originator\n", orig_orn);
00583 
00584     /* add a recipient */
00585     status = X400RecipNew (X400_RECIP_STANDARD, &rp);
00586     if ( status != X400_E_NOERROR ) {
00587         fprintf (stderr, "x400RecipNew returned error: %s\n", X400msError (status));
00588         exit (status);
00589     }
00590 
00591     status = X400RecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
00592     if ( status != X400_E_NOERROR ) {
00593         fprintf (stderr, "x400RecipAddStrParam returned error: %s\n", X400msError (status));
00594         exit (status);
00595     }
00596 
00597     status = X400RecipAddStrParam (rp, X400_S_DIRECTORY_NAME, "CN=recipient;c=gb", -1);
00598     if ( status != X400_E_NOERROR ) {
00599         fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
00600         exit (status);
00601     }
00602 
00603 
00604     /* put recipient into message */
00605     status = X400MsgAddRecip (x400_mp, X400_RECIP_STANDARD, rp);
00606     if ( status != X400_E_NOERROR ) {
00607         fprintf (stderr, "X400MsgAddRecip returned error: %s\n", X400msError (status));
00608         exit (status);
00609     }
00610     printf("Put %s in as reipient\n", recip);
00611 
00612     /* envelope */
00613 
00614     /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
00615     printf("message priority is %d ( 0 - normal, 1 - non-urgent, 2 - urgent)\n", 
00616             x400_default_priority);
00617     status = X400MsgAddIntParam (x400_mp, X400_N_PRIORITY, x400_default_priority);
00618     if ( status != X400_E_NOERROR ) return (status);
00619 
00620     /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
00621     printf("military message priority is %d ( 0 - low, 1 - high)\n", 
00622             x400_default_priority);
00623     status = X400MsgAddIntParam (x400_mp, X400_N_MMTS_PRIORITY_QUALIFIER, 1);
00624     if ( status != X400_E_NOERROR ) return (status);
00625 
00626     /* content */
00627     /* subject */
00628     status = X400MsgAddStrParam (x400_mp, X400_S_SUBJECT, fwd_subject, -1);
00629     if ( status != X400_E_NOERROR ) {
00630         fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
00631         exit (status);
00632     }
00633 
00634     /* now an IA5 body part using the bodypart func  */
00635     status = X400MsgAddAttachment (x400_mp, X400_T_IA5TEXT, text, strlen(text));
00636     if ( status != X400_E_NOERROR ) {
00637         printf("failed to add X400_T_IA5TEXT BP\n");
00638         return (status);
00639     }
00640     num_atts++;
00641 
00642     /* 8859-1 attachment */
00643     status = X400MsgAddStrParam (x400_mp, X400_T_ISO8859_1, text, -1);
00644     if ( status != X400_E_NOERROR ) {
00645         fprintf (stderr, "x400ms returned error: %s\n", X400msError (status));
00646         exit (status);
00647     }
00648     num_atts++;
00649 
00650     status = X400MsgAddIntParam (x400_mp, X400_N_NUM_ATTACHMENTS, num_atts);
00651     if (status != X400_E_NOERROR ) 
00652         return (status);
00653 
00654     status = X400msMsgAddMessageBody (mp, x400_mp);
00655     if (status != X400_E_NOERROR ) {
00656         fprintf (stderr, "X400msMsgAddMessageBody returned error: %s\n", X400msError (status));
00657         return (status);
00658     }
00659 
00660     return X400_E_NOERROR;
00661 }
00662 
00663 static void usage(void) {
00664     printf("usage: %s\n", optstr);
00665     printf("\t where:\n");
00666     printf("\t -u : Don't prompt to override defaults \n");
00667     printf("\t -3 : Use P3 connection \n");
00668     printf("\t -7 : Use P7 connection \n");
00669     printf("\t -m : OR Address in P7 bind arg \n");
00670     printf("\t -d : DN in P7 bind arg \n");
00671     printf("\t -p : Presentation Address of P7 Store \n");
00672     printf("\t -w : P7 password of P7 user \n");
00673     printf("\t -M : OR Address in P3 bind arg \n");
00674     printf("\t -D : DN in P3 bind arg \n");
00675     printf("\t -P : Presentation Address of P3 server\n");
00676     printf("\t -W : P3 password of P3 user \n");
00677     printf("\t -o : Originator \n");
00678     printf("\t -O : Originator Return Address \n");
00679     printf("\t -r : Recipient\n");
00680     printf("\t -l : Logline\n");
00681     printf("\t -y : Priority (0 - normal, 1 - non-urgent, 2 - urgent \n");
00682     printf("\t -C : Content Type (2/22/772/OID) \n");
00683     printf("\t -i : Implicit conversion prohibited = TRUE \n");
00684     printf("\t -a : Alternate Recipient Prohibited = TRUE \n");
00685     printf("\t -q : Content Return Request = TRUE \n");
00686     printf("\t -s : Disclosure of Recipient = FALSE \n");
00687     printf("\t -A : Recipient Reassignment Prohibited = FALSE \n");
00688     printf("\t -v : Conversion with Loss Prohibited = FALSE \n");
00689     printf("\t -f : Filename to transfer as binary bp\n");
00690     return;
00691 }
00692 
00693 
Copyright © 2008 Isode privacy   feedback Subscribe to our rss newsfeed