insert|replace|write|overwrite|append|prepend)\s+(?P(?:in|into|on|to|at the (?:top|bottom) of)\s+)?\[\[(?P[\w.]+)\]\](?:\s+(?before|after|instead of|replacing)\s+(?\/.*?\/[msi]*))?/i"; Markup('WikiBoxForm', '\n"; $pop3=new pop3_class; $pop3->hostname=$WikiBoxHost; # POP 3 server host name $pop3->port=$WikiBoxPort; # POP 3 server host port, usually 110 but # some servers use other ports Gmail uses 995 $pop3->tls=$WikiBoxTLS; # Establish secure connections using TLS $user=$WikiBoxUser; # Authentication user name $password=$WikiBoxPass; # Authentication password $pop3->realm=$WikiBoxRealm; # Authentication realm or domain $pop3->workstation=$WikiBoxWorkstation;# Workstation for NTLM authentication $apop=$WikiBoxAPOP; # Use APOP authentication $pop3->authentication_mechanism=$WikiBoxAuthMech; # SASL authentication ... # ...mechanism $pop3->debug=$WikiBoxDebug; # Output debug information $pop3->html_debug=$WikiBoxHTMLDebug;# Debug information is in HTML $pop3->join_continuation_header_lines=$WikiBoxJoinHeader; # Concatenate ... # ... headers split in multiple lines SDV($WikiBoxMessagesPerPage, 5); $MessagesPerPage = ($opt['MESSAGES']) ? $opt['MESSAGES'] : $WikiBoxMessagesPerPage; # start with $_REQUEST['start'] or $opt['start'] or 1, in that order $Start = ($_REQUEST['start']) ? $_REQUEST['start'] : (($opt['START']) ? $opt['START'] : 1); if ($_REQUEST['next']) $Start += $MessagesPerPage; elseif ($_REQUEST['prev']) $Start = max($Start - $MessagesPerPage, 1); if ($opt['AUTO']) { $Auto = $opt['AUTO']; $MessagesPerPage = $Auto; // for looping } else $Auto = 0; if(($error=$pop3->Open())!="") { echo "ERROR: WikiBox: Cannot open the mailbox
\n"; if($error!="") echo "

Error: ",HtmlSpecialChars($error),"

"; return; } if(($error=$pop3->Login($user,$password,$apop))!="") { echo "ERROR: WikiBox: Cannot login to the mailbox
\n"; if($error!="") echo "

Error: ",HtmlSpecialChars($error),"

"; return; } if(($error=$pop3->Statistics($messages,$size))!="") { echo "ERROR: WikiBox: Cannot get statistics from the mailbox
\n"; if($error!="") echo "

Error: ",HtmlSpecialChars($error),"

"; return; } if ($messages <= 0) { $rtn = 'No mail messages to process.'; } else { $rtn = "(:input form method=POST:)"; $rtn .= '(:input hidden n {*$FullName}:)' . "\n"; $rtn .= "(:input default start $Start:)\n"; $rtn .= "(:input hidden start:)\n"; for ($i=$Start; $i <= min($messages, $Start+$MessagesPerPage-1); $i++) { if (($error=$pop3->RetrieveMessage($i,$headers,$body,-1))!="") { if($error!="") echo "

Error: ",HtmlSpecialChars($error),"

"; continue; } $body = implode("\n", $body); foreach ($headers as $h) { list($k, $v) = explode(":", $h, 2); $header[strtolower($k)] = trim($v); } $rtn .= "'''[+Message #${i}+]'''\n"; $rtn .= "(:table border=1 width=100%:)\n"; $rtn .= "(:cellnr width=65% valign=middle:)"; $rtn .= "'''COMMAND:''' "; $rtn .= "(:input default subject${i} \"$header[subject]\":)"; $rtn .= "(:input text subject${i} size=70 value=\"$header[subject]\":)\\\\\n"; if (!preg_match($WikiBoxSubjectPattern, $header['subject'], $m)) { $rtn .= "%red%ERROR - Invalid Command! Either edit the command or delete the message.%%\n"; if ($apply && !$opt['AUTO'] && $_REQUEST["act${i}"]=='apply') { echo "WikiBox: Non-matching subject command
\n"; continue; } if ($apply && $opt['AUTO'] && $opt['BADSUBJECT'] == 'ignore') continue; $BadSubject = true; $rtn .= "(:input default act${i} delete:)\n"; } else { $rtn .= "This command is valid. \n"; $rtn .= "(:input default act${i} apply:)\n"; $BadSubject = false; } $rtn .= "(:cell:)(:input radio name=act${i} value=\"delete\":) Discard & delete\\\\\n"; $rtn .= "(:input radio name=act${i} value=\"ignore\":) Ignore command (and don't delete)\\\\\n"; $rtn .= "(:input radio name=act${i} value=\"apply\":) Apply action & delete\n"; $rtn .= "(:cellnr colspan=2:)$body\n"; $rtn .= "(:tableend:)\n<:vspace>\n====\n<:vspace>\n"; if ($apply && ((!$Auto && $_REQUEST["act${i}"]=='apply') || ($Auto && !$BadSubject))) { if (!($page = RetrieveAuthPage($m['target'], 'edit'))) { echo "ERROR: WikiBox: No permission to write to $target
\n"; continue; } $newpage = $page; #echo "Starting text: >>$newpage[text]<<
\n"; $m['cmd'] = strtolower($m['cmd']); if ($m['cmd'] != 'insert' && $m['loc'] && $m['pat']) $m['cmd'] = 'insert'; switch ($m['cmd']) { case 'append': $newpage['text'] .= "\n" . $body; break; case 'prepend': $newpage['text'] = $body . "\n" . $newpage['text']; break; case 'insert': if (!$m['loc'] || !$m['pat']) { echo "ERROR: WikiBox: $header[subject]: location/pattern not specified correctly
\n"; continue; } if (!preg_match($m['pat'], $newpage['text'], $m1)) { echo "ERROR: WikiBox: $m[pat]: pattern not found
\n"; continue; } switch ($m['loc']) { case 'before': $newpage['text'] = str_replace($m1[0], $body.$m1[0], $newpage['text']); break; case 'after': $newpage['text'] = str_replace($m1[0], $m1[0].$body, $newpage['text']); break; case 'replacing': case 'instead of': $newpage['text'] = str_replace($m1[0], $body, $newpage['text']); break; } break; case 'write': case 'replace': case 'overwrite': $newpage['text'] = $body; break; } #echo "Writing >>$newpage[text]<< to $m[target]
\n"; if (!UpdatePage($m['target'], $page, $newpage)) { echo "ERROR: WikiBox: Error writing to $m[target]
\n"; continue; } } if ($apply && (!$Auto && ($_REQUEST["act${i}"]=='apply' || $_REQUEST["act${i}"]=='delete')) || ($Auto && (!$BadSubject || ($BadSubject && $opt['BADSUBJECT'] == 'delete')))) { if(($error=$pop3->DeleteMessage($i))!="") { echo "ERROR: WikiBox: Unable to delete message #${i}
\n"; if($error!="") echo "

Error: ",HtmlSpecialChars($error),"

"; continue; // not really necessary, but clearer... #echo "
Marked message 1 for deletion.
\n"; # While debugging it's convenient for messages to not be deleted... #if(false && ($error=$pop3->ResetDeletedMessages())=="") #{ #echo "
List of deleted messages has been reset.
\n"; #} } } } if ($error=="") $error=$pop3->Close(); $rtn .= "(:input submit Submit Submit:)\n"; if ($Start > 1) $rtn .= "(:input submit name=prev value=\"<>\" :)\n"; } return($rtn); } function WikiBoxOld($pagename, $parms) { global $WikiBoxHost, $WikiBoxPort, $WikiBoxTLS, $WikiBoxUser, $WikiBoxPass; global $WikiBoxRealm, $WikiBoxWorkstation, $WikiBoxAPOP, $WikiBoxAuthMech; global $WikiBoxDebug, $WikiBoxHTMLDebug, $WikiBoxJoinHeader; echo "WikiBoxOld(): Entering
\n"; $pop3=new pop3_class; $pop3->hostname=$WikiBoxHost; # POP 3 server host name $pop3->port=$WikiBoxPort; # POP 3 server host port, usually 110 but # some servers use other ports Gmail uses 995 $pop3->tls=$WikiBoxTLS; # Establish secure connections using TLS $user=$WikiBoxUser; # Authentication user name $password=$WikiBoxPass; # Authentication password $pop3->realm=$WikiBoxRealm; # Authentication realm or domain $pop3->workstation=$WikiBoxWorkstation;# Workstation for NTLM authentication $apop=$WikiBoxAPOP; # Use APOP authentication $pop3->authentication_mechanism=$WikiBoxAuthMech; # SASL authentication ... # ...mechanism $pop3->debug=$WikiBoxDebug; # Output debug information $pop3->html_debug=$WikiBoxHTMLDebug;# Debug information is in HTML $pop3->join_continuation_header_lines=$WikiBoxJoinHeader; # Concatenate ... # ... headers split in multiple lines if(($error=$pop3->Open())!="") { echo "ERROR: WikiBox: Cannot open the mailbox
\n"; if($error!="") echo "

Error: ",HtmlSpecialChars($error),"

"; return; } #echo "
Connected to the POP3 server "".$pop3->hostname."".
\n"; if(($error=$pop3->Login($user,$password,$apop))!="") { echo "ERROR: WikiBox: Cannot login to the mailbox
\n"; if($error!="") echo "

Error: ",HtmlSpecialChars($error),"

"; return; } #echo "
User "$user" logged in.
\n"; if(($error=$pop3->Statistics($messages,$size))!="") { echo "ERROR: WikiBox: Cannot get statistics from the mailbox
\n"; if($error!="") echo "

Error: ",HtmlSpecialChars($error),"

"; return; } echo "
There are $messages messages in the mail box with a total of $size bytes.
\n"; if ($messages > 0) { for ($i = 1; $i <= $messages; $i++) { if(($error=$pop3->RetrieveMessage($i,$headers,$body,-1))=="") { #echo "
Message 1:\n---Message headers starts below---
\n"; #for($line=0;$lineHEADER${line}: ",HtmlSpecialChars($headers[$line]),"\n"; $msg = implode("\n", $headers) . "\n" . implode("\n", $body); #$mime = new mime_parser_class; $param = array('Data' => $msg); #if (!$mime->Decode($param, $decoded)) { #echo "ERROR: WikiBox: Unable to decode the message
\n"; #return; #} #echo "
SUBJECT: " . $decoded['Headers']['subject'] . "
\n"; #echo "
FROM: " . $decoded['Headers']['from'] . "
\n"; #echo "
REPLY-TO: " . $decoded['Headers']['reply-to'] . "
\n"; #echo "
DATE: " . $decoded['Headers']['date'] . "
\n"; foreach ($headers as $h) { list($k, $v) = explode(":", $h, 2); $header[strtolower($k)] = $v; } if (!preg_match("/(?Pinsert|replace|write|overwrite|append|prepend)\s+(?P(?:in|into|on|to|at the (?:top|bottom) of)\s+)?\[\[(?P[\w.]+)\]\](?:\s+(?before|after|instead of|replacing)\s+(?\/.*?\/[msi]*))?/i", $header['subject'], $m)) { echo "WikiBox: Non-matching subject command
\n"; continue; } echo "SUBJECT: $header[subject], cmd=$m[cmd], page=$m[target], loc=$m[loc], $pat=$m[pat]
\n"; $body = implode("\n", $body); echo "BODY: $body
\n"; if (!($page = RetrieveAuthPage($m['target'], 'edit'))) { echo "ERROR: WikiBox: No permission to write to $target
\n"; return; } $newpage = $page; echo "Starting text: >>$newpage[text]<<
\n"; $m['cmd'] = strtolower($m['cmd']); if ($m['cmd'] != 'insert' && $m['loc'] && $m['pat']) $m['cmd'] = 'insert'; switch ($m['cmd']) { case 'append': $newpage['text'] .= "\n" . $body; break; case 'prepend': $newpage['text'] = $body . "\n" . $newpage['text']; break; case 'insert': if (!$m['loc'] || !$m['pat']) { echo "ERROR: WikiBox: $header[subject]: location/pattern not specified correctly
\n"; return; } if (!preg_match($m['pat'], $newpage['text'], $m1)) { echo "ERROR: WikiBox: $m[pat]: pattern not found
\n"; return; } switch ($m['loc']) { case 'before': $newpage['text'] = str_replace($m1[0], $body.$m1[0], $newpage['text']); break; case 'after': $newpage['text'] = str_replace($m1[0], $m1[0].$body, $newpage['text']); break; case 'replacing': case 'instead of': $newpage['text'] = str_replace($m1[0], $body, $newpage['text']); break; } break; case 'write': case 'replace': case 'overwrite': $newpage['text'] = $body; break; } echo "Writing >>$newpage[text]<< to $m[target]
\n"; if (!UpdatePage($m['target'], $page, $newpage)) { echo "ERROR: WikiBox: Error writing to $m[target]
\n"; return; } if(($error=$pop3->DeleteMessage($i))=="") { echo "
Marked message 1 for deletion.
\n"; # While debugging it's convenient for messages to not be deleted... if(false && ($error=$pop3->ResetDeletedMessages())=="") { echo "
List of deleted messages has been reset.
\n"; } } } } if($error=="" && ($error=$pop3->Close())=="") echo "
Disconnected from the POP3 server "".$pop3->hostname."".
\n"; } else $error=$result; } if (!function_exists("wdbg")) { # Printlevel indicates what level of importance this line is. # 0=never print # 1=very detailed debugging # 2=a little less detailed # 3=fairly normal debugging # 4=high-level, print it without thinking about it # (you can go higher, but the indentation doesn't work) function wdbg($printlevel, $text, $txt2 = '', $txt3 = '') { global $MessagesFmt, $WikiShVars; #if ($printlevel >= 3) echo "$text (" . (microtime(true) - $WikiShVars['SECONDS_START']) . ")
\n"; if ($printlevel<$WikiShVars['DEBUGLEVEL']) return; foreach (array($text, $txt2, $txt3) as $txt) { if ($txt == '') break; elseif (is_array($text)) { $MessagesFmt[] = "
" . print_r($text,true) . "
" . ($newline ? "\n" : ""); } else { $suffix = ""; for ($i = 4-$printlevel; $i > 0; $i--) { $prefix .= "
"; $suffix .= "
"; } $prefix .= "
  • "; $MessagesFmt[] = $prefix . $text . $suffix . "\n"; } #echo $MessagesFmt[sizeof($MessagesFmt)-1] . "
    \n"; } } } // if !function_exists() # DEVELOPMENT ROADMAP # There was an error where the NEXT wasn't displayed after applying/deleting # some of the actions. There were additional messages but no option to go to # them. # # MUST CODE THE AUTO=x option. Right now it's working basically in the form # implementation but neither coded nor tested in the auto implementation.