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

📄 ishappp.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *  $Id: IshAppP.C,v 1.9 2000/08/07 11:05:16 evgeny Exp $ *   *  Copyright (c) 1994 HAL Computer Systems International, Ltd. *  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. *                  1315 Dell Avenue *                  Campbell, CA  95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * http://www.gnu.org/copyleft/gpl.html * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */#include <config.h>#include "IshAppP.h"#include "IshAppC.h"#include "SigPrefC.h"#include "MailPrefC.h"#include "MailFile.h"#include "AlertPrefC.h"#include "AppPrefC.h"#include "FolderC.h"#include "FolderPrefC.h"#include "MainWinC.h"#include "Query.h"#include "ReadWinC.h"#include "SendWinC.h"#include "CompPrefC.h"#include "ishmail.xpm"#include "ishmail_info.xpm"#include "ishmail_question.xpm"#include "ishmail_warning.xpm"#include "ishmail_error.xpm"#include <hgl/CharC.h>#include <hgl/StringC.h>#include <hgl/StringListC.h>#include <hgl/PixmapC.h>#include <hgl/WXmString.h>#include <hgl/WArgList.h>#include <hgl/RowColC.h>#include <hgl/SysErr.h>#include <hgl/TextMisc.h>#include <hgl/rsrc.h>#include <hgl/VBoxC.h>#include <Xm/MessageB.h>#include <Xm/SelectioB.h>#include <Xm/Label.h>#include <Xm/Protocols.h>#include <Xm/TextF.h>#include <Xm/RowColumn.h>#include <Xm/Frame.h>#include <Xm/ToggleB.h>#include <Xm/AtomMgr.h>#include <Xm/PushB.h>#include <unistd.h>#include <errno.h>/*---------------------------------------------------------------------- * Constructor */IshAppP::IshAppP(IshAppC *ia){   pub              = ia;   messagePM        = NULL;   warningPM        = NULL;   questionPM       = NULL;   errorPM          = NULL;   checkTimer       = (XtIntervalId)NULL;   lastMailCheck    = 0;} // End constructor/*---------------------------------------------------------------------- * Destructor */IshAppP::~IshAppP(){   delete messagePM;   delete warningPM;   delete questionPM;   delete errorPM;}/*--------------------------------------------------------------- * See if "Ishmail" needs to be added to beginning of resources.  Prior to *    version 1.1 we thought we didn't need it, but it looks like we really *    do. * Also check for duplicate lines.  If there are any, keep the last. */  voidIshAppP::FixIshmailrc(){   StringC	data;   if ( !data.ReadFile(pub->resFile) ) return;//// See if we need to add the "Ishmail*" prefix//   Boolean	addPrefix  = !data.Contains("\nIshmail*");//// See if we need to fix the "Ishmail**" prefix//   Boolean	fixPrefix  = data.Contains("\nIshmail**");//// See if we need to remove width and height resources//   Boolean	fixSize = (data.Contains("mainShell.width:")	||			   data.Contains("mainShell.height:")	||			   data.Contains("viewDA.width:")	||			   data.Contains("viewDA.height:")	||			   data.Contains("sendWin.width:")	||			   data.Contains("sendWin.height:")	||			   data.Contains("readWin.width:")	||			   data.Contains("readWin.height:")	||			   data.Contains("msgBox*scrollForm.height:")	||			   data.Contains("msgBox*taskVBox.height:"));//// See if we need to change from font to fontList in the viewDA//   Boolean	fixFont  = !data.Contains("viewDA.fontList:");//// See if we need to remove duplicate lines//   Boolean	removeDups = HasDuplicateLines(data);   if ( !addPrefix && !fixPrefix && !fixSize && !removeDups && !fixFont )      return;//// Break the resources into lines//   StringListC	lineList;   GetResLines(data, lineList, removeDups);//// Remove all .width and .height resources for main windows//   if ( fixSize ) {      if ( debuglev > 0 )	 cout <<"Removing bogus width and height resources." <<endl;      u_int	count = lineList.size();      int i=count-1; for (i=count-1; i>=0; i--) {	 StringC	*line = lineList[i];	 if ( (line->Contains(".width:") || line->Contains(".height:")) &&	      (line->Contains("mainShell.width:")	||	       line->Contains("mainShell.height:")	||	       line->Contains("viewDA.width:")		||	       line->Contains("viewDA.height:")		||	       line->Contains("sendWin.width:")		||	       line->Contains("sendWin.height:")	||	       line->Contains("readWin.width:")		||	       line->Contains("readWin.height:")	||	       line->Contains("msgBox*scrollForm.height:")	||	       line->Contains("msgBox*taskVBox.height:")) ) {	    lineList.remove(i);	 }      }   }   if ( addPrefix ) {      if ( debuglev > 0 ) cout <<"Adding Ishmail* prefix" <<endl;//// Add "Ishmail" to the beginning of any lines that don't have it//      u_int	count = lineList.size();      int i=0; for (i=0; i<count; i++) {	 StringC	*line = lineList[i];//// See if the line needs to be updated//	 if ( line->StartsWith("*") )	    (*line)(0,0) = "Ishmail";      }   } // End if prefix needed   if ( fixPrefix ) {      if ( debuglev > 0 ) cout <<"Adding Ishmail* prefix" <<endl;//// Change "Ishmail**" to "Ishmail*"//      u_int	count = lineList.size();      int i=0; for (i=0; i<count; i++) {	 StringC	*line = lineList[i];//// See if the line needs to be updated//	 if ( line->StartsWith("Ishmail**") )	    (*line)(7,1) = "";      }   } // End if prefix fix needed   if ( fixFont ) {      if ( debuglev > 0 )	 cout <<"Changing viewDA.font to viewDA.fontList" <<endl;//// Change "viewDA.font:" to "viewDA.fontList:"//      u_int	count = lineList.size();      int i=0; for (i=0; i<count; i++) {	 StringC	*line = lineList[i];//// See if the line needs to be updated//	 if ( line->StartsWith("Ishmail*viewDA.font:") )	    (*line)(19,0) = "List";      }   } // End if font fix needed//// Write out the resources//   WriteResFile(lineList);} // End FixIshmailrc/*--------------------------------------------------------------- * See if mapped resource file contains any duplicate lines */  BooleanIshAppP::HasDuplicateLines(CharC data){//// Loop through lines//   u_int	offset = 0;   CharC	line = data.NextWord(offset, "\n");   while ( line.Length() > 0 ) {      offset = line.Addr() - data.Addr() + line.Length();      if ( line.StartsWith('*') || line.StartsWith("Ishmail*") ) {//// Remove the value portion of the resource //	 int	pos = line.PosOf(':');	 if ( pos >= 0 ) {	    line = line(0,pos+1);//// Now look from here to the end to see if there is any copy of this line//	    pos = data.PosOf(line, offset);	    if ( pos > 0 && data[pos-1] == '\n' )	       return True;	 }      }//// Read the next line//      line = data.NextWord(offset, "\n");   } // End for each line in file      return False;} // End HasDuplicateLines/*--------------------------------------------------------------- *  Function to read the resource lines from the given text data */voidIshAppP::GetResLines(CharC data, StringListC& lineList, Boolean removeDups){   if ( debuglev > 0 && removeDups ) cout <<"Removing duplicate lines" <<endl;   lineList.removeAll();   lineList.AllowDuplicates(TRUE);   StringC	line;   CharC	word;   u_int	offset = 0;   int		pos = data.PosOf('\n', offset);   while ( pos >= 0 ) {      word = data(offset, (u_int)pos-offset);      offset = pos + 1;//// If the newline is escaped, read some more.//      if ( word.EndsWith("\\") ) {	 word.CutEnd(1);	 line += word;      }      else {	 line += word;	 if ( removeDups ) {	    StringC	*lineP = FindLine(lineList, line);	    if ( lineP ) *lineP = line;	    else	 lineList.add(line);	 }	 else	    lineList.add(line);	 line.Clear();      }      pos = data.PosOf('\n', offset);   } // End for each line in file} // End GetResLines/*--------------------------------------------------------------- *  Function to see if the specified line already exists in the line list */StringC*IshAppP::FindLine(StringListC& list, CharC res){   if ( !res.StartsWith('*') && !res.StartsWith("Ishmail*") ) return NULL;//// Remove the value portion of the resource //   int	pos = res.PosOf(':');   if ( pos < 0 ) return NULL;   res = res(0,pos+1);//// Loop through the line list and see if any line starts with this resource//   u_int	count = list.size();   int i=0; for (i=0; i<count; i++) {      StringC	*line = list[i];      if ( line->StartsWith(res) ) return line;   }   return NULL;} // End FindLine/*--------------------------------------------------------------- *  Function to write the .ishmailrc file from a list of lines */BooleanIshAppP::WriteResFile(StringListC& lineList){   if ( debuglev > 0 ) cout <<"Writing resource file: " <<pub->resFile <<endl;//// Write the information back to the file//   FILE *fp = fopen(pub->resFile, "w");   if ( !fp ) {      StringC	errmsg = "Could not open resource file: ";      errmsg += pub->resFile;      errmsg += '\n';      errmsg += SystemErrorMessage(errno);      halApp->PopupMessage(errmsg);      return False;   }   CharC	nl("\n");   unsigned	count = lineList.size();   Boolean	error = False;   int i=0; for (i=0; !error && i<count; i++) {      StringC	*line = lineList[i];//// See if the line needs to be split//      if ( line->StartsWith("Ishmail*alerts:")		||	   line->StartsWith("Ishmail*icons:")		||	   line->StartsWith("Ishmail*saveRules:")	||	   line->StartsWith("Ishmail*folderSortKeys:")	||	   line->StartsWith("Ishmail*automaticFilingRules:") )	 error = !WriteRules(fp, *line);      else	 error = !line->WriteFile(fp);      if ( !error ) error = !nl.WriteFile(fp);   }   if ( !error ) error = (fclose(fp) != 0);   if ( error ) {      StringC	errmsg = "Could not write resource file: ";      errmsg += pub->resFile;      errmsg += '\n';      errmsg += SystemErrorMessage(errno);      halApp->PopupMessage(errmsg);   }   return !error;} // End WriteResFile/*--------------------------------------------------------------- *  Write a resource that represents a rule dictionary and add line breaks. */BooleanIshAppP::WriteRules(FILE *fp, StringC& line){//// Add a newline after the first : and then after each successive ;//   char		*start = line;   char		*end   = start + line.size();   char		*cp    = strchr(start, ':');   Boolean	error  = False;   while ( !error && cp ) {//// Skip found character and following whitespace//      cp++;      while ( cp < end && isspace(*cp) ) cp++;      int	len = cp - start;//// Write up to this point, then write an escaped newline if there's more//    text to come//

⌨️ 快捷键说明

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