示例#1
0
文件: string.c 项目: pbevin/hypermail
/*  escape: 1==on 0==off */
char *i18n_utf2numref(char *instr,int escape){

  char *ucs,*headofucs;
  size_t len;
  struct Push buff;
  char strbuf[10];

  INIT_PUSH(buff);

  if (!set_i18n){
    PushString(&buff,instr);
    RETURN_PUSH(buff);
  }

  headofucs=ucs=i18n_convstring(instr, "UTF-8", "UCS-2BE", &len);

  unsigned int p;
  int i = (int) len;
  for(; i > 0; i-=2){
    p=(unsigned char)*ucs*256+(unsigned char)*(ucs+1);
    if (p<128){
      /* keep ASCII characters human readable */
      if (escape){
        switch (p){
        case '<':
          PushString(&buff, "&#0060;");
          break;
        case '>':
          PushString(&buff, "&#0062;");
          break;
        case '&':
          PushString(&buff, "&#0038;");
          break;
        case '\"':
          PushString(&buff, "&#0034;");
          break;
        case '\'':
          PushString(&buff, "&#0039;");
          break;
        default:
          PushByte(&buff,p);
        }
      }else{
        PushByte(&buff,p);
      }
    }else{
      snprintf(strbuf,10,"&#%04d;",p);
      PushString(&buff,strbuf);
    }
    ucs+=2;
  }
  free(headofucs);
  RETURN_PUSH(buff);
}
示例#2
0
文件: string.c 项目: pbevin/hypermail
/*
** email address obfuscation
*/
char *obfuscate_email_address(char *address)
{
  char sbuf[10];
  struct Push buf;
  int at_mailbox=1;
  char *sentinel;

  if (!set_email_address_obfuscation){
    return address;
  }

  sentinel=strlen(address)+address;

  INIT_PUSH(buf);
  while (address<sentinel){
    if (*address=='@'){
      PushString(&buf,"&#x40;");
      at_mailbox=0;
    }else{
      if(!at_mailbox){
	sprintf(sbuf,"&#%04d;",*address);
	PushString(&buf,sbuf);
      }else{
	sbuf[0]=*address;
	sbuf[1]=0x0;
	PushString(&buf,sbuf);
      }
    }
    address++;
  }
  RETURN_PUSH(buf);
}
示例#3
0
static char *msgsperfolder_label(char *frmptr, int subdir_no)
{
    register char *aptr;
    char dtstr[DATESTRLEN];
    char c;

    struct Push buff;

    INIT_PUSH(buff);

    aptr = frmptr;

    while ((c = *aptr++)) {
	if (c == '%') {
	    switch (*aptr++) {
	    case '%':		/* Add the % character */
		PushByte(&buff, '%');
		continue;
	    case 'd':		/* directory number, starting at 0 */
		sprintf(dtstr, "%d", subdir_no);
		PushString(&buff, dtstr);
		continue;
	    case 'D':		/* directory number, starting with 1 */
				sprintf(dtstr, "%d", subdir_no + 1);
		PushString(&buff, dtstr);
		continue;
	    case 'm':		/* number of first message in directory */
				sprintf(dtstr, "%d", set_msgsperfolder * subdir_no);
		PushString(&buff, dtstr);
		continue;
	    case 'M':		/* number of last message possible */
				sprintf(dtstr, "%d", set_msgsperfolder * (subdir_no + 1) - 1);
		PushString(&buff, dtstr);
		continue;
	    default:
		PushString(&buff, "%?");
		continue;
	    }			/* end switch */
	}

	PushByte(&buff, c);
    }				/* end while */

    RETURN_PUSH(buff);
}
示例#4
0
文件: string.c 项目: pbevin/hypermail
char *unobfuscate_email_address(char *address){

#define uea_sbufsize 6
  int flag=0; /* 1==obfuscated string */
  int on_error=0; /* 1==something was happen */
  int on_hex=0; /* 1==base 16 */
  int at_mailbox=1; /* 1==mailbox part */
  char *sentinel;

  char sbuf[uea_sbufsize+1];
  int scount=0;
  struct Push buf;
  long c;

  INIT_PUSH(buf);

  sentinel=strlen(address)+address;


  while (address<sentinel){
    switch (*address){
    case '&':
      if(strncmp(address,"&#x40;",6)==0){
	PushByte(&buf, '@');
	address+=5;
	flag=0;
	on_error=0;
	on_hex=0;
	at_mailbox=0;
	break;
      }
      if (at_mailbox){
	PushByte(&buf, '&');
	break;
      }
      if (flag==0){
	flag=1;
      }else{
	/* broken string */
	on_error=1;
      }
      break;
    case ';':
      if (at_mailbox){
	PushByte(&buf, ';');
	break;
      }
      if (flag==1){
	flag=0;
	sbuf[scount]=0;
	if(on_hex==1){
	  c=strtol(sbuf,NULL,16);
	}else{
	  c=strtol(sbuf,NULL,10);
	}
	if (on_error==0){
	  PushByte(&buf, (unsigned char)c); /* should be ASCII */
	} /* simply discard error */
	scount=0;
	on_error=0;
      }else{
	/* broken string */
	on_error=1;
      }
      break;
    case '#':
      if (at_mailbox){
	PushByte(&buf, '#');
	break;
      }
      if (flag==1){
	if (*(address+1)=='x'){
	  on_hex=1;
	  address++;
	}else{
	  on_hex=0;
	}
	break;
      }else{
	PushByte(&buf, *address);
      }
      break;
    default:
      if (at_mailbox || flag==0){
	PushByte(&buf, *address);
      }else{
	sbuf[scount++]=*address;
	if (scount>=uea_sbufsize){
	  /* broken string */
	  scount=0;
	  on_error=1;
	}
      }
    }
    address++;
  }
  RETURN_PUSH(buf);
}
示例#5
0
void check1dir(char *dir)
{
    struct stat sbuf;

    if (stat(dir, &sbuf)) {
    /*
    ** LCC only has the short mkdir().  Fortunately, we do a chmod
    ** immediately afterward, so it's a don't care.
    */
#ifdef __LCC__
	if (errno != ENOENT || mkdir(dir) < 0) {
#else
	if (errno != ENOENT || mkdir(dir, set_dirmode) < 0) {
#endif
            if (errno != EEXIST) {
		snprintf(errmsg, sizeof(errmsg), "%s \"%s\".", lang[MSG_CANNOT_CREATE_DIRECTORY], dir);
		progerr(errmsg);
	    }
	}
	if (set_showprogress)
			printf(" %s \"%s\", %s %o.\n", lang[MSG_CREATING_DIRECTORY], dir, lang[MSG_MODE], set_dirmode);

	if (chmod(dir, set_dirmode) == -1) {
			snprintf(errmsg, sizeof(errmsg), "%s \"%s\" to %o.", lang[MSG_CANNOT_CHMOD], dir, set_dirmode);
	    progerr(errmsg);
	}
    }
}

/*
** This tries to create and chmod a path to a directory.
*/

void checkdir(char *dir)
{
    register char *p;
    struct stat sbuf;
    int ch;

    p = dir;

    if (*p && *p == '/')	/* get off root */
	p++;

    for (;; ++p) {
	if (!*p || *p == '/') {
	    ch = *p;
	    *p = '\0';
	    if (stat(dir, &sbuf)) {
	    /* See comment in check1dir */
#ifdef __LCC__
		if (errno != ENOENT || mkdir(dir) < 0) {
#else
		if (errno != ENOENT || mkdir(dir, set_dirmode) < 0) {
#endif
		    if (errno != EEXIST) {
			snprintf(errmsg, sizeof(errmsg), "%s \"%s\".", lang[MSG_CANNOT_CREATE_DIRECTORY], dir);
			progerr(errmsg);
		    }
		}
		if (set_report_new_folder) {
		    printf("%s\n", dir);
		}
		if (set_showprogress)
		    printf(" %s \"%s\", %s %o.\n", lang[MSG_CREATING_DIRECTORY], dir, lang[MSG_MODE], set_dirmode);

		if (chmod(dir, set_dirmode) == -1) {
		    snprintf(errmsg, sizeof(errmsg), "%s \"%s\" to %o.", lang[MSG_CANNOT_CHMOD], dir, set_dirmode);
		    progerr(errmsg);
		}
	    }
	    *p = ch;
	    if (!*p)
		break;
	}
    }
}

char *getfilecontents(char *filename)
{
    FILE *infile;
    struct stat finfo;
    char *retval;

    if ((infile = fopen(filename, "r")) == NULL)
	return (NULL);

    if (fstat(fileno(infile), &finfo) != 0) {
	(void)fclose(infile);
	return (NULL);
    }

    if (finfo.st_size == 0) {
	(void)fclose(infile);
	return (NULL);
    }

    else {
	if (!(retval = (char *)malloc((unsigned)finfo.st_size + 1))) {
	    (void)fclose(infile);
	    return (NULL);
	}
	if (!fread(retval, (size_t) finfo.st_size, 1, infile)) {
	    (void)fclose(infile);
	    free(retval);
	    return (NULL);
	}
	*(retval + finfo.st_size) = '\0';
    }
    (void)fclose(infile);
    return (retval);
}


/*
** expand_path - fill in values substituting for magic cookies
**
**      Substitution cookies supported
**
**              %d - two digit day of month (1-28/30/31)
**              %D - three letter day of the week
**              %m - two digit month of year (1-12)
**              %M - three letter month of year (Jan, Feb, ..., Dec)
**              %y - four digit year (1990,..2001)
**
** Returns:   expanded path string
*/

char *dirpath(char *frmptr)
{
    register char *aptr;
    char dtstr[DATESTRLEN];
    char c;
    struct tm *now;
    time_t clk;

    struct Push buff;

    INIT_PUSH(buff);

    clk = time((time_t *)0);
    now = localtime(&clk);

    aptr = frmptr;

    while ((c = *aptr++)) {
	if (c == '%') {
	    switch (*aptr++) {
	    case '%':		/* Add the % character */
		PushByte(&buff, '%');
		continue;
	    case 'd':		/* two digit day of month (1-31) */
		sprintf(dtstr, "%.2d", now->tm_mday);
		PushString(&buff, dtstr);
		continue;
	    case 'D':		/* three letter day of week */
		PushString(&buff, days[now->tm_wday]);
		continue;
	    case 'j':		/* julian date */
		sprintf(dtstr, "%.3d", now->tm_yday);
		PushString(&buff, dtstr);
		continue;
	    case 'm':		/* two digit month of year (1-12) */
		sprintf(dtstr, "%.2d", now->tm_mon + 1);
		PushString(&buff, dtstr);
		continue;
	    case 'M':		/* three letter month of year */
		PushString(&buff, months[now->tm_mon]);
		continue;
	    case 'y':		/* 4 digit year */
		sprintf(dtstr, "%.4d", now->tm_year + 1900);
		PushString(&buff, dtstr);
		continue;
	    default:
		PushString(&buff, "%?");
		continue;
	    }			/* end switch */
	}

	PushByte(&buff, c);
    }				/* end while */

    RETURN_PUSH(buff);
}

/*
** Reads a configuration file if it exists and puts all the right
** values into the right variables.
*/

void readconfigs(char *path, int cmd_show_variables)
{
    if (path && path[0] == '~') {
    	char *ep; 
	char tmppath[MAXFILELEN]; /*AUDIT biege: pathname + filename is more then 4KB long on linux */
        struct passwd *pp;

#ifndef __LCC__
	/*
	** Getting password data from /etc/passwd is pretty silly in
	** Win9x systems since nearly everybody builds this file after
	** they set up $HOME.  Just skip this try at finding a default
	** location for the config file and go on to try $HOME.
	*/
        if ((pp = getpwuid(getuid())) != NULL) {
			snprintf(tmppath, sizeof(tmppath), "%s%s", pp->pw_dir, path + 1);	/* AUDIT biege: who gurantees that path+1 contains data? */
            ConfigInit(tmppath);
        } 
	else
#endif
            if ((ep = getenv("HOME")) != NULL) { /* AUDIT biege: possible BOF.. but it's not setuid.. so why to care? */
			snprintf(tmppath, sizeof(tmppath), "%s%s", ep, path + 1);	/* AUDIT biege: who gurantees that path+1 contains data? */
            ConfigInit(tmppath);
        }
        /* 
         * So what happens here if the above two conditions fail ????
         * Simply use the compiled in defaults ?
         */
    }    
    else {
	ConfigInit(path);

	if (set_showprogress && !cmd_show_variables)
	    printf("%s: %s\n", lang[MSG_PATH], path);
    }
}

void symlink_latest()
{
    /*
    ** Symlinks work so differently in Windows that I think we'll just
    ** skip that whole thing and ignore that option.
    */
#ifdef __LCC__
    snprintf(errmsg, sizeof(errmsg),
	"WARNING: latest_folder not supported in Win32 environment.\n");
    fprintf(stderr, "%s", errmsg);
#else
    char filename[MAXFILELEN];
    
    struct stat stbuf;

    if (!latest_folder_path)
	return;			/* haven't created new folder this time? */
    trio_snprintf(filename, MAXFILELEN, "%s%s", set_dir, set_latest_folder);

    if (!stat(filename, &stbuf) && unlink(filename)) {
		snprintf(errmsg, sizeof(errmsg), "%s \"%s\" (latest_folder option).", lang[MSG_CANNOT_UNLINK], filename);
	progerr(errmsg);
	return;
    }

    if (symlink(latest_folder_path, filename)) {
		snprintf(errmsg, sizeof(errmsg), "%s \"%s\" (latest_folder option).", lang[MSG_CANNOT_CREATE_SYMLINK], filename);
	progerr(errmsg);
	return;
    }
#endif
}