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

📄 aliasprefc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  $Id: AliasPrefC.C,v 1.3 2000/05/07 12:26:11 fnevgeny 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 "IshAppC.h"#include "AliasPrefC.h"#include "AliasPrefWinC.h"#include "ShellExp.h"#include "Misc.h"#include "CompPrefC.h"#include "AddressC.h"#include <hgl/rsrc.h>#include <hgl/CharC.h>#include <hgl/RegexC.h>#include <hgl/RangeC.h>#include <stdio.h>/*--------------------------------------------------------------- *  Constructor */AliasPrefC::AliasPrefC() : PrefC(){   aliasWin = NULL;   groupWin = NULL;//// Example mailrc alias://	alias ishmail support@ishmail.com//   aliasPat = new RegexC("^alias[ \t]+\\([^ \t]+\\)[ \t]+\\(.*\\)");//// Example elm alias://	ishmail = Ishmail Technical Support = support@ishmail.com//   elmAliasPat = new RegexC("^\\([^= \t]+\\)[ \t]*=[ \t]*\\([^=]*\\)[ \t]*=[ \t]*\\(.*\\)");//// Example pine alias://	ishmail Ishmail Technical Support (support@ishmail.com)//   pineAliasPat = new RegexC("^\\([^\t]+\\)\t\\([^\t]*\\)\t\\((?[^)]*)?\\)");//// Used for converting aliases to mailrc format and back//   namePat  = new RegexC("\\([ \t]*\\)\\([^,]+\\),?");        aliasDict.AllowDuplicates(TRUE);        aliasDict.SetSorted(FALSE);   groupAliasDict.AllowDuplicates(TRUE);   groupAliasDict.SetSorted(FALSE);   otherAliasDict.AllowDuplicates(TRUE);   otherAliasDict.SetSorted(FALSE);//// Read resources//   mailrcFile        = ishApp->home + "/" + ".mailrc";   orig.mailrcFile   = get_string(*halApp, "mailrcFile", mailrcFile);   groupMailrcFile   = ishHome + "/lib/" + "mailrc";   orig.groupMailrcFile = get_string(*halApp, "groupMailrcFile",				     groupMailrcFile);   orig.otherAliasStr = get_string(*halApp, "otherAliasFiles");   mailrcFile      = orig.mailrcFile;		ShellExpand(mailrcFile);   groupMailrcFile = orig.groupMailrcFile;	ShellExpand(groupMailrcFile);   ExtractList(orig.otherAliasStr, otherAliasFiles);   ExpandList(otherAliasFiles);//// Read mailrc files//   ReadAliasFile(mailrcFile,      aliasDict,      False/*no others*/ );   ReadAliasFile(groupMailrcFile, groupAliasDict, False/*no others*/ );//// Read other alias files//   unsigned count = otherAliasFiles.size();   for (int i=0; i<count; i++)      ReadAliasFile(*otherAliasFiles[i], otherAliasDict, True/*allow others*/);//// Read list of aliases that are not to be expanded//   StringC	expandStr = get_string(*halApp, "hideAddresses");   ExtractList(expandStr, hideAddrList);} // End constructor/*--------------------------------------------------------------- *  destructor */AliasPrefC::~AliasPrefC(){   delete aliasPat;   delete elmAliasPat;   delete pineAliasPat;   delete namePat;   delete aliasWin;   delete groupWin;} // End destructor/*--------------------------------------------------------------- *  Method to write resources to resource database */BooleanAliasPrefC::WriteDatabase(){   Store("mailrcFile",		orig.mailrcFile);   Store("groupMailrcFile",	orig.groupMailrcFile);   Store("otherAliasFiles",	orig.otherAliasStr);   Store("sortAliases",		sortAliases);   Store("hideAddresses",	hideAddrList);   return True;} // End WriteDatabase/*--------------------------------------------------------------- *  Method to write resources to a file */BooleanAliasPrefC::WriteFile(){   if ( !WriteAliases(mailrcFile, aliasDict) )      return False;   if ( !WriteAliases(groupMailrcFile, groupAliasDict) )      return False;   StringListC	lineList;   ReadResFile(lineList);   Update(lineList, "mailrcFile",	orig.mailrcFile);   Update(lineList, "groupMailrcFile",	orig.groupMailrcFile);   Update(lineList, "otherAliasFiles",	orig.otherAliasStr);   Update(lineList, "sortAliases",	sortAliases);   Update(lineList, "hideAddresses",	hideAddrList);//// Write the information back to the file//   return WriteResFile(lineList);} // End WriteFile/*--------------------------------------------------------------- *  Method to read aliases out of a file */voidAliasPrefC::ReadAliasFile(const char *aFile, StringDictC& aDict,			  Boolean otherFmt){   if ( debuglev > 0 ) cout <<"Reading aliases from " <<aFile <<endl;   StringC	line; line.AutoShrink(False);   StringC	key;   StringC	val;   FILE	*fp = fopen(aFile, "r");   if ( !fp ) return;	// if file unreadable, don't worry about it//// Process lines in the file//   while ( line.GetLine(fp) != EOF ) {      line.Trim();	// Remove whitspace//// If the newline is escaped, read some more//      if ( line.EndsWith("\\") ) {	 line.Clear(line.size()-1);	 continue;      }//// See if this is an alias line//      if ( aliasPat->match(line) ) {	 key = line((*aliasPat)[1]);	 val = line((*aliasPat)[2]);	 ConvertMailrcToAlias(val);	 aDict.add(key, val);	 if ( debuglev > 1 )	    cout <<"   Found mailrc alias: " <<key <<": " <<val <<endl;      } // End if an alias was found//// Conditionally see if this is an elm alias line//      else if ( otherFmt && elmAliasPat->match(line) ) {	 key = line((*elmAliasPat)[1]);	 val = line((*elmAliasPat)[3]);	 RangeC	r2 = (*elmAliasPat)[2];	 if ( r2.length() > 0 ) val += " (" + line(r2) + ")";	 aDict.add(key, val);	 if ( debuglev > 1 )	    cout <<"   Found elm alias: " <<key <<": " <<val <<endl;      } // End if elm alias found//// Conditionally see if this is a pine alias line//      else if ( otherFmt && pineAliasPat->match(line) ) {	 key = line((*pineAliasPat)[1]);	 val = line((*pineAliasPat)[3]);//// If there is a left paren, make sure we've read the right paren//	 val.Trim();	 if ( val.StartsWith('(') && !val.EndsWith(')') )	    continue;	 if ( val.StartsWith('(') && val.EndsWith(')') )	    val.CutBoth(1);	 RangeC	r2 = (*pineAliasPat)[2];	 if ( r2.length() > 0 ) val += " (" + line(r2) + ")";	 aDict.add(key, val);	 if ( debuglev > 1 )	    cout <<"   Found pine alias: " <<key <<": " <<val <<endl;      } // End if pine alias found      line.Clear();   } // End while not EOF   fclose(fp);} // End ReadAliasFile/*--------------------------------------------------------------- *  Method to remove unnecessary quotes from alias strings and to add commas */voidAliasPrefC::ConvertMailrcToAlias(StringC& val){//// Add commas//   AddAliasCommas(val);//// Loop through addresses//   CharC	name;   int		findPos, startPos = 0;   RangeC	range0, range2;   while ( (findPos=namePat->search(val,startPos)) >= 0 ) {      range0 = (*namePat)[0];      range2 = (*namePat)[2];      startPos = findPos + range0.length();      name = val(range2);//// If this alias starts and ends with quotes, remove them//      if ( (name.StartsWith('"')  && name.EndsWith('"')) ||           (name.StartsWith('\'') && name.EndsWith('\'')) ) {	 name.CutBoth(1);	 val(range2) = name;	 startPos -= 2;      }   } // End for each address in the alias   } // End ConvertMailrcToAlias/*--------------------------------------------------------------- *  Method to add necessary commas to alias string *     address *    <address> *   "<address>  comment" *   "<address> (comment)" *    "comment  <address>" *   "(comment) <address>" *    "comment  <address>  comment" *    "comment  <address> (comment)" *   "(comment) <address>  comment" *   "(comment) <address> (comment)" *    "address  (comment)" *   "(comment)  address" */voidAliasPrefC::AddAliasCommas(StringC& inStr){   StringC	outStr;   unsigned	count = inStr.size();   int		comment = 0;   Boolean	gotSpace = False;   char		lastChar = 0;   Boolean	squoted = False;   Boolean	dquoted = False;   for (int i=0; i<count; i++ ) {      char	c = inStr[i];      switch (c) {         case '(':	    comment++;	    if ( gotSpace ) {	       outStr += (char)' ';	       gotSpace = False;	    }	    outStr += c;	    lastChar = c;

⌨️ 快捷键说明

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