51a52,55
> #ifdef QMAIL_EXT
> char TheUserExt[AUTH_SIZE]; /* the User with '-' and following chars out if any */
> #endif
> 
65c69
< int process_valias(char *user, char *domain);
---
> int process_valias(void);
75a80,81
> void checkuser(void);
> void usernotfound(void);
87,88d92
<  int ret;
< 
94c98
<     if ( process_valias( TheUser, TheDomain) == 1 ) {
---
>     if ( process_valias() == 1 ) {
102,121c106,114
< 
<         /* check if the account is locked and thier email
<          * should be bounced back
<          */
< 	if (vpw->pw_gid & BOUNCE_MAIL ) {
<             printf("vdelivermail: account is locked email bounced %s@%s\n",
<                 TheUser, TheDomain);
<             vexit(100);
<         }
< 
<         /* check for a .qmail file in thier Maildir
<          * If it exists, then deliver to the contents and exit
<          */
<         if ( check_forward_deliver(vpw->pw_dir) == 1 ) {
<             vexit(0);
<         }
< 
<         snprintf(TheDir, AUTH_SIZE, "%s/Maildir/", vpw->pw_dir);
<         if ( deliver_mail(TheDir, vpw->pw_shell) != 0 ) {
<             vexit(100);
---
>         checkuser();
>     } 
> #ifdef QMAIL_EXT
>     /* try and find user that matches the QmailEXT address if: no user found, */
>     /* and the QmailEXT address is different, meaning there was an extension */
>     else if ( strncmp(TheUser, TheUserExt, AUTH_SIZE) != 0 ) {
>         /* get the user from vpopmail database */
>         if ((vpw=vauth_getpw(TheUserExt, TheDomain)) != NULL ) {
> 	    checkuser();
123,163c116,117
< 
<     /* the vpopmail user does not exist. Follow the rest of 
<      * the directions in the .qmail-default file
<      */ 
<     } else {
< 
<         /* If they want to delete email for non existant users
<          * then just exit 0. Qmail will delete the email for us
<          */
<         if ( strcmp(bounce, DELETE_ALL) == 0 ) {
<             /* just exit 0 and qmail will delete the email from the system */
<             vexit(0);
< 
<         /* If they want to bounce the email back then
<          * print a message and exit 100 
<          */
<         } else if ( strcmp(bounce, BOUNCE_ALL) == 0 ) {
<             printf("Sorry, no mailbox here by that name. vpopmail (#5.1.1)\n");
< 
<             /* exit 100 causes the email to be bounced back */
<             vexit(100);
< 
<         } 
< 
<         /* check if it is a path add the /Maildir/ for delivery */ 
<         if ( strstr( bounce, VPOPMAILDIR ) != 0 ) {
<             strcat( bounce, "/Maildir/");
<         } 
< 
< 	ret = deliver_mail(bounce, "NOQUOTA" );
< 
<         /* Send the email out, if we get a -1 then the user is over quota */
<         if ( ret == -1 ) {
<             printf("user is over quota, mail bounced\n");
<             vexit(100);
<         } else if ( ret == -2 ) {
< 	    printf("system error\n");
< 	    vexit(100);
<         } else if ( ret != 0 ) {
< 	    printf("mail is looping\n");
< 	    vexit(100);
---
> 	else {
> 	    usernotfound();
165c119,122
< 
---
>     }
> #endif
>     else {
>         usernotfound();
217c174,175
<     for(i=0;TheUser[i]!=0;++i) {
---
>     /* delete the '-' and following chars if any and store in TheUserExt */
>     for(i = 0; TheUser[i] != 0; i++) {
219d176
<             TheUser[i] = 0;
221a179,180
> 
>         TheUserExt[i] = TheUser[i];
222a182,183
> 
>     TheUserExt[i] = 0;
239c200
< int process_valias(char *user, char *domain)
---
> int process_valias(void)
245c206
<     tmpstr = valias_select( user, domain );
---
>     tmpstr = valias_select( TheUser, TheDomain );
259a221,242
>     #ifdef QMAIL_EXT 
>     /* try and find alias that matches the QmailEXT address if: no alias found, */
>     /* and the QmailEXT address is different, meaning there was an extension */
>     if ( (!found) && ( strncmp(TheUser, TheUserExt, AUTH_SIZE) != 0 )  ) {
>         /* Get the first alias for this user@domain */
>         tmpstr = valias_select( TheUserExt, TheDomain );
> 
>         /* tmpstr will be NULL if there are no more aliases */
>         while (tmpstr != NULL ) {
> 
>             /* We found one */
>             found = 1;
> 
>             /* deliver the mail */
>             deliver_mail(tmpstr, "NOQUOTA");
> 
>             /* Get the next alias for this user@domain */
>             tmpstr = valias_select_next();
>         } 
>     }	
>     #endif
> 
885a869,941
> 
> }
> 
> 
> /*
>  * check for locked account
>  * deliver to .qmail file if any
>  * deliver to user if no .qmail file
>  */
> void checkuser() {
>     if (vpw->pw_gid & BOUNCE_MAIL ) {
>         printf("vdelivermail: account is locked email bounced %s@%s\n",
>             TheUser, TheDomain);
>         vexit(100);
>     }
> 
>     /* check for a .qmail file in thier Maildir
>      * If it exists, then deliver to the contents and exit
>      */
>     if ( check_forward_deliver(vpw->pw_dir) == 1 ) {
>         vexit(0);
>     }
> 
>     snprintf(TheDir, AUTH_SIZE, "%s/Maildir/", vpw->pw_dir);
>     if ( deliver_mail(TheDir, vpw->pw_shell) != 0 ) {
>         vexit(100);
>     }
> }
> 
> 
> /*
>  * the vpopmail user does not exist. Follow the rest of
>  * the directions in the .qmail-default file
>  */
> void usernotfound() {
>  int ret;
> 
>     /* If they want to delete email for non existant users
>      * then just exit 0. Qmail will delete the email for us
>      */
>     if ( strcmp(bounce, DELETE_ALL) == 0 ) {
>         /* just exit 0 and qmail will delete the email from the system */
>         vexit(0);
> 
>     /* If they want to bounce the email back then
>      * print a message and exit 100
>      */
>     } else if ( strcmp(bounce, BOUNCE_ALL) == 0 ) {
>         printf("Sorry, no mailbox here by that name. vpopmail (#5.1.1)\n");
> 
>         /* exit 100 causes the email to be bounced back */
>         vexit(100);
> 
>     }
> 
>     /* check if it is a path add the /Maildir/ for delivery */
>     if ( strstr( bounce, VPOPMAILDIR ) != 0 ) {
>         strcat( bounce, "/Maildir/");
>     }
> 
>     ret = deliver_mail(bounce, "NOQUOTA" );
> 
>     /* Send the email out, if we get a -1 then the user is over quota */
>     if ( ret == -1 ) {
>         printf("user is over quota, mail bounced\n");
>         vexit(100);
>     } else if ( ret == -2 ) {
>         printf("system error\n");
>         vexit(100);
>     } else if ( ret != 0 ) {
>         printf("mail is looping\n");
>         vexit(100);
>     }
