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

📄 sendiconc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  $Id: SendIconC.C,v 1.2 2000/05/07 12:26:12 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 "SendIconC.h"#include "SendWinC.h"#include "IncludeWinC.h"#include "MsgPartC.h"#include "MsgC.h"#include "MimeEncode.h"#include "FileMisc.h"#include "SendMisc.h"#include "HeaderC.h"#include "ParamC.h"#include "Misc.h"#include "Base64.h"#include "QuotedP.h"#include <hgl/rsrc.h>#include <hgl/SysErr.h>#include <unistd.h>	// For unlink#include <errno.h>#include <sys/stat.h>/*--------------------------------------------------------------- *  Constructor with file data from include window */SendIconC::SendIconC(SendWinC *sw, IncludeWinC *iw): MimeIconC(iw->ContentTypeStr(), sw->BodyText()){   sendWin = sw;   data    = NULL;   Update(iw);} // End constructor with file data/*--------------------------------------------------------------- *  Constructor with content type. */SendIconC::SendIconC(SendWinC *sw, char *type, char *ifile, char *ofile): MimeIconC(type, sw->BodyText()){   sendWin = sw;//// Build a message part and open the message file//   FILE	*fp = CreatePart();   if ( !fp ) return;//// Initialize data from type and file//   if ( !ofile ) ofile = ifile;   Boolean	error = !BuildPartFile(fp, type, ifile, ofile);   if ( !error ) {      fseek(fp, 0, SEEK_SET);      error = !data->ScanHead(fp);   }   if ( !error ) CalcBodySize(fp);   fclose(fp);   if ( !error ) InitIcon();} // End constructor with content type/*--------------------------------------------------------------- *  Constructor with rfc822 message. */SendIconC::SendIconC(SendWinC *sw, MsgC *msg): MimeIconC("message/rfc822", sw->BodyText()){   sendWin = sw;//// Build a message part and open the message file//   FILE	*fp = CreatePart();   if ( !fp ) return;//// Initialize data from message//   Boolean	error = !BuildPartFile(fp, msg);   if ( !error ) {      fseek(fp, 0, SEEK_SET);      error = !data->ScanHead(fp);   }   if ( !error ) CalcBodySize(fp);   fclose(fp);   if ( !error ) InitIcon();} // End constructor with content type/*--------------------------------------------------------------- *  Constructor with a mime message part */SendIconC::SendIconC(SendWinC *sw, MsgPartC *part): MimeIconC(part->conStr, sw->BodyText()){   sendWin = sw;//// Build a message part and open the message file//   FILE	*fp = CreatePart();   if ( !fp ) return;//// Initialize data from the specified part//   Boolean	error = !BuildPartFile(fp, part);   if ( !error ) {      fseek(fp, 0, SEEK_SET);      error = !data->ScanHead(fp);   }   if ( !error ) CalcBodySize(fp);   fclose(fp);   if ( !error ) InitIcon();} // End constructor with mime part/*--------------------------------------------------------------- *  Method to create a new message part */FILE*SendIconC::CreatePart(){   data = new MsgPartC;//// Create temporary message part file//   char	*cs = tempnam(NULL, "part.");   FILE	*fp = fopen(cs, "w+");   if ( !fp ) {      StringC	errmsg("Could not create file: \"");      errmsg += cs;      errmsg += "\"\n.";      errmsg += SystemErrorMessage(errno);      sendWin->PopupMessage(errmsg);   }   else {      data->msgFile    = cs;      data->delMsgFile = True;   }   free(cs);   return fp;} // End CreatePart/*--------------------------------------------------------------- *  Method to build a MIME message body for the information in the include *     window */BooleanSendIconC::BuildPartFile(FILE *fp, IncludeWinC *iw){   StringC	headStr;   StringC	tmpStr;   StringC	name;   iw->GetFileName(name);//// Write external-body header if necessary//   MimeAccessType	accType = iw->AccessType();   if ( IsExternal(accType) ) {      headStr = "Content-Type: message/external-body;\n\taccess-type=";//// Add the access information//      switch (accType) {	 case (AT_LOCAL_FILE):	    headStr += "\"local-file\"";	    AddQuotedVal(headStr, ";\n\tname=", name);	    break;	 case (AT_ANON_FTP):	 case (AT_FTP):	 case (AT_TFTP):	    if      ( accType == AT_TFTP ) headStr += "\"tftp\"";	    else if ( accType == AT_FTP  ) headStr += "\"ftp\"";	    else			   headStr += "\"anon-ftp\"";	    AddQuotedVal(headStr, ";\n\tname=", name);	    iw->GetFtpHost(tmpStr);	    AddQuotedVal(headStr, ";\n\tsite=", tmpStr);	    iw->GetFtpDir(tmpStr);	    if ( tmpStr.size() > 0 )	       AddQuotedVal(headStr, ";\n\tdirectory=", tmpStr);	    tmpStr.Clear();	    if ( accType == AT_TFTP ) iw->GetTftpMode(tmpStr);	    else		      iw->GetFtpMode(tmpStr);	    if ( tmpStr.size() > 0 )	       AddQuotedVal(headStr, ";\n\tmode=", tmpStr);	    break;	 case (AT_MAIL_SERVER):	    headStr += "\"mail-server\"";	    iw->GetMailAddr(tmpStr);	    AddQuotedVal(headStr, ";\n\tserver=", tmpStr);	    iw->GetMailSubject(tmpStr);	    if ( tmpStr.size() > 0 )	       AddQuotedVal(headStr, ";\n\tsubject=", tmpStr);	    break;	 case (AT_INLINE):	// Not possible here	 default:	    break;      } // End switch access type//// Add parameters common to all//      iw->GetExpiration(tmpStr);      if ( tmpStr.size() > 0 )	 AddQuotedVal(headStr, ";\n\texpiration=", tmpStr);      iw->GetSize(tmpStr);      if ( tmpStr.size() > 0 )	 AddQuotedVal(headStr, ";\n\tsize=", tmpStr);      if ( iw->IsReadWrite() )	 headStr += ";\n\tpermission=\"read-write\"";      if ( !headStr.EndsWith('\n') ) headStr += '\n';//// Add description header//      iw->GetDescription(tmpStr);      if ( tmpStr.size() > 0 ) {	 headStr += "Content-Description: ";	 headStr += tmpStr;	 if ( !headStr.EndsWith('\n') ) headStr += '\n';      }//// Add a blank line//      while ( !headStr.EndsWith("\n\n") ) headStr += '\n';   } // End if type is message/external-body//// Build the content-type header for this body part// If we're uuencoding, force the type to "text/plain"//   headStr += "Content-Type: ";   if ( iw->IsUUencode() ) headStr += "text/plain";   else			   headStr += iw->ContentTypeStr();   iw->GetCharset(tmpStr);   if ( tmpStr.size() > 0 && !tmpStr.Equals("us-ascii", IGNORE_CASE) )      AddQuotedVal(headStr, ";\n\tcharset=", tmpStr);   iw->GetAppType(tmpStr);   if ( tmpStr.size() > 0 ) AddQuotedVal(headStr, ";\n\ttype=", tmpStr);   iw->GetAppPadding(tmpStr);   if ( tmpStr.size()  > 0 ) AddQuotedVal(headStr, ";\n\tpadding=", tmpStr);   iw->GetOtherParams(tmpStr);   if ( tmpStr.size() > 0 ) {      headStr += "; ";      headStr += tmpStr;   }   if ( !headStr.EndsWith('\n') ) headStr += '\n';//// Add description header//   iw->GetDescription(tmpStr);   if ( tmpStr.size() > 0 ) {      headStr += "Content-Description: ";      headStr += tmpStr;      if ( !headStr.EndsWith('\n') ) headStr += '\n';   }//// Add a content-id header//   if ( IsExternal(accType) ) {      GenId(tmpStr);      headStr += "Content-Id: ";      headStr += '<';      headStr += tmpStr;      headStr += ">\n";   }//// Add a content-disposition header//   headStr += "Content-Disposition: attachment";   iw->GetOutputName(tmpStr);   if ( tmpStr.size() > 0 ) {      headStr += ";\n\tfilename=";      headStr += tmpStr;   }   headStr += '\n';//// Add a content transfer encoding header//   MimeEncodingType	encType = iw->EncodingType();   if ( !IsExternal(accType) &&        (Is8Bit(encType) || IsBase64(encType) || IsQP(encType)) ) {      headStr += "Content-Transfer-Encoding: ";      headStr += EncodingTypeStr(encType);      headStr += '\n';   }//// Add a blank line//   while ( !headStr.EndsWith("\n\n") ) headStr += '\n';   if ( !headStr.WriteFile(fp) ) {      StringC	errmsg("Could not write file: \"");      errmsg += data->msgFile;      errmsg += "\".\n";      errmsg += SystemErrorMessage(errno);      sendWin->PopupMessage(errmsg);      return False;   }//// Add the body//   if ( IsMail(accType) ) {      iw->GetMailBody(tmpStr);      if ( !tmpStr.WriteFile(fp) ) {	 StringC	errmsg("Could not write file: \"");	 errmsg += data->msgFile;	 errmsg += "\".\n";	 errmsg += SystemErrorMessage(errno);	 sendWin->PopupMessage(errmsg);	 return False;      }   }   else if ( !IsExternal(accType) ) {//// Encode the file if necessary//      if ( IsEncoded(encType) && !iw->AlreadyEncoded() ) {	 tmpStr = "Encoding file ";	 tmpStr += name;	 sendWin->Message(tmpStr);//// Encode the original file and write the result to the output file//	 Boolean	success = True;	 if      ( IsBase64(encType) )	    success = FileToFile64(name, data->msgFile, iw->IsText(), NULL, fp);	 else if ( IsQP(encType) )	    success = FileToFileQP(name, data->msgFile, NULL, fp);	 else if ( IsUU(encType) )	    success = FileToFileUU(name, data->msgFile, fp);	 else if ( IsBinHex(encType) )	    success = FileToFileBH(name, data->msgFile, fp);	 if ( !success ) {	    StringC	errmsg("Could not encode file: ");	    errmsg += name;	    errmsg += "\n";	    errmsg += SystemErrorMessage(errno);	    sendWin->PopupMessage(errmsg);	    return False;	 }	 data->dataFile    = name;	 data->delDataFile = False;      } // End if encoded//// Just copy the file//      else {         if ( !CopyFile(name, data->msgFile, False, False, NULL, fp) )	    return False;      } // End if no encoding   } // End if not external attachment   return True;} // End BuildPartFile

⌨️ 快捷键说明

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