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

📄 mailcap.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * $Id: Mailcap.C,v 1.4 2001/03/29 09:44:25 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 "IshAppC.h"#include "Mailcap.h"#include "Misc.h"#include "MsgPartC.h"#include "MsgC.h"#include "SafeSystem.h"#include "ParamC.h"#include <hgl/StrCase.h>#include <hgl/CallbackC.h>#include <hgl/RegexC.h>#include <hgl/CharC.h>#include <unistd.h>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>#include <errno.h>#include <time.h>#include <sys/stat.h>	// For statMailcapFileC	*MailcapFiles   = NULL;time_t		mailcapReadTime = 0;static StringC	*mailcapPath    = NULL;const char	*defMailcapPath =	 "$HOME/.mailcap:/etc/mailcap:/usr/etc/mailcap:/usr/local/etc/mailcap";extern int	debuglev;/*--------------------------------------------------------------- *  Method to return a pointer to the requested parameter */static ParamC*Param(CharC key, ParamC *list){//// Loop through list//   ParamC	*param;   for ( param=list; param; param=param->next )      if ( param->key.Equals(key, IGNORE_CASE) )	 return param;   return NULL;} // End Param/*----------------------------------------------------------------------- *  Function to perform substitutions in mailcap commands */StringCBuildCommand(StringC cmdStr, CharC file, CharC enc, CharC type, ParamC *params,	     CharC user, CharC pass){//// Make the following substitutions://// %%       ==> %// %s       ==> file name// %e       ==> encoding string// %t       ==> type string// %{param} ==> parameter value//   static RegexC	*percPat = NULL;   static RegexC	*parmPat = NULL;   if ( !percPat ) percPat = new RegexC("%[%set{]");   if ( !parmPat ) parmPat = new RegexC("%{\\([^}]+\\)}");   Boolean	gotFile = False;   int	pos = 0;   while ( (pos=percPat->search(cmdStr, pos)) >= 0 ) {      char	c = cmdStr[pos+1];      RangeC	range = (*percPat)[0];      switch (c) {	 case '%':	    cmdStr(range) = "%";	    pos++;	    break;	 case 's':	// File name	    if ( file.Length() > 0 ) {	       cmdStr(range) = file;	       pos += file.Length();	       gotFile = True;	    }	    else	       pos += range.length();	    break;	 case 'e':	// Encoding	    if ( enc.Length() > 0 ) {	       cmdStr(range) = enc;	       pos += enc.Length();	    }	    else	       pos += range.length();	    break;	 case 't':	// Type	    if ( type.Length() > 0 ) {	       cmdStr(range) = type;	       pos += type.Length();	    }	    else	       pos += range.length();	    break;	 case '{':	    if ( parmPat->match(cmdStr, pos) ) {//// Look up the parameter//	       range = (*parmPat)[1];	       CharC	key    = cmdStr(range);	       ParamC	*param = Param(key, params);	       StringC	val;//// If it wasn't found, check for the special cases of "ruser" and "rpwd"//    used in the ftp command//	       if ( !param ) {		  if ( user.Length() >0 && key.Equals("ruser", IGNORE_CASE) )		     val = user;		  else		  if ( pass.Length()>0  && key.Equals("rpwd",  IGNORE_CASE) ) {//// Encode the password so it doesn't accidently show up in clear text. In//    'tr' format, here is the encoding://// tr '\050-\172' '\060-\172\050-\057'//		     val = pass;		     char	*vp = val;		     for (int i=0; i<val.size(); i++, vp++) {			if ( *vp >= '\050' && *vp <= '\172' ) {			   *vp += '\010';			   if ( *vp > '\172' ) *vp = '\050' + (*vp - '\173');			}		     }		  } // End if need password	       } // End if parameter not found	       else		  val = param->val;//// Substitute the parameter value//	       //if ( val.size() > 0 ) {		  range = (*parmPat)[0];		  cmdStr(range) = val;		  pos += val.size();	       //}	       //else		  //pos += range.length();	    } // End if parameter pattern found	    break;      } // End switch character   } // End for each percent pattern//// If we didn't add the file name, we have to pipe it through stdin.//   if ( !gotFile ) {      StringC	pipeStr = "cat ";      pipeStr += file;      pipeStr += " | ";      cmdStr = pipeStr + cmdStr;   }   return cmdStr;} // End BuildCommand/*----------------------------------------------------------------------- *  Function to perform substitutions in mailcap commands */StringCBuildCommand(StringC cmdStr, MsgPartC *part, CharC file){//// Make the following substitutions://// %%       ==> %// %s       ==> file name// %e       ==> encoding string// %t       ==> type string// %{param} ==> parameter value//   static RegexC	*percPat = NULL;   static RegexC	*parmPat = NULL;   if ( !percPat ) percPat = new RegexC("%[%set{]");   if ( !parmPat ) parmPat = new RegexC("%{\\([^}]+\\)}");   Boolean	gotFile = False;   int	pos = 0;   while ( (pos=percPat->search(cmdStr, pos)) >= 0 ) {      char	c = cmdStr[pos+1];      RangeC	range = (*percPat)[0];      switch (c) {	 case '%':	    cmdStr(range) = "%";	    pos++;	    break;	 case 's':	// File name	    if ( file.Length() > 0 ) {	       cmdStr(range) = file;	       pos += file.Length();	       gotFile = True;	    }	    else	       pos += range.length();	    break;	 case 'e':	// Encoding	 {	    CharC	enc = EncodingTypeStr(part->encType);	    if ( enc.Length() > 0 ) {	       cmdStr(range) = enc;	       pos += enc.Length();	    }	    else	       pos += range.length();	 } break;	 case 't':	// Type	 {	    CharC	type(part->conStr);	    if ( type.Length() > 0 ) {	       cmdStr(range) = type;	       pos += type.Length();	    }	    else	       pos += range.length();	 } break;	 case '{':	    if ( parmPat->match(cmdStr, pos) ) {//// Look up the parameter//	       range = (*parmPat)[1];	       CharC	key    = cmdStr(range);	       ParamC	*param = part->Param(key);	       StringC	val;//// If it wasn't found, check for the special cases of "ruser" and "rpwd"//    used in the ftp command//	       if ( !param ) {		  if ( part->userName.size() > 0 &&		       key.Equals("ruser", IGNORE_CASE) )		     val = part->userName;		  else		  if ( part->userPass.size() > 0 &&		       key.Equals("rpwd",  IGNORE_CASE) ) {//// Encode the password so it doesn't accidently show up in clear text. In//    'tr' format, here is the encoding://// tr '\050-\172' '\060-\172\050-\057'//		     val = part->userPass;		     char	*vp = val;		     for (int i=0; i<val.size(); i++, vp++) {			if ( *vp >= '\050' && *vp <= '\172' ) {			   *vp += '\010';			   if ( *vp > '\172' ) *vp = '\050' + (*vp - '\173');			}		     }		  } // End if need password	       } // End if parameter not found	       else		  val = param->val;//// Substitute the parameter value//	       //if ( val.size() > 0 ) {		  range = (*parmPat)[0];		  cmdStr(range) = val;		  pos += val.size();	       //}	       //else		  //pos += range.length();	    } // End if parameter pattern found	    break;      } // End switch character   } // End for each percent pattern//// If we didn't add the file name, we have to pipe it through stdin.//   if ( !gotFile && file.Length() > 0 ) {      StringC	pipeStr = "cat ";      pipeStr += file;      pipeStr += " | ";      cmdStr = pipeStr + cmdStr;   }   return cmdStr;} // End BuildCommand/*----------------------------------------------------------------------- *  Method to run mailcap test command */static intTestMailcap(MailcapC *mc, MsgPartC *part){   if ( mc->test.size() == 0 ) return True;//// See if we need a data file to pass to the command//   char		*file = NULL;   StringC	cmd;   if ( part ) {//// See if there's a %s and a data file//      if ( mc->test.Contains("%s") && part->CreateDataFile() )	 file = part->dataFile;      cmd = BuildCommand(mc->test, part, file);

⌨️ 快捷键说明

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