📄 mhfolderc.c
字号:
unsigned count = msgList->size(); int wcount = 0; int i=0; for (i=0; i<count; i++) { if ( wcount%10 == 0 ) { statusStr = "Saving "; statusStr = abbrev; statusStr += " - "; statusStr += wcount; statusStr += " messages"; ishApp->mainWin->Message(statusStr); } MhMsgC *msg = (MhMsgC*)(*msgList)[i]; if ( msg->IsDeleted() ) continue; if ( msg->IsNew() && ishApp->appPrefs->markNewAsUnread ) msg->ClearStatus(MSG_NEW, False/*Don't update index file*/); if ( msg->IsChanged() ) { if ( debuglev > 0 ) cout <<" updating file: " <<msg->filename <<endl; if ( Save(msg) ) wcount++; } else wcount++; } // End for each message statusStr = "Saving "; statusStr = abbrev; statusStr += " - "; statusStr += wcount; statusStr += " messages"; ishApp->mainWin->Message(statusStr);//// 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// count = msgList->size(); for (i=0; i<count; i++) { MhMsgC *msg = (MhMsgC*)(*msgList)[i]; if ( !msg->IsDeleted() ) continue; if ( debuglev > 1 ) cout <<" removing message: " <<msg->Number() <<endl; msg->deleteFile = True; delete msg; msgList->replace(NULL, i); } msgList->removeNulls(); delItemList->removeAll();//// Update display// if ( active && !ishApp->exiting ) { if ( SortMgr()->Threaded() ) ishApp->mainWin->MsgVBox().Sort(); ishApp->mainWin->MsgVBox().Refresh(); }//// Rebuild index file// CreateIndex(); NewMail(); SetChanged(False); UpdateIcon(); if ( debuglev > 0 ) cout <<"Folder save complete" <<endl; return True;} // End Save/*------------------------------------------------------------------------ * Method to save the specified message */BooleanMhFolderC::Save(MhMsgC *msg){//// Create a save file.// StringC saveFile = msg->filename; saveFile += ".ish-sav"; if ( !msg->WriteFile(saveFile, /*copyHead=*/True, /*allHead=*/True, /*statHead=*/True, /*addBlank=*/False, /*protectFroms=*/False) ) return False; int err = 0;//// Apply original owner and group to new file// struct stat idBuf; if ( err == 0 && stat(msg->filename, &idBuf) != 0 ) err = errno; if ( err == 0 && chown(saveFile, idBuf.st_uid, idBuf.st_gid) != 0 ) err = errno; if ( err == 0 && chmod(saveFile, idBuf.st_mode) != 0 ) err = errno; if ( err == 0 && unlink(msg->filename) != 0 ) err = errno; if ( err == 0 && rename(saveFile, msg->filename) != 0 ) err = errno; if ( err != 0 ) { StringC errmsg("Could not save message: "); errmsg += BaseName(msg->filename); errmsg += " in folder: "; errmsg += name; errmsg += ".\n"; errmsg += SystemErrorMessage(err); halApp->PopupMessage(errmsg); return False; } MsgPartC *body = msg->Body(); body->headScanned = False; body->bodyScanned = False; return True;} // End Save/*------------------------------------------------------------------------ * Method to copy the specified message into this folder */BooleanMhFolderC::AddMessage(MsgC *msg){//// Before we start, see if the index is valid// Boolean indexValid = IndexValid();//// Create a new file. GetNextMsgFile generates a unique name// StringC file; GetNextMsgFile(file); if ( !msg->WriteFile(file, /*copyHead=*/True, /*allHead=*/True, /*statHead=*/True, /*addBlank=*/False, /*protectFroms=*/False) ) return False;//// If the index is valid, add an entry// if ( indexValid ) AddIndexEntry(msg->status, msg->BodyBytes(), msg->BodyLines(), msg->Id()); if ( scanned ) NewMail(); else { StringC numStr; int spos = file.RevPosOf('/'); if ( spos >= 0 ) numStr = file(spos+1, file.length()); else numStr = file; dirList.add(atoi(numStr)); stat(name, &stats); UpdateIcon(); } return True;} // End AddMessage/*------------------------------------------------------------------------ * Method to copy the specified message into this folder */BooleanMhFolderC::AddMessage(StringListC& headList, char *bodyFile){//// Create a new file. GetNextMsgFile generates a unique name// StringC file; GetNextMsgFile(file); FILE *fp = fopen(file, "w"); if ( !fp ) { StringC errmsg("Could not create file: "); errmsg += file; errmsg += "\n" + SystemErrorMessage(errno); halApp->PopupMessage(errmsg); return False; } if ( !WriteHeaders(headList, file, /*addBlank=*/True, fp) ) return False; if ( !CopyFile(bodyFile, file, False/*add blank*/, False/*protect Froms*/, NULL, fp) ) return False; if ( scanned ) NewMail(); else { stat(name, &stats); UpdateIcon(); } return True;} // End AddMessage/*------------------------------------------------------------------------ * Method to check for new mail */BooleanMhFolderC::NewMail(){ if ( debuglev > 1 ) cout <<"Checking for new mail in folder " <<name <<endl; Boolean newMail = False;//// If the folder changed while we were asleep, reread it.// if ( changedWhileSleeping && !ishApp->sleeping ) { Rescan(); newMail = HasNewMessages(); if ( newMail && !ishApp->exiting ) UpdateIcon(); changedWhileSleeping = False; return newMail; }//// Get the status of the directory// struct stat newStats; if ( stat(name, &newStats) != 0 ) { int err = errno; if ( ishApp->sleeping ) changedWhileSleeping = True;//// If the directory is gone but was there before, this is a problem.// else if ( err == ENOENT && stats.st_size > 0 ) { StringC errmsg = "Mail folder "; errmsg += name; errmsg += " has disappeared.\n"; errmsg += "The last time we checked, it had a size of "; errmsg += (int)stats.st_size; errmsg += " bytes."; halApp->PopupMessage(errmsg, XmDIALOG_WARNING); Reset(); MakeDir(name); stat(name, &stats); } // End if dir was there before else if ( err != ENOENT ) { StringC errmsg = "Mail folder "; errmsg += name; errmsg += " could not be checked:\n"; errmsg += SystemErrorMessage(err); halApp->PopupMessage(errmsg, XmDIALOG_ERROR); } return False; } // End if folder can't be stat'd//// Check times// if ( newStats.st_mtime == stats.st_mtime ) return False; if ( debuglev > 1 ) cout <<"Directory changed." <<endl; stats = newStats; if ( ishApp->sleeping ) { changedWhileSleeping = True; return True; }//// Everything looks good, so lets pull in the new data// int oldMsgCount = NewMsgCount(); Scan(); int newMsgCount = NewMsgCount() - oldMsgCount; newMail = (newMsgCount > 0); 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 find the next available file name in an MH folder */voidMhFolderC::GetNextMsgFile(StringC& file){//// Scan the directory just in case// ReadDirectory();//// Find the highest number in the directory list// int maxNum = 0; u_int count = dirList.size(); int i=0; for (i=0; i<count; i++) { int num = *dirList[i]; if ( num > maxNum ) maxNum = num; }//// Make sure file doesn't already exist by accident// GetMsgFile(name, maxNum+1, file); while ( access(file, F_OK) == 0 ) { maxNum++; GetMsgFile(name, maxNum+1, file); }} // End GetNextMsgFile#if 0/*--------------------------------------------------------------- * Method to mark the specified message for deletion */voidMhFolderC::MarkForDeletion(MsgC *msg){//// Try to move the file to the comma version// int oldNumber = msg->te->Number(); if ( oldNumber < 0 ) return; int newNumber = -oldNumber; StringC file = MessageFile(newNumber); if ( access(file, F_OK) == 0 ) { do { newNumber--; file = MessageFile(newNumber); } while ( access(file, F_OK) == 0 ); }//// Rename the file and get the directory stats again// msg->RenameFile(file); stat(name, &stats);//// We also need to change the number in the message summary, the table of// contents and the directory listing// if ( msg->Item() ) msg->Item()->SetNumber(newNumber); msg->te->SetNumber(newNumber); u_int count = dirList.size(); int i=0; for (i=0; i<count; i++) { int *num = dirList[i]; if ( *num == oldNumber ) { *num = newNumber; i = count; } }} // End MarkForDeletion/*--------------------------------------------------------------- * Method to undelete the specified message */voidMhFolderC::Undelete(MsgC *msg){//// Try to move the file to the non-comma version// int oldNumber = msg->te->Number(); if ( oldNumber > 0 ) return; int newNumber = -oldNumber; StringC file = MessageFile(newNumber); if ( access(file, F_OK) == 0 ) file = NextMessageFile();//// Rename the file and get the directory stats again// msg->RenameFile(file); stat(name, &stats);//// See what the new number is// int pos = file.RevPosOf('/'); file.CutBeg(pos+1); newNumber = atoi(file);//// We also need to change the number in the message summary, the table of// contents and the directory listing// if ( msg->Item() ) msg->Item()->SetNumber(newNumber); msg->te->SetNumber(newNumber); u_int count = dirList.size(); int i=0; for (i=0; i<count; i++) { int *num = dirList[i]; if ( *num == oldNumber ) { *num = newNumber; i = count; } }} // End Undelete#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -