| 1 | ##---------------------------------------------------------------------------## |
| 2 | ## File: |
| 3 | ## $Id: mhdysub.pl,v 2.6 2002/06/07 17:45:09 ehood Exp $ |
| 4 | ## Author: |
| 5 | ## Earl Hood mhonarc@mhonarc.org |
| 6 | ## Description: |
| 7 | ## Definition of create_routines() that creates routines are |
| 8 | ## runtime. |
| 9 | ##---------------------------------------------------------------------------## |
| 10 | ## MHonArc -- Internet mail-to-HTML converter |
| 11 | ## Copyright (C) 1996-2001 Earl Hood, mhonarc@mhonarc.org |
| 12 | ## |
| 13 | ## This program is free software; you can redistribute it and/or modify |
| 14 | ## it under the terms of the GNU General Public License as published by |
| 15 | ## the Free Software Foundation; either version 2 of the License, or |
| 16 | ## (at your option) any later version. |
| 17 | ## |
| 18 | ## This program is distributed in the hope that it will be useful, |
| 19 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | ## GNU General Public License for more details. |
| 22 | ## |
| 23 | ## You should have received a copy of the GNU General Public License |
| 24 | ## along with this program; if not, write to the Free Software |
| 25 | ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | ##---------------------------------------------------------------------------## |
| 27 | |
| 28 | package mhonarc; |
| 29 | |
| 30 | my $_sub_eval_cnt = 0; |
| 31 | |
| 32 | ##--------------------------------------------------------------------------- |
| 33 | ## create_routines is used to dynamically create routines that |
| 34 | ## would benefit from being create at run-time. Routines |
| 35 | ## that have to check against several regular expressions |
| 36 | ## are candidates. |
| 37 | ## |
| 38 | sub create_routines { |
| 39 | my($sub) = ''; |
| 40 | |
| 41 | ##----------------------------------------------------------------------- |
| 42 | ## exclude_field: Used to determine if field should be excluded from |
| 43 | ## message header |
| 44 | ## |
| 45 | $sub =<<'EndOfRoutine'; |
| 46 | sub exclude_field { |
| 47 | my($f) = shift; |
| 48 | my $ret = 0; |
| 49 | EXC_FIELD_SW: { |
| 50 | EndOfRoutine |
| 51 | |
| 52 | # Create switch block for checking field against regular |
| 53 | # expressions (a large || statement could also work). |
| 54 | my $pat; |
| 55 | foreach $pat (keys %HFieldsExc) { |
| 56 | $sub .= join('', |
| 57 | 'if ($f =~ /^', |
| 58 | $pat, |
| 59 | '/i) { $ret = 1; last EXC_FIELD_SW; }', |
| 60 | "\n"); |
| 61 | } |
| 62 | |
| 63 | $sub .=<<'EndOfRoutine'; |
| 64 | } |
| 65 | $ret; |
| 66 | } |
| 67 | EndOfRoutine |
| 68 | |
| 69 | $sub .= "# $_sub_eval_cnt\n"; ++$_sub_eval_cnt; |
| 70 | eval $sub; |
| 71 | die("ERROR: Unable to create exclude_field routine:\n$@\n") if $@; |
| 72 | |
| 73 | ##----------------------------------------------------------------------- |
| 74 | ## subject_strip: Used to apply user-defined s/// operations on |
| 75 | ## message subjects as they are read; |
| 76 | ## |
| 77 | $sub =<<EndOfRoutine; |
| 78 | sub subject_strip { |
| 79 | local(\$_) = shift; |
| 80 | $SubStripCode; |
| 81 | \$_; |
| 82 | } |
| 83 | EndOfRoutine |
| 84 | |
| 85 | $sub .= "# $_sub_eval_cnt\n"; ++$_sub_eval_cnt; |
| 86 | eval $sub; |
| 87 | die("ERROR: Unable to create subject_strip routine:\n$@\n") if $@; |
| 88 | |
| 89 | ##----------------------------------------------------------------------- |
| 90 | ## Routine to determine last message number in use. |
| 91 | ## |
| 92 | $sub =<<'EndOfRoutine'; |
| 93 | sub get_last_msg_num { |
| 94 | opendir(DIR, $OUTDIR) || die("ERROR: Unable to open $OUTDIR\n"); |
| 95 | my($max) = -1; |
| 96 | my $msgrex = '^'. |
| 97 | "\Q$MsgPrefix". |
| 98 | '(\d+)\.'. |
| 99 | "\Q$HtmlExt". |
| 100 | '$'; |
| 101 | chop $msgrex if ($HtmlExt =~ /html$/i); |
| 102 | |
| 103 | foreach (readdir(DIR)) { |
| 104 | if (/$msgrex/io) { $max = int($1) if $1 > $max; } |
| 105 | } |
| 106 | close(DIR); |
| 107 | $max; |
| 108 | } |
| 109 | EndOfRoutine |
| 110 | |
| 111 | $sub .= "# $_sub_eval_cnt\n"; ++$_sub_eval_cnt; |
| 112 | eval $sub; |
| 113 | die("ERROR: Unable to create get_last_msg_num routine:\n$@\n") if $@; |
| 114 | |
| 115 | ##----------------------------------------------------------------------- |
| 116 | ## Routine to get base subject text from index |
| 117 | ## |
| 118 | $sub =<<'EndOfRoutine'; |
| 119 | sub get_base_subject { |
| 120 | my($ret) = ($Subject{$_[0]}); |
| 121 | 1 while $ret =~ s/$SubReplyRxp//io; |
| 122 | if ($ret eq "") { |
| 123 | return $NoSubjectTxt; |
| 124 | } |
| 125 | $ret; |
| 126 | } |
| 127 | EndOfRoutine |
| 128 | |
| 129 | $sub .= "# $_sub_eval_cnt\n"; ++$_sub_eval_cnt; |
| 130 | eval $sub; |
| 131 | die("ERROR: Unable to create get_base_subject routine:\n$@\n") if $@; |
| 132 | |
| 133 | ##----------------------------------------------------------------------- |
| 134 | ## Routine to rewrite mail addresses in message header |
| 135 | ## |
| 136 | $sub =<<EndOfRoutine; |
| 137 | sub rewrite_address { |
| 138 | local \$_ = shift; |
| 139 | $AddressModify; |
| 140 | \$_; |
| 141 | } |
| 142 | EndOfRoutine |
| 143 | |
| 144 | $sub .= "# $_sub_eval_cnt\n"; ++$_sub_eval_cnt; |
| 145 | eval $sub; |
| 146 | die("ERROR: Unable to create rewrite_address routine:\n$@\n") if $@; |
| 147 | |
| 148 | ##----------------------------------------------------------------------- |
| 149 | ## message_exclude: User-defined code to check if a message should |
| 150 | ## be added or not. |
| 151 | ## |
| 152 | $sub =<<EndOfRoutine; |
| 153 | sub message_exclude { |
| 154 | package mhonarc::Pkg_message_exclude; |
| 155 | local(\$_) = shift; |
| 156 | $MsgExcFilter; |
| 157 | } |
| 158 | EndOfRoutine |
| 159 | |
| 160 | $sub .= "# $_sub_eval_cnt\n"; ++$_sub_eval_cnt; |
| 161 | eval $sub; |
| 162 | die("ERROR: Unable to create subject_strip routine:\n$@\n") if $@; |
| 163 | |
| 164 | } |
| 165 | |
| 166 | ##---------------------------------------------------------------------------## |
| 167 | 1; |