📄 mailcap.c
字号:
} // End if there was a body part passed in else { StringC type = mc->conType; if ( mc->subType != "*" ) { type += "/"; type += mc->subType; } cmd = BuildCommand(mc->test, NULL, NULL, type, NULL, NULL, NULL); } // End if there is no body part//// Run the command// int status = SafeSystem(cmd); if ( debuglev > 0 ) cout <<cmd <<" returns " <<status <<endl; return (status == 0);} // TestMailcap/*----------------------------------------------------------------------- * Function to re-read mailcap files if necessary */static voidUpdateMailcapFiles(){//// See if any files have changed since we last read them// u_int offset = 0; CharC file = mailcapPath->NextWord(offset, ':'); while ( file.Length() > 0 ) {//// If a file has changed, re-read them all.// StringC tmp(file); struct stat stats; if ( stat(tmp, &stats) == 0 && stats.st_mtime > mailcapReadTime ) { ReadMailcap(); return; } offset = file.Addr() - (char*)(*mailcapPath) + file.Length(); file = mailcapPath->NextWord(offset, ':'); }} // End UpdateMailcapFiles/*----------------------------------------------------------------------- * Functions to lookup mailcap entry */MailcapC*MailcapEntry(MsgPartC *part){//// Re-read mailcap files if necessary// UpdateMailcapFiles();//// Look for matching type// MailcapFileC *file = MailcapFiles; while ( file ) {//// Loop through entries in this file// u_int count = file->entryList.size(); for (int i=0; i<count; i++) { MailcapC *entry = file->entryList[i];//// See if type matches// if ( entry->conType.Equals(part->grpStr, IGNORE_CASE) || entry->conType == "*" ) {//// See if subtype matches// if ( entry->subType.Equals(part->subStr, IGNORE_CASE) || entry->subType == "*" ) {//// See if entry passes test// if ( TestMailcap(entry, part) ) return entry; } // End if subtype matches } // End if type matches } // End for each mailcap entry file = file->next; } // End for each mailcap file return NULL;} // End MailcapEntryMailcapC*MailcapEntry(CharC con, CharC sub, MsgPartC *part){//// Re-read mailcap files if necessary// UpdateMailcapFiles();//// Look for matching type// MailcapFileC *file = MailcapFiles; while ( file ) {//// Loop through entries in this file// u_int count = file->entryList.size(); for (int i=0; i<count; i++) { MailcapC *entry = file->entryList[i];//// See if type matches// if ( entry->conType.Equals(con, IGNORE_CASE) || entry->conType == "*" ) {//// See if subtype matches// if ( entry->subType.Equals(sub, IGNORE_CASE) || entry->subType == "*" ) {//// See if entry passes test// if ( TestMailcap(entry, part) ) return entry; } // End if subtype matches } // End if type matches } // End for each mailcap entry file = file->next; } // End for each mailcap file return NULL;} // End MailcapEntry/*--------------------------------------------------------------------- * Function to read the next real line from a mailcap file */static BooleanGetNextLine(CharC data, u_int *offset, StringC *line){ line->Clear();//// Look for next non-commented line// CharC segment = data.NextWord(*offset, '\n'); *offset = segment.Addr() - data.Addr() + segment.Length(); while ( segment[0] == '#' ) { segment = data.NextWord(*offset, '\n'); *offset = segment.Addr() - data.Addr() + segment.Length(); } if ( segment.Length() == 0 ) return False;//// Remove escaped newlines// *line = segment; line->Replace("\\\n", ""); return True;} // End GetNextLine/*--------------------------------------------------------------------- * Function to read a mailcap file and add its entries */static voidProcessMailcapFile(StringC file){ if ( debuglev > 0 ) cout <<"Reading mailcap file: " <<file <<endl; StringC data; if ( !data.ReadFile(file) ) return;//// Create a new file object// MailcapFileC *mcfile = new MailcapFileC(file); if ( MailcapFiles ) { MailcapFileC *fileEntry = MailcapFiles; while ( fileEntry->next ) fileEntry = fileEntry->next; fileEntry->next = mcfile; } else MailcapFiles = mcfile; StringC line; u_int offset = 0; while ( GetNextLine(data, &offset, &line) ) { if ( debuglev > 0 ) cout <<"Found mailcap entry: " <<line <<endl;//// Create a new data structure// MailcapC *mcap = new MailcapC(line); mcfile->entryList.add(mcap); } // End for each mailcap entry//// Sort the entries in this file// mcfile->Sort(); if ( debuglev > 1 ) { cout <<"Sorted entries:" <<endl; u_int count = mcfile->entryList.size(); for (int i=0; i<count; i++) { MailcapC *entry = mcfile->entryList[i]; cout <<"\t" <<entry->fullType <<endl; } }} // End ProcessMailcapFile/*--------------------------------------------------------------------- * Function to read mailcap files and build tree */intReadMailcap(){ if ( !mailcapPath ) mailcapPath = new StringC; char *cs = getenv("MAILCAPS"); if ( cs ) { *mailcapPath = cs; } else { *mailcapPath = ishHome + "/lib/mailcap:" + defMailcapPath; mailcapPath->Replace("$HOME", ishApp->home); }//// Delete existing entries// MailcapFileC *mcfile = MailcapFiles; while ( mcfile ) { MailcapFileC *next = mcfile->next; delete mcfile; mcfile = next; } MailcapFiles = NULL;//// Loop through files and process them// u_int offset = 0; CharC file = mailcapPath->NextWord(offset, ':'); StringC data; while ( file.Length() > 0 ) { ProcessMailcapFile(file); offset = file.Addr() - (char*)(*mailcapPath) + file.Length(); file = mailcapPath->NextWord(offset, ':'); } mailcapReadTime = time(0); return 0;} // End ReadMailcap/*--------------------------------------------------------------------- * Initialize mailcap stuff */intInitMailcap(){ MailcapFileC *fileEntry = MailcapFiles; while ( fileEntry ) { MailcapFileC *nextEntry = fileEntry->next; delete fileEntry; fileEntry = nextEntry; } MailcapFiles = NULL; return ReadMailcap();}/*--------------------------------------------------------------------- * Constructor for mailcap file object */MailcapFileC::MailcapFileC(const char *file){ name = file; next = NULL; entryList.AllowDuplicates(FALSE); entryList.SetSorted(FALSE);}/*--------------------------------------------------------------------- * Destructor for mailcap file object */MailcapFileC::~MailcapFileC(){ u_int count = entryList.size(); for (int i=0; i<count; i++) { MailcapC *entry = entryList[i]; delete entry; }}/*--------------------------------------------------------------------- * Method to sort mailcap entries */static intCompareEntries(const void *a, const void *b){#define A_GREATER 1#define AB_EQUAL 0#define B_GREATER -1 MailcapC *ma = *(MailcapC **)a; MailcapC *mb = *(MailcapC **)b; int result = AB_EQUAL;//// Check the content types// if ( ma->conType.Equals("*") && !mb->conType.Equals("*") ) result = A_GREATER; else if ( mb->conType.Equals("*") && !ma->conType.Equals("*") ) result = B_GREATER; else if ( ma->conType == mb->conType ) {//// Check the sub types// if ( ma->subType.Equals("*") && !mb->subType.Equals("*") ) result = A_GREATER; else if ( mb->subType.Equals("*") && !ma->subType.Equals("*") ) result = B_GREATER; else if ( ma->subType == mb->subType ) result = AB_EQUAL; else result = ma->subType.compare(mb->subType); } // End if content types are equal else result = ma->conType.compare(mb->conType); return result;} // End CompareEntriesvoidMailcapFileC::Sort(){ entryList.sort(CompareEntries);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -