⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mail-loadsave.c

📁 一个功能全面的电子邮件客户端
💻 C
📖 第 1 页 / 共 3 页
字号:
		mseek=mseek->next;	}	free (sep);}/* * Completely new index functions to replace the completely lame index code * that was previously in place.  I can't for the life of me imagine why * anyone would do byte at a time I/O and not expect to get slammed for it!!! * Additionally, some dummy decided that we'll have distinct indecies, but * maintain everything in memory in a single list.  Duh! * * At any rate, this will be a new implemention of the current logic (highly * optimized) with only minor departures.  Once the current implementation * is better understood, and give allows, the optimizations will be complete, * which should yield MUCH better results.  The next thing to do here is to * optimize the folder opening code.  Between these two, things should be * TONS faster when dealing with large folders. * * This function returns the number of index nodes that were read out. * Also, note that we use 64K blocks for our I/O. * * This code is NOT complete and will have to wait until some other code * can be re-written (folder logic) to properly make use of indexes per * foler, whereby, the folder index/contents are actually maintained * properly instead of trying to cramp everthing into a single linked * list.   Grrrr... */#if 0intnew_index_read( pfile *pf, Folder *fl ){  int ret ;   FILE *f ;  char *buf ;  int index ;  int length ;  ret = 0 ;  index = 0 ;  length = 0 ;  f = pf -> fs ;  buf = malloc( IO_CHUNK ) ;  /* Fetch our first block chunk */  length = fread( buf, IO_CHUNK, 1, f ) ;  /* Make sure we have fetched something, otherwise, report the error */  if( length > 0 )    {      /*       * First, fetch the version number.  If the version       * number is an older number, we'll error for now.  In the future, I'll       * try to automatically reindex.       */      if( atoi(buf) >= 2 )	{	  /* Jump past the version */	  index += 4 + 1 ;  /* NULL value */	  fl -> parent = strdup( &buf[index] ) ;	  index += strlen(&buf[index]) ;	  index++ ;  /* NULL value */	  fl -> flags = (int *)&buf[index] ;	  index += sizeof( int ) ;	  fl -> seek = (int *)&buf[index] ;	  index += sizeof( int ) ;	  fl -> size = (int *)&buf[index] ;	  index += sizeof( int ) ;	  fl -> hsize = (int *)&buf[index] ;	  index += sizeof( int ) ;	  fl -> flags = (int *)&buf[index] ;	  index += sizeof( int ) ;	  fl -> time = (int *)&buf[index] ;	  index += sizeof( int ) ;	  fl -> folder = strdup( &buf[index] ) ;	  index += strlen(&buf[index]) ;	  index++ ;  /* NULL value */	  fl -> subject = strdup( &buf[index] ) ;	  index += strlen(&buf[index]) ;	  index++ ;  /* NULL value */	  fl -> date = strdup( &buf[index] ) ;	  index += strlen(&buf[index]) ;	  index++ ;  /* NULL value */	  fl -> uidl = strdup( &buf[index] ) ;	  index += strlen(&buf[index]) ;	  index++ ;  /* NULL value */	}    }  return ret ;}#endifvoid index_read (pfile *pf, Folder *fl) {	char *tmps=(char *)calloc(1025, sizeof(char));	unsigned long seek, size, hsize, flags, time;	int iversion;	char *folder=NULL, *from=NULL, *subject=NULL, *date=NULL, *uidl=NULL;	char *priority=NULL;	char *replyto=NULL;	char *sensitivity=NULL;	char *expiry=NULL;	char *replyby=NULL;	char *keywords=NULL;	char snum[4];	char ch;	int i=0, id;	Message *msgs;	ch=getch (pf);	while ((ch!=EOW)&&(i<1024)) {		tmps[i]=ch;		ch=getch (pf);		i++;		if (pf->T_EOF==1) goto errorhead;	}	if (tmps[i]==EOW) tmps[i]='\0';	fl->parent=strdup (tmps);	snum[0]=getch(pf);	if (pf->T_EOF==1) goto errorhead;	snum[1]=getch(pf);	if (pf->T_EOF==1) goto errorhead;	snum[2]=getch(pf);	if (pf->T_EOF==1) goto errorhead;	snum[3]=getch(pf);	iversion=atoi (snum);#if DEBUG > 4	printf( "Reading index file version %d.\n", iversion ) ;#endif	if (iversion==0) {		fl->flags=assemble_long (snum);	} else {		snum[0]=getch(pf);		if (pf->T_EOF==1) goto errorhead;		snum[1]=getch(pf);		if (pf->T_EOF==1) goto errorhead;		snum[2]=getch(pf);		if (pf->T_EOF==1) goto errorhead;		snum[3]=getch(pf);		fl->flags=assemble_long (snum);	}	ch=getch (pf);	if (ch!=-1) ungetch(pf);	while (pf->T_EOF==0) {		snum[0]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[1]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[2]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[3]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		seek=assemble_long (snum);		snum[0]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[1]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[2]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[3]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		size=assemble_long (snum);		snum[0]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[1]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[2]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[3]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		hsize=assemble_long (snum);		snum[0]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[1]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[2]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[3]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		flags=assemble_long (snum);		snum[0]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[1]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[2]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		snum[3]=getch(pf);			if (pf->T_EOF==1) goto errormsg;		time=assemble_long (snum);		ch=getch(pf);		i=0;		memset (tmps, 0, 1024);		while ((ch!=EOW)&&(pf->T_EOF!=-1)) {			tmps[i]=ch;			ch=getch(pf);			if (pf->T_EOF==1) goto errormsg;			i++;		}		folder=strdup(tmps);		ch=getch(pf);		i=0;		memset (tmps, 0, 1024);		while ((ch!=EOW)&&(pf->T_EOF!=-1)) {			tmps[i]=ch;			ch=getch(pf);			if (pf->T_EOF==1) goto errormsg;			i++;		}		from=strdup(tmps);		ch=getch(pf);		i=0;		memset (tmps, 0, 1024);		while ((ch!=EOW)&&(pf->T_EOF!=-1)) {			tmps[i]=ch;			ch=getch(pf);			if (pf->T_EOF==1) goto errormsg;			i++;		}		subject=strdup(tmps);		/* Trey added priority support */		if( iversion > 1 ) {		  ch=getch(pf);		  i=0;		  memset (tmps, 0, 1024);		  while ((ch!=EOW)&&(pf->T_EOF!=-1)) {		    tmps[i]=ch;		    ch=getch(pf);		    if (pf->T_EOF==1) goto errormsg;		    i++;		  }		  priority=strdup(tmps);		}		else priority = strdup( "3" ) ;                if( iversion > 3 ) {                  ch=getch(pf);                  i=0;                  memset (tmps, 0, 1024);                  while ((ch!=EOW)&&(pf->T_EOF!=-1)) {                    tmps[i]=ch;                    ch=getch(pf);                    if (pf->T_EOF==1) goto errormsg;                    i++;                  }                  replyto=strdup(tmps);                }                if( iversion > 4 ) {                  ch=getch(pf);                  i=0;                  memset (tmps, 0, 1024);                  while ((ch!=EOW)&&(pf->T_EOF!=-1)) {                    tmps[i]=ch;                    ch=getch(pf);                    if (pf->T_EOF==1) goto errormsg;                    i++;                  }                  sensitivity=strdup(tmps);                }                if( iversion > 5 ) {                  ch=getch(pf);                  i=0;                  memset (tmps, 0, 1024);                  while ((ch!=EOW)&&(pf->T_EOF!=-1)) {                    tmps[i]=ch;                    ch=getch(pf);                    if (pf->T_EOF==1) goto errormsg;                    i++;                  }                  expiry=strdup(tmps);                }                if( iversion > 5 ) {                  ch=getch(pf);                  i=0;                  memset (tmps, 0, 1024);                  while ((ch!=EOW)&&(pf->T_EOF!=-1)) {                    tmps[i]=ch;                    ch=getch(pf);                    if (pf->T_EOF==1) goto errormsg;                    i++;                  }                  replyby=strdup(tmps);                }                if( iversion > 2 ) {                  ch=getch(pf);                  i=0;                  memset (tmps, 0, 1024);                  while ((ch!=EOW)&&(pf->T_EOF!=-1)) {                    tmps[i]=ch;                    ch=getch(pf);                    if (pf->T_EOF==1) goto errormsg;                    i++;                  }                  keywords=strdup(tmps);                }		ch=getch(pf);		i=0;		memset (tmps, 0, 1024);		while ((ch!=EOW)&&(pf->T_EOF!=-1)) {			tmps[i]=ch;			ch=getch(pf);			if (pf->T_EOF==1) goto errormsg;			i++;		}		date=strdup(tmps);		if ( iversion > 0 ) {			ch=getch(pf);			i=0;			memset (tmps, 0, 1024);			while ((ch!=EOW)&&(pf->T_EOF!=-1)) {				tmps[i]=ch;				ch=getch(pf);				if (pf->T_EOF==1) goto errormsg;				i++;			}			uidl=strdup(tmps);		}		id=message_add_new (fl, seek, size, hsize, flags, time, folder);				msgs=message_seek (fl, id);		msgs->rfolder=strdup (fl->name);		msgs->from=strdup (from);		msgs->subject=strdup (subject);		/* Priority support added by trey */		if( iversion > 1 ) {		  msgs->priority=strdup(priority);		} else msgs->priority=strdup("3");		if (iversion > 3)		{			if (replyto) msgs->replyto = strdup (replyto);		}		if (iversion > 3)		{			if (sensitivity) msgs->sensitivity = strdup (sensitivity);		}		if (iversion > 5)                {                        if (expiry) msgs->expiry = strdup (expiry);                }		if (iversion > 5)                {                        if (replyby) msgs->replyby = strdup (replyby);                }		if ( iversion > 2 ) {		  msgs->keywords=strdup(keywords);		}		msgs->date=strdup (date);		if ( iversion > 0 ) {			msgs->uidl=strdup (uidl);		}		ch=getch (pf);		if (ch!=-1) ungetch(pf);		if (folder!=NULL) free (folder);		if (from!=NULL) free (from);		if (subject!=NULL) free (subject);		if (date!=NULL) free (date);		if (uidl!=NULL) free (uidl);		if (keywords!=NULL) free (keywords);		if (sensitivity!=NULL) free (sensitivity);		if (replyby!=NULL) free (replyby);		if (expiry!=NULL) free (expiry);		if (replyto!=NULL) free (replyto);		if (priority!=NULL) free (priority);	}	goto ending;errorhead:	printf ("index file header crouption, discarding\n");	fl->flags=F_INDEX_HEAD_CORRUPT;	goto ending;errormsg:	printf ("error occured while reading message index, destroying list\n");	message_list_destroy (fl);	if (folder!=NULL) free (folder);	if (from!=NULL) free (from);	if (subject!=NULL) free (subject);	if (date!=NULL) free (date);ending:	if (tmps!=NULL) free (tmps);}void folders_write_index () {	Folder *flist=folder_list;	pfile *pf;	char *tmps;	char *home;	home=(char *)calloc(1024, sizeof(char));	snprintf (home, 1024, "$(HOME)/.tradeclient");	env_srch_rep (home);	tmps=(char *)calloc(1024, sizeof(char));	if (flist!=NULL) {		while (flist) {			if ((flist->flags&F_INDEX_MISSING)==0) {	 			pf=new_pfile();				snprintf (tmps, 1024, "%s/.%s.smi", home, flist->name);				strcpy( pf->name, tmps ) ;				pf->fs=fopen (tmps, "w+");#if 1				index_write (pf, flist);#else				new_index_write( pf, flist ) ;#endif				fclose (pf->fs);				delete_pfile( pf ) ;			}			flist=flist->next;		}	}	free (home);	free (tmps);}void folders_read_index () {  pfile *pf;  char *home;  char *tmps;  Folder *flist=folder_list;  home=(char *)calloc(1024, sizeof(char));  snprintf (home, 1024, "$(HOME)/.tradeclient");  env_srch_rep (home);  tmps=(char *)calloc(1024, sizeof(char));  if (flist!=NULL) {    while (flist) {      pf=new_pfile();      snprintf (tmps, 1024, "%s/.%s.smi", home, flist->name);      strcpy( pf->name, tmps ) ;      pf->fs=fopen (tmps, "r");      if (pf->fs!=NULL) {#if 1	index_read (pf, flist);#else	new_index_read( pf, flist ) ;#endif	fclose (pf->fs);	flist->flags&=~F_INDEX_MISSING;	delete_pfile( pf ) ;      } else {	flist->flags|=F_INDEX_MISSING;	delete_pfile( pf ) ;      }      flist=flist->next;    }  }  free (tmps);  free (home);  return ;}int message_hsize (char *message) {	int i=0, len=strlen(message);#ifdef DMALLOC	dmalloc_verify( 0 ) ;#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -