<?
// $Header: /cvsroot/jwapmail/Jwapmail/html/jwap.lib.php,v 1.4 2003/10/04 21:36:13 tripatti Exp $
/**********************************************************************
*
* a libray used for jmail
*
* Copyright (C) 2002 3WSI <http://3wsi.com)
*
* Author : Nasir Simbolon <hide@address.com>
*
* This program is open source; 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 <http://www.opensource.org/licenses/gpl-license.html>
* for a complete version of the license
*
**********************************************************************/
/* Wrap message with size $width
*/
function jWordwrap ($str, $width = 75, $break = '\n', $cut = 0) {
$s1 = split ("[[:space:]]", trim ($str));
$totalwords = count ($s1);
unset ($ww);
$j = 0;
$ww[$j] = '';
for ($i = 0; $i < $totalwords; $i++) {
$ww[$j] .= $s1[$i].' ';
if (strlen ($ww[$j] . $s1[$i + 1]) > $width){
$j++;
$ww[$j] = '';
}
}
$wwrap = '';
$totww= count ($ww);
if($totww <= 1) {
$wwrap = $ww[0];
return $wwrap;
}
for($k = 0; $k < ($totww - 1); $k++)
$wwrap .= $ww[$k].$break;
$wwrap .= $ww[$k];
return $wwrap;
}
/* Split word at the $break chars
*/
function jSplitword ($str, $break) {
return explode ($break, $str);
}
/* Abstraction purpose
*/
function jSplitmsg ($msg, $width) {
$break = '-+-';
$t = jWordwrap ($msg, $width, $break);
return jSplitword ($t, $break);
}
/* Register all variable for a session
*/
function registerVariables () {
$server = array ();
if (! is_set_and_not_empty ($_SESSION['username'])) {
$_SESSION['username'] = str_replace ('[/\;]', '', $_GET['username']);
}
if (! is_set_and_not_empty ($_SESSION['password'])) {
$_SESSION['password'] = $_GET['password'];
}
if (! is_set_and_not_empty ($_SESSION['inifile'])) {
$_SESSION['inifile'] =
USER_PROFILE_DATA_PATH .'/'. $_SESSION['username'];
}
$server = explode (':', $_GET['host']);
if (! is_set_and_not_empty ($_SESSION['host'])) {
$_SESSION['host'] =
(isset ($server[0]) && ! empty ($server[0]))
? $server[0]
: DEFAULT_SERVER_HOST;
}
if (! is_set_and_not_empty ($_SESSION['port'])) {
$_SESSION['port'] =
(isset ($server[1]) && ! empty ($server[1]))
? $server[1]
: DEFAULT_SERVER_PORT;
}
}
/* Send mail
*/
function sendMail ($to, $subject, $body, $header) {
// :TODO: Implent support for chrooted Apache environment
return mail ($to, $subject, $body, $header);
}
/* Create message with RFC822 compliance
*/
function messageRFC822 ($from) {
$header = 'From: ' . $from . "\r\n";
$header .= 'X-mailer: ' . X-MAILER . "\r\n";
return $header;
}
/* Set query for search message as argument for SEARCH imap
client commamd
*/
function setQuery ($inifile) {
$a = getSection ($inifile, 'Filter');
unset ($queries);
$j = 0;
foreach ($a as $rule) {
$x = explode (',', $rule);
$queries[$j]['rule'] = $x[0] . ' "' . $x[1] . '"';
$queries[$j]['mbox'] = $x[2];
$j++;
}
return $queries;
}
/* Filtering messages
*/
function filterMsg ($imap_conn) {
global $inifile;
if(! is_file ($_SESSION['inifile']))
return;
$a = setQuery ($inifile);
if(count ($a) > 0) {
while(list ($aa, $queri) = each ($a)) {
$msgs = searchMsg ($imap_conn, $queri['rule'], ',');
moveMsg ($imap_conn, 'INBOX', $msgs, $queri['mbox']);
}
}
return;
}
/* Perform search message
*/
function searchMsg ($imap_conn, $query, $separator) {
$res = imapSearch($imap_conn, $query);
$pattern = "^\* SEARCH ([0-9 ]*)\r\n";
ereg ($pattern, $res, $msg);
return ereg_replace ('[[:space:]]', $separator, $msg[1]);
}
/* wml entities
right now just assume same with html entties
*/
function wmlentities ($str) {
return htmlentities ($str);
}
function is_set_and_not_empty ($var) {
if (! isset ($var)) {
return false;
}
else {
if (empty ($var)) {
return false;
}
}
return true;
}
?>