Пример #1
0
int main(int argc,char *argv[])
{
  const char* dir;
  int fd;
  int match;
  unsigned long msgsize = 0L;
  int opt;
  
  while ((opt = getopt(argc,argv,"vV")) != opteof) {
    switch(opt) {
    case 'v':
    case 'V':
      strerr_die2x(0, "ezmlm-import version: ",auto_version);
    default:
      die_usage();
    }
  }

  if (argc - optind != 2)
    die_usage();

  if ((fd = open_read(argv[optind+1])) == -1)
    strerr_die4sys(111,FATAL,ERR_OPEN,argv[optind+1],": ");
  substdio_fdbuf(&ssin,read,fd,inputbuf,sizeof inputbuf);

  startup(dir = argv[optind]);
  lockfile("lock");

  getconf_ulong2(&msgnum,&cumsize,"num",0,dir);
  
  fd = 0;
  while (getln(&ssin,&line,&match,'\n') == 0 && match) {
    if (line.len > 5
	&& byte_diff(line.s,5,"From ") == 0) {
      if (fd > 0) {
	if (substdio_flush(&ssarchive) == -1
	    || fchmod(fd,MODE_ARCHIVE|0700) == -1
	    || close(fd) == -1)
	  strerr_die4sys(111,FATAL,ERR_WRITE,fnaf.s,": ");
	fd = 0;
      }
      ++msgnum;
      cumsize += (msgsize + 128L) >> 8;
      msgsize = 0L;
      fd = openone(msgnum);
    }
    else if (fd > 0) {
      substdio_put(&ssarchive,line.s,line.len);
      msgsize += line.len;
    }
  }
Пример #2
0
int main(int argc,char *argv[])
{
  int fd;
  int match;
  unsigned long msgsize = 0L;
  int opt;
  stralloc line = {0};
  substdio ssin;
  char inputbuf[4096];
  unsigned long msgnum;
  unsigned long cumsize;


  opt = getconfopt(argc,argv,options,1,0);
  switch (argc - opt) {
    case 0:
      substdio_fdbuf(&ssin,read,0,inputbuf,sizeof inputbuf);
      break;
    case 1:
      if ((fd = open_read(argv[opt])) == -1)
        strerr_die2sys(111,FATAL,MSG1(ERR_OPEN,argv[opt]));
      substdio_fdbuf(&ssin,read,fd,inputbuf,sizeof inputbuf);
      break;
    default:
      die_usage();
  }

  lockfile("lock");

  getconf_ulong2(&msgnum,&cumsize,"num",0);
  
  fd = 0;
  while (getln(&ssin,&line,&match,'\n') == 0 && match) {
    if (line.len > 5
	&& byte_diff(line.s,5,"From ") == 0) {
      flushit(fd);
      ++msgnum;
      cumsize += (msgsize + 128L) >> 8;
      msgsize = 0L;
      fd = openone(msgnum);
    }
    else if (fd > 0) {
Пример #3
0
int main(int argc,char *argv[])
{
  int fd;
  int match;
  unsigned long msgsize = 0L;
  int opt;

  opt = getconfopt(argc,argv,options,1,0);
  if (argc - opt != 1)
    die_usage();

  if ((fd = open_read(argv[opt])) == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_OPEN,argv[opt]));
  substdio_fdbuf(&ssin,read,fd,inputbuf,sizeof inputbuf);

  lockfile("lock");

  getconf_ulong2(&msgnum,&cumsize,"num",0);
  
  fd = 0;
  while (getln(&ssin,&line,&match,'\n') == 0 && match) {
    if (line.len > 5
	&& byte_diff(line.s,5,"From ") == 0) {
      if (fd > 0) {
	if (substdio_flush(&ssarchive) == -1
	    || fchmod(fd,MODE_ARCHIVE|0700) == -1
	    || close(fd) == -1)
	  strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnaf.s));
	fd = 0;
      }
      ++msgnum;
      cumsize += (msgsize + 128L) >> 8;
      msgsize = 0L;
      fd = openone(msgnum);
    }
    else if (fd > 0) {
      substdio_put(&ssarchive,line.s,line.len);
      msgsize += line.len;
    }
  }