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

📄 aliasprefc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	    break;	 case ')':	    if ( comment>0 ) {	       comment--;	       outStr += c;	       lastChar = c;	    }	    gotSpace = False;	    break;	 case ' ':	 case '\t':	    if ( comment==0 && !squoted && !dquoted ) gotSpace = True;	    else {	       outStr += c;	       lastChar = c;	    }	    break;	 default:	    if ( gotSpace ) {	       if ( lastChar != 0 ) {		  if ( lastChar != ',' ) outStr += (char)',';		  outStr += (char)' ';	       }	       gotSpace = False;	    }	    if      ( c == '"'  ) dquoted = !dquoted;	    else if ( c == '\'' ) squoted = !squoted;	    outStr += c;	    lastChar = c;      } // End switch current character   } // End for each character//// Check for space in last character//   if ( gotSpace ) outStr += (char)' ';//// Return the resulting string//   inStr = outStr;} // End AddAliasCommas/*--------------------------------------------------------------- *  Method to write resources to a file */BooleanAliasPrefC::WriteAliases(const char *file, StringDictC& dict){   StringListC	lineList;//// Try to open file for reading and writing//   if ( debuglev > 0 ) cout <<"Opening mailrc file: " <<file <<endl;   FILE	*fp = fopen(file, "r+");//// If the file was opened, read the lines into a list//   if ( fp ) {      StringC	line;      lineList.AllowDuplicates(TRUE);      while ( line.GetLine(fp) != EOF ) {//// If the newline is escaped, read some more.//	 if ( line.EndsWith("\\") )	    line.Clear(line.size()-1);	 else {	    lineList.add(line);	    line.Clear();	 }      }      fclose(fp);   } // End if file found   UpdateAliases(lineList, dict);//// Write the information back to the file//   fp = fopen(file, "w");   if ( !fp ) return False;   unsigned	count = lineList.size();   for (int i=0; i<count; i++)      fprintf(fp, "%s\n", (char *)(*lineList[i]));   fclose(fp);   return True;} // End WriteAliases/*--------------------------------------------------------------- *  Method to update the resource line list */voidAliasPrefC::UpdateAliases(StringListC& lineList, StringDictC& dict){//// Remove any alias lines that aren't in the dictionary//   unsigned	lcount = lineList.size();   StringC	key;   for (int l=lcount-1; l>=0; l--) {      StringC	*line = lineList[l];      StringC	*prev = (l>0) ? lineList[l-1] : (StringC*)NULL;      if ( aliasPat->match(*line) ) {	 key = (*line)((*aliasPat)[1]);	 if ( !dict.includes(key) ) {	    lineList.remove(l);	 } // End if alias not in dictionary      } // End if line is an alias   } // End for each line//// Modify any lines that have changed or add any that are missing//   unsigned	acount = dict.size();   StringC	val;   for (int a=0; a<acount; a++) {      StringC&	key = dict[a]->key;      val = dict[a]->val;//// Add quotes to value where needed and remove commas//      ConvertAliasToMailrc(val);//// Look at each line//      lcount = lineList.size();      Boolean	found = False;      for (int l=0; !found && l<lcount; l++) {	 StringC	*lineP = lineList[l];	 if ( aliasPat->match(*lineP) && (*lineP)((*aliasPat)[1]) == key ) {//// Found a match//	    if ( debuglev > 0 ) cout <<"   Modifying line: " <<*lineP <<endl;	    *lineP = "alias " + key + "\t" + val;	    if ( debuglev > 0 ) cout <<"   New line is   : " <<*lineP <<endl;	    found = True;	 }      } // End for each line//// Add a new line if none was found//      if ( !found ) {	 StringC	line = "alias " + key + "\t" + val;	 lineList.add(line);	 if ( debuglev > 0 ) cout <<"   Added new line" <<endl;      }   } // End for each alias} // End UpdateAliases/*--------------------------------------------------------------- *  Function to add quotes to alias strings and to remove commas */voidAliasPrefC::ConvertAliasToMailrc(StringC& val){//// Look through names//   StringC	name;   int		findPos, startPos = 0;   int		commaPos;   RangeC	range0;   RangeC	range1;   RangeC	range2;   while ( (findPos=namePat->search(val,startPos)) >= 0 ) {      range0 = (*namePat)[0];      range1 = (*namePat)[1];      range2 = (*namePat)[2];      startPos = findPos + range0.length();      commaPos = range0.lastIndex();      name = val(range2);//// If the name contains whitespace, it must be quoted.  Doing this will also//    remove any commas//      if ( (strchr((char *)name, ' ') || strchr((char *)name, '\t')) && name[0] != '"' ) {	 val(range0) = val(range1) + "\"" + name + "\"";	 startPos += 2;      }//// Remove the comma if present//      else if ( val[commaPos] == ',' ) {//// Make sure there's whitespace after//	 if ( commaPos+1 < val.size() && val[commaPos+1] == ' ' ) {	    val(commaPos,1) = "";	    startPos--;	 }	 else	    val(commaPos,1) = " ";      }   } // End for each address in the alias} // End ConvertAliasToMailrc/*------------------------------------------------------------------------ * Method to edit the aliases */voidAliasPrefC::Edit(Widget parent){   halApp->BusyCursor(True);   if ( !aliasWin ) aliasWin = new AliasPrefWinC(parent, aliasDict);   aliasWin->Show();   halApp->BusyCursor(False);}/*------------------------------------------------------------------------ * Method to edit the group aliases */voidAliasPrefC::EditGroup(Widget parent){   halApp->BusyCursor(True);   if ( !groupWin ) groupWin = new AliasPrefWinC(parent, groupAliasDict);   groupWin->Show();   halApp->BusyCursor(False);}/*--------------------------------------------------------------- *  Function to expand aliases with an argument to tell whether or *     not to expand hidden aliases. */StringCAliasPrefC::ExpandAddress(StringC& alias, int depth, Boolean expandHidden){   if ( debuglev > 0 )      cout <<depth <<" Expanding alias string: " <<alias <<endl;   if ( alias.size() < 1 || depth <= 0 )      return alias;   StringC	output;   if ( !expandHidden && hideAddrList.includes(alias) ) {      output = alias;      output += ":;";	// RFC822 section 6.2.6 "named list" syntax      return output;   }//// Loop through addresses//   AddressC	addrs(alias);   AddressC	*addr = &addrs;   StringC	*val;   StringC	addrStr;   while ( addr ) {//// If there's a comment don't expand this one//      if ( addr->name ) {//// Remove comments if spaces are used as address separators//	 if ( ishApp->compPrefs->spaceEndsAddr )	    addrStr = addr->addr;	 else	    addrStr = addr->full;      }//// Try to expand the address//      else {	 addrStr = addr->addr;	 val = aliasDict.definitionOf(addrStr);	 if ( !val ) val = groupAliasDict.definitionOf(addrStr);	 if ( !val ) val = otherAliasDict.definitionOf(addrStr);	 if ( val ) {            if ( depth>1 )	       addrStr = ExpandAddress(*val, depth-1, expandHidden);            else {//// Remove comments if spaces are used as address separators//	       if ( ishApp->compPrefs->spaceEndsAddr ) {		  AddressC	valAddr(*val);		  addrStr = valAddr.addr;	       }	       else		  addrStr = *val;	    }	 } // End if there is a new value      } // End if we can expand//// Add the result to the output//      if ( addrStr.size() > 0 ) {	 if ( output.size() > 0 ) output += ", ";	 output += addrStr;      }      addr = addr->next;   } // End for each address   if ( debuglev > 0 ) cout <<depth <<" Expanded string: " <<output <<endl;   return output;} // End ExpandAddress

⌨️ 快捷键说明

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