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_mslist.c
1 /* Copyright (c) 2005-2010, Isode Limited, London, England.
2  * All rights reserved.
3  *
4  * Acquisition and use of this software and related materials for any
5  * purpose requires a written licence agreement from Isode Limited,
6  * or a written licence from an organisation licenced by Isode Limited
7  * to grant such a licence.
8  *
9  */
10 
11 /*
12  *
13  * @VERSION@
14  * Simple example program for listing the contents of an X.400 Message Store mailbox.
15  */
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 
20 #include <x400_msapi.h>
21 #include "example.h"
22 
23 static void usage(void);
24 
25 static char *optstr = "371um:p:d:w:t:znT:S:h:V:";
26 
27 int main (
28  int argc,
29  char **argv
30 )
31 {
32  char buffer[BUFSIZ];
33  char pa[BUFSIZ];
34  char orn[BUFSIZ];
35  int status;
36  struct X400msSession *sp;
37  int contype;
38  char *def_oraddr;
39  char *def_dn;
40  char *def_pa;
41  int i;
42  struct X400msListResult *lr;
43 
44  if (get_args(argc, argv, optstr)) {
45  usage();
46  exit(-1);
47  }
48 
49  printf("Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
50  contype = ic_fgetc(x400_contype, stdin);
51  if (contype != 10)
52  ic_fgetc(x400_contype, stdin);
53 
54  if ( contype < '0' || '2' < contype )
55  contype = x400_contype;
56  else
57  contype -= '0';
58 
59  if (contype == 0) {
60  def_oraddr = x400_ms_user_addr;
61  def_dn = x400_ms_user_dn;
62  def_pa = x400_ms_presentation_address;
63  } else {
64  def_oraddr = x400_mta_user_addr;
65  def_dn = x400_mta_user_dn;
66  def_pa = x400_mta_presentation_address;
67  }
68 
69  printf("Your ORAddress [%s] > ", def_oraddr);
70  ic_fgets (orn, sizeof orn, stdin);
71 
72  if ( orn[strlen(orn)-1] == '\n' )
73  orn[strlen(orn)-1] = '\0';
74 
75  if (orn[0] == '\0')
76  strcpy(orn, def_oraddr);
77 
78  /* Prompt for password; note: reflected. */
79  printf ("Password [%s]: ",
80  contype == 0 ? x400_p7_password : x400_p3_password);
81  if ( ic_fgets (buffer, sizeof buffer, stdin) == NULL )
82  exit (1);
83 
84  if (buffer[strlen(buffer)-1] == '\n' )
85  buffer[strlen(buffer)-1] = '\0';
86  if (buffer[0] == '\0')
87  strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
88 
89  printf("Presentation Address [%s] > ", def_pa);
90  ic_fgets (pa, sizeof pa, stdin);
91 
92  if ( pa[strlen(pa)-1] == '\n' )
93  pa[strlen(pa)-1] = '\0';
94 
95  if (pa[0] == '\0')
96  strcpy(pa, def_pa);
97 
98 
99  if (talking_to_marben_ms)
101 
102  status = X400msOpen (contype, orn, def_dn, buffer, pa, NULL, &sp);
103  if ( status != X400_E_NOERROR ) {
104  fprintf (stderr, "Error in Open: %s\n", X400msError (status));
105  exit (status);
106  }
107 
108  if (talking_to_marben_ms)
110 
111  /* setup logging from $(ETCDIR)x400api.xml or $(SHAREDIR)x400api.xml */
112  X400msSetStrDefault(sp, X400_S_LOG_CONFIGURATION_FILE, "x400api.xml", -1);
113 
114  for (i = 0; attrs[i] != NULL; i++) {
115  X400msSetStrDefault(sp, X400_S_LIST_ATTR + i, attrs[i], -1);
116  }
117 
118  /* Now list messages, since we have a P7 connection */
119 
120  /* List messages since a specific time and date - 20/01/2005, 12:05:06
121  in this case. Specify NULL string instead to list all of them */
122 
123  status = X400msListExAuxPriBefore(sp, since_time, until_time,
124  (submitted_messages == 1) ?
127  (bin_bp_size == 10000) ?
128  (new_messages == 1) ? 0 : -1 :
129  bin_bp_size,
130  priority,
131  &lr);
132  if (status != X400_E_NOERROR) {
133  fprintf (stderr, "X400msList returned status: %s\n",
134  X400msError (status));
135  exit(1);
136  }
137 
138  i = 1;
139 
140  printf("\nGot a list result\n");
141 
142  /* Traverse list result, extracting information about each message */
143  while (status == X400_E_NOERROR) {
144  int n;
145  int seqnum;
146  int substat;
147  char buf[1024];
148  size_t len;
149 
150  /* Get sequence number */
152  &seqnum);
153  if (status == X400_E_NOERROR)
154  printf("\nSequence number = %d\n", seqnum);
155  else if (status == X400_E_NO_MORE_RESULTS)
156  break;
157 
158  /* Get type of entry */
159  substat = X400msListGetStrParam(lr,
161  i,
162  buf,
163  1024,
164  &len);
165 
166  if (substat == X400_E_NOERROR) {
167  printf("Object type = %s\n", buf);
168  } else {
169  printf("No object type present \n");
170  }
171 
172  /* Get Subject field, if any */
173  substat = X400msListGetStrParam(lr,
175  i,
176  buf,
177  1024,
178  &len);
179 
180  if (substat == X400_E_NOERROR) {
181  printf("Subject = %s\n", buf);
182  } else {
183  printf("No subject present \n");
184  }
185 
186  /* Get sender address */
187  substat = X400msListGetStrParam(lr,
189  i,
190  buf,
191  1024,
192  &len);
193 
194  if (substat == X400_E_NOERROR) {
195  printf("Sender = %s\n", buf);
196  } else {
197  printf("No sender present \n");
198  }
199 
200  substat = X400msListGetStrParam(lr,
202  i,
203  buf,
204  1024,
205  &len);
206 
207  if (substat == X400_E_NOERROR) {
208  printf("Msg Id = %s\n", buf);
209  } else {
210  printf("No Msg Id present \n");
211  }
212 
213  substat = X400msListGetStrParam(lr,
215  i,
216  buf,
217  1024,
218  &len);
219 
220  if (substat == X400_E_NOERROR) {
221  printf("Subject Id = %s\n", buf);
222  } else {
223  printf("No Subject Id present \n");
224  }
225 
226  /* Priority */
227  substat = X400msListGetIntParam(lr, X400_N_PRIORITY, i, &n);
228  if (substat == X400_E_NOERROR) {
229  printf("Priority = %d\n", n);
230  } else {
231  printf("No priority present \n");
232  }
233 
234  /* Length */
236  &n);
237  if (substat == X400_E_NOERROR) {
238  printf("Content length = %d\n", n);
239  } else {
240  printf("No content length present \n");
241  }
242 
244  buf, 1024, &len);
245  if (substat == X400_E_NOERROR) {
246  printf("Content type = %s\n", buf);
247  } else {
248  printf("No content type present \n");
249  }
250 
251  /* Entry status */
253  &n);
254  if (substat == X400_E_NOERROR) {
255  if ( n == X400_MS_ENTRY_STATUS_NEW ) {
256  printf("MS entry status = %d, (New message)\n", n);
257  } else if ( n == X400_MS_ENTRY_STATUS_LISTED ) {
258  printf("MS entry status = %d, (Message listed)\n", n);
259  } else if ( n == X400_MS_ENTRY_STATUS_FETCHED ) {
260  printf("MS entry status = %d, (Message fetched)\n", n);
261  } else {
262  printf("MS entry status = %d, (Unknown status)\n", n);
263  }
264  } else {
265  printf("No entry status present \n");
266  }
267 
268  i++;
269  }
270 
271  X400msListFree(lr);
272 
273  printf("The list result contained %d entries\n", i-1);
274 
275  status = X400msClose (sp);
276  return (status);
277 }
278 
279 static void usage(void) {
280  printf("usage: %s\n", optstr);
281  printf("\t where:\n");
282  printf("\t -u : Don't prompt to override defaults \n");
283  printf("\t -m : OR Address in P7 bind arg \n");
284  printf("\t -p : Presentation Address of P7 Store \n");
285  printf("\t -d : DN in P7 bind arg \n");
286  printf("\t -w : P7 password of P7 user \n");
287  printf("\t -z : List submitted messages\n");
288  printf("\t -n : List messages with status 'new' only\n");
289  printf("\t -T : List messages with delivery time after <UTCTime>\n");
290  printf("\t -V : List messages with delivery time before <UTCTime>\n");
291  printf("\t -S : Specify ms-entry-status value for list operation\n");
292  printf("\t -h : Specify priority value for list operation\n");
293  return;
294 }
295 
#define X400_S_EXTERNAL_CONTENT_TYPE
Definition: x400_att.h:444
#define X400_E_NO_MORE_RESULTS
Definition: x400_att.h:211
#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.
#define X400_S_SUBJECT_IDENTIFIER
Definition: x400_att.h:1027
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 and entrystatus.
#define X400_N_CONTENT_LENGTH
Definition: x400_att.h:408
void X400msSetConfigRequest(int val)
Disable and enable configuration requests in MS Bind operations.
#define X400_N_STRICT_P7_1988
Definition: x400_att.h:1257
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
int X400msClose(struct X400msSession *sp)
Close a X400 Session.
void X400msListFree(struct X400msListResult *lr)
Free the memory occupied by a ListResult.
#define X400_N_MS_ENTRY_STATUS
Definition: x400_att.h:1217
#define X400_S_OBJECTTYPE
Definition: x400_att.h:467
#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_S_OR_ADDRESS
Definition: x400_att.h:346
#define X400_S_MESSAGE_IDENTIFIER
Definition: x400_att.h:402
#define X400_N_MS_SEQUENCE_NUMBER
Definition: x400_att.h:1220
#define X400_MS_ENTRY_STATUS_NEW
Definition: x400_att.h:1265
X400 MA/MS (P3/P7) Interface.
#define MS_ENTRY_CLASS_STORED_MESSAGES
Definition: x400_msapi.h:372
#define X400_N_PRIORITY
Definition: x400_att.h:419
int X400msSetIntDefault(struct X400msSession *sp, int paramtype, int value)
Set a default integer 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_MS_ENTRY_STATUS_LISTED
Definition: x400_att.h:1268
#define X400_S_SUBJECT
Definition: x400_att.h:719
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 MS_ENTRY_CLASS_SUBMITTED_MESSAGES
Definition: x400_msapi.h:375
#define X400_S_LIST_ATTR
Definition: x400_att.h:1146
#define X400_MS_ENTRY_STATUS_FETCHED
Definition: x400_att.h:1271