1 |
<? |
2 |
|
3 |
// encode quoted-printable |
4 |
// php port by Dobrica Pavlinusic <dpavlin@rot13.org> |
5 |
// from encdec.c-1.1 by Jörgen Hägg 1993 <jh@efd.lth.se> |
6 |
|
7 |
function e_qp($foo) { |
8 |
|
9 |
$count=0; |
10 |
$out=""; |
11 |
|
12 |
for($i=0; $i<strlen($foo); $i++) { |
13 |
if ($count > 73) { |
14 |
$out.="\n"; |
15 |
$count = 0; |
16 |
} |
17 |
$c=substr($foo,$i,1); |
18 |
$p=ord($c); |
19 |
if ($p == 10) { |
20 |
$out.="\n"; |
21 |
$count = 0; |
22 |
} else if ($p == 9 || $p == 32) { |
23 |
// if (!*(p+1)) |
24 |
// { |
25 |
$out.=sprintf("=%02X", $p); |
26 |
$count += 3; |
27 |
// } |
28 |
// else |
29 |
// { |
30 |
// $out.=$c; |
31 |
// $count++; |
32 |
// } |
33 |
continue; |
34 |
} else if (($p >= 33 && $p <= 60) || |
35 |
($p >= 62 && $p <= 126)) { |
36 |
$out.=$c; |
37 |
$count++; |
38 |
} else { |
39 |
$out.=sprintf("=%02X", $p); |
40 |
$count += 3; |
41 |
} |
42 |
|
43 |
} |
44 |
$out.="\n"; |
45 |
return $out; |
46 |
} |
47 |
|
48 |
// mail function replacement |
49 |
|
50 |
// example: iso_mail("From name <from_address@domain.dot>", |
51 |
// "to_addrress@domain.dot", |
52 |
// "subject of message", |
53 |
// "body of message" |
54 |
|
55 |
function iso_mail($from,$to,$subject,$msg) { |
56 |
$mail=popen("/usr/sbin/sendmail -t","w"); |
57 |
if (! $mail) { |
58 |
return 0; // error! |
59 |
} |
60 |
fputs($mail,'To: '.$to.' |
61 |
From: '.$from.' |
62 |
Subject: '.$subject.' |
63 |
X-Mailer: php-quotedprintable-mailer |
64 |
Content-Type: text/plain; charset="iso-8859-2" |
65 |
Content-Transfer-Encoding: quoted-printable |
66 |
'.$headers.' |
67 |
|
68 |
'.e_qp($msg)); |
69 |
pclose($mail); |
70 |
return 1; |
71 |
} |
72 |
|
73 |
/* don't add newlines to output stream */ |
74 |
function e_qp_nonl($foo) { |
75 |
|
76 |
$out=""; |
77 |
|
78 |
for($i=0; $i<strlen($foo); $i++) { |
79 |
$c=substr($foo,$i,1); |
80 |
$p=ord($c); |
81 |
if ($p == 10) { |
82 |
$out.="\n"; |
83 |
} else if (($p >= 33 && $p <= 60) || |
84 |
($p >= 62 && $p <= 126)) { |
85 |
$out.=$c; |
86 |
} else { |
87 |
$out.=sprintf("=%02X", $p); |
88 |
} |
89 |
|
90 |
} |
91 |
return $out; |
92 |
} |
93 |
|
94 |
/* like sendmail -t ... extract headers from message */ |
95 |
function iso_sendmail_t($msg) { |
96 |
$mail=popen("/usr/sbin/sendmail -t","w"); |
97 |
if (! $mail) { |
98 |
return 0; // error! |
99 |
} |
100 |
list($h,$b)=split("\n\n",$msg,2); |
101 |
fputs($mail, $h.' |
102 |
X-Mailer: php-quotedprintable-mailer |
103 |
Content-Type: text/plain; charset="iso-8859-2" |
104 |
Content-Transfer-Encoding: quoted-printable |
105 |
|
106 |
'.e_qp_nonl($b)); |
107 |
pclose($mail); |
108 |
return 1; |
109 |
} |
110 |
|
111 |
?> |