ftp.nice.ch/pub/next/connectivity/news/Alexandra-0.9.s.tar.gz#/alex/rfc822realname.c

This is rfc822realname.c in view mode; [Download] [Up]

#include <string.h>

int rfc822_realname(const char *from_header,int *from,int *to)
{
   char *s,*e;
   int i,j,z;
   int a,b;

   *from=0; *to=-1;

   if((from_header!=(void *)0)&&(from_header[0]!='\0')){
      if(strchr(from_header,(int)'@')==NULL){
         // no regular rfc822 thing
         i=0;
         j=strlen(from_header)-1;
         if((from_header[i]=='(')&&(from_header[j]==')')){
            i++; j--;
         }
         *from=i; *to=j;
         return 0;
      }
      s=strrchr(from_header,(int)'<');
      e=strrchr(from_header,(int)'>');
      if((s!=NULL)&&(e!=NULL)){
         i=strlen(s);
         j=strlen(e);
         z=strlen(from_header);
         if(i>j){
            if(i==z){
               a=1;
               b=i-j-1;
            }
            else{
               int ii;
               a=0;
               ii=z-i-1;
               if(from_header[ii]==' ')
                  ii--;
               b=ii;
            }
            if((from_header[a]=='"')&&(from_header[b]=='"')){
               a++; b--;
            }
            *from=a; *to=b;
            return 0; 
         }
      }
      else{
         s=strchr(from_header,(int)'(');
         e=strrchr(from_header,(int)')');
			if(s==e-1){
			   int t=strlen(from_header)-strlen(s)-1;
				while(t>0 && (from_header[t]==' '))
					t--;
				if(t>0)
				   *to=t;
				else
					*to=strlen(from_header);
				*from=0;
				return 0;
			}
         if((s!=(void *)0)&&(e!=(void *)0)){
            i=strlen(s);
            j=strlen(e);
            z=strlen(from_header);
            if(i>j+1){
               a=z-i+1;
               b=z-j-1;
               if((from_header[a]=='"')&&(from_header[b]=='"')){
                  a++; b--;
               }
               *from=a; *to=b;
               return 0;
            }
         }
         else{
            *from=0;
            *to=strlen(from_header)-1;
            return 0;
         }
      }
   }
   return 0;
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.