*** storeinfo.c.old	Thu Nov 20 13:21:34 2003
--- storeinfo.c	Fri Jan  9 15:18:45 2004
***************
*** 153,158 ****
--- 153,167 ----
  char	buf[BUFSIZ];
  struct uidplus_info *new_uidplus_info;
  
+ //DAVE: just a few variable declarations
+ char	*extprogram;
+ char	*envvar;
+ char	*syscall;
+ char	*mailboxclean;
+ int	ret;
+ int	idx;
+ //EVAD
+ 
  	if (fstat(fd, &stat_buf) < 0
  	    || (new_uidplus_info=(struct uidplus_info *)
  		malloc(sizeof(struct uidplus_info))) == NULL)
***************
*** 232,244 ****
  		free(new_uidplus_info);
  		return (-1);
  	}
! 
  	new_uidplus_info->tmpfilename=tmpname;
  	new_uidplus_info->curfilename=newname;
  	new_uidplus_info->next=NULL;
  	new_uidplus_info->old_uid=old_uid;
  	*cpy_info->uidplus_tail=new_uidplus_info;
  	cpy_info->uidplus_tail=&new_uidplus_info->next;
  	return (0);
  }
  
--- 241,309 ----
  		free(new_uidplus_info);
  		return (-1);
  	}
!  
  	new_uidplus_info->tmpfilename=tmpname;
  	new_uidplus_info->curfilename=newname;
  	new_uidplus_info->next=NULL;
  	new_uidplus_info->old_uid=old_uid;
  	*cpy_info->uidplus_tail=new_uidplus_info;
  	cpy_info->uidplus_tail=&new_uidplus_info->next;
+ 
+ //DAVE: call an external program depending on the target mailbox
+ 
+         	envvar=(char *)malloc(1024);
+         	syscall=(char *)malloc(1024);
+         	mailboxclean=(char *)malloc(1024);
+         	
+         	// if length of the mailbox string is 1, it is "." == INBOX
+         	if( strlen(cpy_info->mailbox) == 1 ) {
+         		extprogram=getenv("ON_COPY_TO_INBOX");
+         		strcpy(envvar, "ON_COPY_TO_INBOX");
+         	} else {
+         		//we want to get the environment variable
+         		//matching the target mailbox.
+         		strcpy(envvar, "ON_COPY_TO_BOX_");
+         		strncpy(mailboxclean, (char *)(cpy_info->mailbox+1), 1000);
+         		
+         		//we need to convert all special chars to underscores,
+         		//since an environment variable can only handle these
+         		for( idx = 0; (mailboxclean[idx] != 0) && (idx<1000); idx++ ) {
+         			if( ((mailboxclean[idx] < 'A') ||
+         			     (mailboxclean[idx] > 'Z')) &&
+         			    ((mailboxclean[idx] < 'a') ||
+         			     (mailboxclean[idx] > 'z'))      ) {
+         				mailboxclean[idx] = '_';
+         			}
+         		}
+         		
+         		//now get the env. var.
+         		strncat(envvar, mailboxclean, 1000);
+         		extprogram=getenv(envvar);
+         	}
+         	
+         	//if env. var. not specified, get the fallback var.
+         	if( extprogram == NULL ) {
+         		extprogram=getenv("ON_COPY_TO_NOT_LISTED");
+         		strcpy(envvar, "ON_COPY_TO_NOT_LISTED");
+         	}
+         	
+         	//run the program in the env. var., but replace the %s
+         	//with the filename first.
+         	if( (extprogram != NULL) && (strlen(extprogram) > 0) ) {
+         		snprintf(syscall, 1000, extprogram, tmpname);
+         		fprintf(stderr, "INFO: option: %s, calling %s\n", envvar, syscall);
+         		ret=system(syscall);
+         		//we want a syslog if there were errors.
+         		if( ret != 0 ) {
+         			fprintf(stderr, "INFO: calling %s returned error code %d\n", syscall, ret); 
+         		}
+         	}
+         	
+         	free(syscall);
+         	free(mailboxclean);
+         	free(envvar);
+ //EVAD	
+ 
  	return (0);
  }
  
