-/*
- * Validate recipients, count delivery types and errors, and handle aliasing
- * FIXME check for dupes!!!!!
- *
- * Returns 0 if all addresses are ok, ret->num_error = -1 if no addresses
- * were specified, or the number of addresses found invalid.
- *
- * Caller needs to free the result using free_recipients()
- */
-struct recptypes *validate_recipients(const char *supplied_recipients, const char *RemoteIdentifier, int Flags) {
+// Return a supplied list of email addresses as an array, removing superfluous information and syntax.
+Array *split_recps(char *addresses) {
+
+ // Copy the supplied address list into our own memory space, because we are going to mangle it.
+ char *a = malloc(strlen(addresses));
+ a[0] = 0;
+
+ // Strip out anything in double quotes
+ int toggle = 0;
+ int pos = 0;
+ char *t;
+ for (t=addresses; t[0]; ++t) {
+ if (t[0] == '\"') {
+ toggle = 1 - toggle;
+ }
+ else if (!toggle) {
+ a[pos++] = t[0];
+ a[pos] = 0;
+ }
+ }
+
+ // Transform all qualifying delimiters to commas
+ for (t=a; t[0]; ++t) {
+ if ((t[0]==';') || (t[0]=='|')) {
+ t[0]=',';
+ }
+ }
+
+ // Tokenize the recipients into an array
+ Array *recipients_array = array_new(256); // no single recipient should be bigger than 256 bytes
+ char *r = a;
+ while ((t = strtok_r(r, ",", &r))) {
+ striplt(t); // strip leading and trailing whitespace
+ stripout(t, '(', ')'); // remove any portion in parentheses
+ stripallbut(t, '<', '>'); // if angle brackets are present, keep only what is inside them
+ array_append(recipients_array, t);
+ }
+
+ free(a); // We don't need this buffer anymore.
+ return(recipients_array); // Return the completed array to the caller.
+}
+
+
+// Validate recipients, count delivery types and errors, and handle aliasing
+// FIXME check for dupes!!!!!
+//
+// Returns 0 if all addresses are ok, ret->num_error = -1 if no addresses
+// were specified, or the number of addresses found invalid.
+//
+// Caller needs to free the result using free_recipients()
+//
+struct recptypes *validate_recipients(char *supplied_recipients, const char *RemoteIdentifier, int Flags) {