22 #include "ms_example.h"
24 static void usage(
void);
26 static int fetch_and_print_msg (
struct X400msSession *sp,
29 static char *optstr =
"371um:p:d:w:t:znT:S:h:V:I";
40 struct X400msSession *sp;
46 struct X400msListResult *lr;
53 if (get_args(argc, argv, optstr)) {
58 printf(
"Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
59 contype = ic_fgetc(x400_contype, stdin);
61 ic_fgetc(x400_contype, stdin);
63 if ( contype <
'0' ||
'2' < contype )
64 contype = x400_contype;
69 def_oraddr = x400_ms_user_addr;
70 def_dn = x400_ms_user_dn;
71 def_pa = x400_ms_presentation_address;
73 def_oraddr = x400_mta_user_addr;
74 def_dn = x400_mta_user_dn;
75 def_pa = x400_mta_presentation_address;
78 printf(
"Your ORAddress [%s] > ", def_oraddr);
79 ic_fgets (orn,
sizeof orn, stdin);
81 if ( orn[strlen(orn)-1] ==
'\n' )
82 orn[strlen(orn)-1] =
'\0';
85 strcpy(orn, def_oraddr);
88 printf (
"Password [%s]: ",
89 contype == 0 ? x400_p7_password : x400_p3_password);
90 if ( ic_fgets (buffer,
sizeof buffer, stdin) == NULL )
93 if (buffer[strlen(buffer)-1] ==
'\n' )
94 buffer[strlen(buffer)-1] =
'\0';
95 if (buffer[0] ==
'\0')
96 strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
98 printf(
"Presentation Address [%s] > ", def_pa);
99 ic_fgets (pa,
sizeof pa, stdin);
101 if ( pa[strlen(pa)-1] ==
'\n' )
102 pa[strlen(pa)-1] =
'\0';
108 if (talking_to_marben_ms)
111 status =
X400msOpen (contype, orn, def_dn, buffer, pa, NULL, &sp);
113 fprintf (stderr,
"Error in Open: %s\n",
X400msError (status));
117 if (talking_to_marben_ms)
123 for (i = 0; attrs[i] != NULL; i++) {
133 (submitted_messages == 1) ?
136 (bin_bp_size == 10000) ?
137 (new_messages == 1) ? 0 : -1 :
142 fprintf (stderr,
"X400msList returned status: %s\n",
149 printf(
"\nGot a list result\n");
163 printf(
"\nSequence number = %d\n", seqnum);
176 printf(
"Object type = %s\n", buf);
178 printf(
"No object type present \n");
190 printf(
"Subject = %s\n", buf);
192 printf(
"No subject present \n");
204 printf(
"Sender = %s\n", buf);
206 printf(
"No sender present \n");
217 printf(
"Msg Id = %s\n", buf);
219 printf(
"No Msg Id present \n");
230 printf(
"Subject Id = %s\n", buf);
232 printf(
"No Subject Id present \n");
238 printf(
"Priority = %d\n", n);
240 printf(
"No priority present \n");
247 printf(
"Content length = %d\n", n);
249 printf(
"No content length present \n");
255 printf(
"Content type = %s\n", buf);
257 printf(
"No content type present \n");
265 printf(
"MS entry status = %d, (New message)\n", n);
267 printf(
"MS entry status = %d, (Message listed)\n", n);
269 printf(
"MS entry status = %d, (Message fetched)\n", n);
271 printf(
"MS entry status = %d, (Unknown status)\n", n);
274 printf(
"No entry status present \n");
279 fetch_and_print_msg(sp, seqnum);
287 printf(
"The list result contained %d entries\n", i-1);
293 static int fetch_and_print_msg (
struct X400msSession *sp,
299 struct X400msMessage *mp;
305 printf(
"Getting message\n");
309 fprintf(stderr,
"MsgGet successfully got message; type = %d\n", type);
312 fprintf(stderr,
"Error from MsgGet: %s\n",
X400msError(status));
319 status = print_msg(mp, type);
331 fprintf(stderr,
"Failed to get raw message length: error %d\n", status);
333 struct X400msMessage *newmsg;
336 databuf = buf = (
char *)malloc(retlen);
337 printf(
"Data buffer length required = %d\n", (
int)retlen);
340 fprintf(stderr,
"Failed to get raw message: error %d\n", status);
343 FILE *fd = fopen(
"message.dump",
"w");
345 fprintf(stderr,
"Failed to open file message.dump\n");
347 if (fwrite(databuf, 1, retlen, fd) < retlen) {
348 fprintf(stderr,
"Failed to write message to file message.dump\n");
350 fprintf(stdout,
"Dumped message to file message.dump\n");
359 fprintf(stderr,
"Failed to create message from bytes: error %d\n", status);
362 printf(
"************************** Printing cached message ************************\n");
363 print_msg(newmsg, newtype);
371 printf(
"\n+++ got message - deleting it and returning+++\n");
379 static void usage(
void) {
380 printf(
"usage: %s\n", optstr);
381 printf(
"\t where:\n");
382 printf(
"\t -u : Don't prompt to override defaults \n");
383 printf(
"\t -m : OR Address in P7 bind arg \n");
384 printf(
"\t -p : Presentation Address of P7 Store \n");
385 printf(
"\t -d : DN in P7 bind arg \n");
386 printf(
"\t -w : P7 password of P7 user \n");
387 printf(
"\t -z : List submitted messages\n");
388 printf(
"\t -n : List messages with status 'new' only\n");
389 printf(
"\t -T : List messages with delivery time after <UTCTime>\n");
390 printf(
"\t -V : List messages with delivery time before <UTCTime>\n");
391 printf(
"\t -S : Specify ms-entry-status value for list operation\n");
392 printf(
"\t -h : Specify priority value for list operation\n");
393 printf(
"\t -I : Fetch and delete listed messages\n");
void X400msSetConfigRequest(int val)
Disable and enable configuration requests in MS Bind operations.
#define X400_N_STRICT_P7_1988
#define X400_S_LOG_CONFIGURATION_FILE
#define X400_S_OBJECTTYPE
#define X400_N_MS_ENTRY_STATUS
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 MS_ENTRY_CLASS_STORED_MESSAGES
int X400msSetStrDefault(struct X400msSession *sp, int paramtype, const char *value, size_t length)
Set a default string parameter value in a session.
int X400msListGetIntParam(struct X400msListResult *lr, int paramtype, int number, int *valp)
Get an integer attribute value from an element of a ListResult.
#define X400_E_NO_MORE_RESULTS
int X400msClose(struct X400msSession *sp)
Close a X400 Session.
#define MS_ENTRY_CLASS_SUBMITTED_MESSAGES
void X400msListFree(struct X400msListResult *lr)
Free the memory occupied by a ListResult.
int X400msMsgGet(struct X400msSession *sp, int number, struct X400msMessage **mpp, int *typep, int *seqp)
Get message object for transfer out from MS or MTA via P3.
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
#define X400_S_MESSAGE_IDENTIFIER
#define X400_N_MS_SEQUENCE_NUMBER
int X400msMsgFromRaw(struct X400msSession *sp, char *buffer, size_t buflen, struct X400msMessage **mpp, int *typep)
Reconstruct a message from a binary representation.
#define X400_S_SUBJECT_IDENTIFIER
#define X400_S_EXTERNAL_CONTENT_TYPE
X400 MA/MS (P3/P7) Interface.
int X400msListExAuxPriBefore(struct X400msSession *sp, char *since_time, char *before_time, int entryclass, int entrystatus, int priority, struct X400msListResult **lrp)
List messages in the P7 Message Store, specifying entryclass, entrystatus and priority,...
#define X400_N_CONTENT_LENGTH
int X400msMsgGetRaw(struct X400msSession *sp, struct X400msMessage *mp, char *buffer, size_t buflen, size_t *buflenp)
Get a binary representation of a message which can be subsequently be used to reconstruct the message...
#define X400_MS_ENTRY_STATUS_FETCHED
int X400msSetIntDefault(struct X400msSession *sp, int paramtype, int value)
Set a default integer parameter value in a session.
int X400msListGetStrParam(struct X400msListResult *lr, int paramtype, int number, char *buffer, size_t buflen, size_t *paramlenp)
Get a string attribute value from an element of a ListResult.
#define X400_MS_ENTRY_STATUS_NEW
#define X400_MS_ENTRY_STATUS_LISTED
#define X400_S_OR_ADDRESS
int X400msMsgDelete(struct X400msMessage *mp, int retain)
Delete message object.