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

📄 filefolderc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 2 页
字号:
//// Read in the new data//   Lock(True);   int	oldMsgCount = NewMsgCount();   if ( scanned ) ScanNew();   else		  Scan();   int	newMsgCount = NewMsgCount() - oldMsgCount;   newMail = (newMsgCount > 0);   Lock(False);   if ( newMail && !ishApp->exiting )      UpdateIcon();   if ( debuglev > 1 && newMsgCount > 0 ) {      cout <<newMsgCount <<" new message";      if ( newMsgCount > 1 ) cout <<"s";      cout <<endl;   }   return newMail;} // End NewMail/*------------------------------------------------------------------------ * Method to save the folder.  Used to update status, get rid of deleted *    messages and renumber remaining ones. */BooleanFileFolderC::Save(){   if ( !writable ) return False;   if ( debuglev > 0 ) cout <<"Saving folder: "<<name NL;   Lock(True);   if ( !scanned ) Scan();//// Gather all new mail before saving.  This is not necessary if we're using//    a POP server.//   if ( !isInBox || !ishApp->appPrefs->usingPop ) {      while ( NewMail() );   }//// See how much space is needed.  Also mark new messages as unread at this time//   StringC	statusStr;   statusStr = abbrev;   statusStr += " - Checking space ...";   ishApp->mainWin->Message(statusStr);   u_long	needed = 0;   unsigned	count = msgList->size();   int i=0; for (i=0; i<count; i++) {      FilePartMsgC	*msg  = (FilePartMsgC*)(*msgList)[i];      if ( msg->IsDeleted() ) continue;      if ( msg->IsNew() && ishApp->appPrefs->markNewAsUnread )	 msg->ClearStatus(MSG_NEW, False/*Don't update index file*/);      needed += msg->SpaceNeeded();   } // End for each message   if ( debuglev > 0 ) cout <<"need " <<needed <<" bytes for folder" <<endl;   StringC	saveFile;   Boolean	renameOk;   if ( !CreateSaveFile(needed, saveFile, &renameOk) ) {      if ( active && !ishApp->exiting ) ishApp->mainWin->MsgVBox().Refresh();      Lock(False);      return False;   }//// Loop through messages and write them out//   if ( debuglev > 0 ) cout <<"Writing messages" <<endl;//// Open original file for reading//   if ( !OpenFile() ) {      Lock(False);      return False;   }//// Open save file for writing//   FILE	*savefp = fopen(saveFile, "w+");   if ( !fp ) {      StringC   errmsg("Could not open file: ");      errmsg += saveFile;      errmsg += "\n";      errmsg += SystemErrorMessage(errno);      halApp->PopupMessage(errmsg);      CloseFile();      Lock(False);      return False;   }   int		err    = 0;   int		wcount = 0;   Boolean	needRescan = False;   for (i=0; !err && i<count; i++) {      if ( wcount%10 == 0 ) {	 statusStr = abbrev;	 statusStr += " - Writing messages: ";	 statusStr += wcount;	 ishApp->mainWin->Message(statusStr);      }      FilePartMsgC	*msg  = (FilePartMsgC*)(*msgList)[i];      if ( msg->IsDeleted() ) continue;// If there are any file messages in the folder, we'll have to rescan      if ( msg->IsFile() ) needRescan = True;      if ( WriteMessage(msg, savefp) ) wcount++;      else			       err = errno;   } // End for each message   statusStr = abbrev;   statusStr += " - Writing messages: ";   statusStr += wcount;   ishApp->mainWin->Message(statusStr);   CloseFile();   fclose(savefp);//// See if write was successful.//   if ( err ) {      StringC	errmsg("Could not save folder: ");      errmsg += name;      errmsg += ".\n";      errmsg += SystemErrorMessage(err);      halApp->PopupMessage(errmsg);      if ( active && !ishApp->exiting ) ishApp->mainWin->MsgVBox().Refresh();      Lock(False);      return False;   }//// If the folder is a link, get the name of the real file.//   StringC	realFile = name;   struct stat	lstats;   if ( lstat(name, &lstats) == 0 && S_ISLNK(lstats.st_mode) ) {      realFile = FullPathname(name);      if ( debuglev > 0 ) cout <<"Folder is a link to: " <<realFile <<endl;   }//// Update original file.//   StringC	errmsg;   if ( unlink(realFile) != 0 ) {      err = errno;      errmsg = "Could not unlink folder: ";      errmsg += realFile;      errmsg += ".\n";   }   if ( !err ) {      if ( renameOk ) {	 if ( debuglev > 0 )	    cout <<"Updating original file using rename()" <<endl;	 if ( rename(saveFile, realFile) != 0 ) {	    err = errno;	    errmsg = "Could not rename folder: ";	    errmsg += saveFile;	    errmsg += "\nto: ";	    errmsg += realFile;	    errmsg += ".\n";	 }      }      else {	 if ( debuglev > 0 ) cout <<"Updating original file using cp()" <<endl;	 StringC	cmd("cp ");	 cmd += saveFile;	 cmd += " ";	 cmd += realFile;	 err = System(cmd);	 if ( err != 0 ) {	    errmsg = "Could not copy folder: ";	    errmsg += saveFile;	    errmsg += "\nto: ";	    errmsg += realFile;	    errmsg += ".\n";	 }	 else	    unlink(saveFile);      }   }   if ( err != 0 ) {      errmsg += SystemErrorMessage(err);      errmsg += "\n\nChanges are in: ";      errmsg += saveFile;      halApp->PopupMessage(errmsg);      if ( active && !ishApp->exiting ) ishApp->mainWin->MsgVBox().Refresh();      Lock(False);      return False;   }//// Get fresh stats//   if ( stat(name, &stats) != 0 ) stats.st_size  = 0;//// Set the access time equal to the modification time to other mailcheck//    programs don't think there is new mail.//   struct utimbuf	times;	// access time, mod time   times.actime  = stats.st_mtime;   times.modtime = stats.st_mtime;   utime(name, &times);   if ( needRescan ) {       Rescan();   }   else {//// Remove deleted messages from display//       if ( active && !ishApp->exiting ) {	  ishApp->mainWin->MsgVBox().RemoveItems(*delItemList);	  if ( ishApp->undelWin ) ishApp->undelWin->Clear();       }//// Get rid of deleted messages and update message numbers and file offsets//       int	num = 1;       count = msgList->size();       for (i=0; i<count; i++) {	  FilePartMsgC	*msg  = (FilePartMsgC*)(*msgList)[i];	  if ( msg->IsDeleted() ) {	     if ( debuglev > 1 )		cout <<"   removing message: " <<msg->Number() <<endl;	     delete msg;	     msgList->replace(NULL, i);	  }	  else {	     msg->SetNumber(num++);	     msg->UpdateOffsets();	  }       }       msgList->removeNulls();       delItemList->removeAll();//// Update display//       if ( active && !ishApp->exiting ) {	  if ( SortMgr()->Threaded() ) ishApp->mainWin->MsgVBox().Sort();       }       SetChanged(False);//// Rebuild index file//       CreateIndex();       UpdateIcon();   } // End if we don't need to rescan   Lock(False);   if ( debuglev > 0 ) cout <<"Folder save complete" <<endl;   if ( active && !ishApp->exiting ) ishApp->mainWin->MsgVBox().Refresh();      return True;} // End Save/*------------------------------------------------------------------------ * Method to create a save file.  It will be created in the tmp directory *    if there is not enough space on the same filesystem as the folder. */BooleanFileFolderC::CreateSaveFile(u_long needed, StringC& saveFile, Boolean *renameOk){   saveFile  = name + ".ish-sav";   *renameOk = True;   if ( !OpenFile() ) return False;   struct STATFS	fsbuf;   int	status = FSTATFS(fileno(fp), &fsbuf);   u_long	srcfsid = GET_FS_ID(fsbuf.f_fsid);   u_long	dstfsid = srcfsid;   CloseFile();//// See if we need to use a temp file.//   u_long	avail = fsbuf.f_bavail * fsbuf.f_bsize;   if ( status != 0 || avail < needed ) {      char	*cs = tempnam(NULL, "save.");      saveFile = cs;      free(cs);      *renameOk = False;   }//// Try to create the save file//   FILE	*savefp = fopen(saveFile, "w+");   if ( !savefp ) {      int	err = errno;      StringC	errmsg("Could not create save file for folder: ");      errmsg += name;      errmsg += ".\n";      errmsg += SystemErrorMessage(err);      halApp->PopupMessage(errmsg);      return False;   }   fclose(savefp);   if ( !*renameOk ) {//// Get the file system status again//      status = STATFS(saveFile, &fsbuf);      srcfsid = GET_FS_ID(fsbuf.f_fsid);      avail = fsbuf.f_bavail * fsbuf.f_bsize;//// See if we can use the temp file//      if ( status != 0 || avail < needed ) {	 StringC	errmsg("There is not enough space in the ");	 errmsg += "folder directory or the temp directory to save: ";	 errmsg += name;	 errmsg += ".\nPlease free up some space before saving this folder.";	 halApp->PopupMessage(errmsg);	 unlink(saveFile);	 return False;      }      *renameOk = (dstfsid == srcfsid);   } // End if not enough space in mail spool   if ( debuglev > 0 ) cout <<"Save file is: " <<saveFile <<endl;//// Set owner and group as before//   chown(saveFile, stats.st_uid, stats.st_gid);   chmod(saveFile, stats.st_mode);   return True;} // End CreateSaveFile/*------------------------------------------------------------------------ * Method to copy the specified message into this folder */BooleanFileFolderC::AddMessage(MsgC *msg){   if ( !writable ) return False;//// Lock the file so no one else can write it//   Lock(True);//// Open the file//   if ( !OpenFile() ) {      Lock(False);      return False;   }   fseek(fp, 0, SEEK_END);//// Write the message//   if ( !WriteMessage(msg, fp) ) {      CloseFile();      Lock(False);      StringC	errmsg("Could not save message to folder: ");      errmsg += name;      errmsg += ".\n";      errmsg += SystemErrorMessage(errno);      halApp->PopupMessage(errmsg);      return False;   }//// Read the new message//   if ( scanned ) NewMail();   UpdateIcon();   CloseFile();   Lock(False);   return True;} // End AddMessage/*------------------------------------------------------------------------ * Method to add a new message to this folder */BooleanFileFolderC::AddMessage(StringListC& headList, char *bodyFile){   if ( !writable ) return False;//// Lock the file so no one else can write it//   Lock(True);//// Open the file//   if ( !OpenFile() ) {      Lock(False);      return False;   }   fseek(fp, 0, SEEK_END);//// Write the message//   if ( !WriteMessage(headList, bodyFile, fp) ) {      CloseFile();      Lock(False);      StringC	errmsg("Could not save message to folder: ");      errmsg += name;      errmsg += ".\n";      errmsg += SystemErrorMessage(errno);      halApp->PopupMessage(errmsg);      return False;   }   CloseFile();//// Read the new message//   if ( scanned ) NewMail();   UpdateIcon();   Lock(False);   return True;} // End AddMessage

⌨️ 快捷键说明

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