// One program is released under the terms of the GNU General Public License.
include "config_ctdlclient.php";
-
+define('VIEW_BBS' ,'0'); /* Bulletin board view */
+define('VIEW_MAILBOX' ,'1'); /* Mailbox summary */
+define('VIEW_ADDRESSBOOK' ,'2'); /* Address book view */
+define('VIEW_CALENDAR' ,'3'); /* Calendar view */
+define('VIEW_TASKS' ,'4'); /* Tasks view */
+define('VIEW_NOTES' ,'5'); /* Notes view */
define("FMT_CITADEL", 0);
define("FMT_FIXED", 1);
define("FMT_RFC822", 4);
+function debugLog($string)
+{
+ print ($string);
+}
+
+function dbgprintf_wrapin($string, $html)
+{
+ if (!CITADEL_DEBUG_HTML){
+ if ($html)
+ debugLog("<< ".$string."\n");
+ }
+ else
+ printf($string);
+}
+function dbgprintf_wrapout($string, $html)
+{
+ if (!CITADEL_DEBUG_HTML){
+ if ($html)
+ debugLog("<< ".$string."\n");
+ }
+ else
+ printf($string);
+
+}
//--------------------------------------------------------------------------------
// internal functions for server communication
//--------------------------------------------------------------------------------
$buf = fgets($clientsocket, 4096); // Read line
$buf = substr($buf, 0, (strlen($buf)-1) ); // strip trailing LF
if (CITADEL_DEBUG_CITPROTO == 1) {
- if (!$readblock) printf ("<div class='ctdldbgRead'>\n");
- printf($buf);
- if (!$readblock) printf ("\n</div>\n");
- else printf ("<br>\n");
+ if (!$readblock) dbgprintf_wrapin("<div class='ctdldbgRead'>\n", false);
+ dbgprintf_wrapin($buf, true);
+ if (!$readblock) dbgprintf_wrapin ("\n</div>\n", false);
+ else dbgprintf_wrapin ("<br>\n", false);
}
return $buf;
}
global $clientsocket;
if (CITADEL_DEBUG_CITPROTO == 1) {
- printf ("<div class='ctdldbgRead'>\n");
- printf("reading ".$nBytes." bytes from server\n");
- printf ("</div>\n");
+ dbgprintf_wrapin ("<div class='ctdldbgRead'>\n", false);
+ dbgprintf_wrapin("reading ".$nBytes." bytes from server\n", true);
+ dbgprintf_wrapin ("</div>\n", false);
}
$buf = fread($clientsocket, $nBytes);
if (CITADEL_DEBUG_CITPROTO == 1) {
- if (!$buf) printf ("<div class='ctdldbgRead'>\n");
- printf($buf);
- if (!$buf) printf ("</div>\n");
- else printf ("<br>\n");
+ if (!$buf) dbgprintf_wrapin ("<div class='ctdldbgRead'>\n", false);
+ dbgprintf_wrapin($buf, true);
+ if (!$buf) dbgprintf_wrapin ("</div>\n", false);
+ else dbgprintf_wrapin ("<br>\n", false);
}
return $buf;
}
fwrite($clientsocket, $buf . "\n", (strlen($buf)+1) );
fflush($clientsocket);
- if (CITADEL_DEBUG_CITPROTO == 1)
- printf ("<div class='ctdldbgWrite'>".$buf."</div>\n");
+ if (CITADEL_DEBUG_CITPROTO == 1) {
+ dbgprintf_wrapin("<div class='ctdldbgWrite'>", false);
+ dbgprintf_wrapin($buf, true);
+ dbgprintf_wrapin("</div>\n", false);
+ }
}
function read_array() {
$nLines = 0;
if (CITADEL_DEBUG_CITPROTO == 1)
- printf ("<div class='ctdldbgRead'>\n");
+ dbgprintf_wrapout("<div class='ctdldbgRead'>\n", false);
$buf = serv_gets(TRUE);
$ret = array();
while (strcasecmp($buf, "000")){
$nLines++;
}
if (CITADEL_DEBUG_CITPROTO == 1){
- echo "read ".$nLines." lines from the server.\n";
- printf ("</div>\n");
+ dbgprintf_wrapout("read ".$nLines." lines from the server.\n", true);
+ dbgprintf_wrapout ("</div>\n", false);
}
return $ret;
}
function read_binary() {
$nLines = 0;
if (CITADEL_DEBUG_CITPROTO == 1)
- printf ("<div class='ctdldbgRead'>\n");
+ dbgprintf_wrapout ("<div class='ctdldbgRead'>\n", false);
$buf = serv_gets(TRUE);
if (CITADEL_DEBUG_CITPROTO == 1){
- echo "status line from the server\n";
+ dbgprintf_wrapout("status line from the server\n", true);
}
$statusline = explode(" ", $buf);
}
if (CITADEL_DEBUG_CITPROTO == 1)
- printf ("</div>\n");
+ dbgprintf_wrapout ("</div>\n", false);
return array($statusline, $buf);
}
serv_puts("USER " . $user);
$resp = serv_gets();
+
+ if (substr($resp, 0, 3) == 541) // we're already logged in.
+ return array(TRUE, substr($resp, 4));
if (substr($resp, 0, 1) != "3") {
+
return array(FALSE, substr($resp, 4));
}
function ctdl_get_serv_info() {
serv_puts("INFO");
$reply = read_array();
- if ((count($reply) == 18) &&
+ if ((count($reply) == 23) &&
substr($reply[0], 0, 1) == "1") {
$server_info=array();
$server_info["serv_nodename"] = $reply[1];
$server_info["serv_sysadmin"] = $reply[7];
if (CITADEL_DEBUG_CITPROTO == 1)
{
- echo "<pre>";
- print_r($server_info);
- echo "</pre>";
+ dbgprintf_wrapout("<pre>", false);
+ dbgprintf_wrapout(print_r($server_info, true), true);
+ dbgprintf_wrapout("</pre>", false);
}
return $server_info;
}
else
- die ("didn't understand the reply to the INFO command");
-
+ {
+ dbgprintf_wrapin ("didn't understand the reply to the INFO command".
+ print_r($reply, TRUE), false);
+
+ die ("CTDLPHP: didn't understand the reply to the INFO command");
+ }
}
//
function ctdl_get_registration_info() {
serv_puts("GREG");
$reply = read_array();
- print_r($reply);
+ dbgprintf_wrapout(print_r($reply, true), true);
// die ("didn't understand the reply to the INFO command");
}
return($msgtext);
}
+//
+// Delete a Message.
+// http://www.citadel.org/doku.php/documentation:appproto:room_indexes_and_messages#dele.delete.a.message
+
+function ctdl_dele($msgname) {
+ global $clientsocket;
+
+ $msgtext = "<DIV ALIGN=CENTER>\n";
+
+ serv_puts("DELE " . $msgname);
+ $response = serv_gets();
+
+ if (substr($response[0], 0, 1) == "1") {
+ return TRUE;
+ }
+ else {
+ return FALSE;
+ }
+}
+
/* http://www.citadel.org/doku.php/documentation:appproto:connection#mesg.read.system.message */
//// TODO: is this still supported?
function ctdl_mrtg($what) {
// IGnore the rest of the fields for now.
if (CITADEL_DEBUG_CITPROTO == 1)
{
- echo "<pre>";
- print_r($oneline);
- echo "</pre>";
+ dbgprintf_wrapout("<pre>", false);
+ dbgprintf_wrapout(print_r($oneline, true), true);
+ dbgprintf_wrapout("</pre>", false);;
}
$_SESSION["room"] = $room;
if (CITADEL_DEBUG_CITPROTO == 1)
{
- echo "<pre>";
- print_r($room_state);
- echo "</pre>";
+ dbgprintf_wrapout("<pre>", false);
+ dbgprintf_wrapout(print_r($room_state, true), true);
+ dbgprintf_wrapout("</pre>", false);
}
if (CITADEL_DEBUG_CITPROTO == 1)
{
- echo "<pre>";
- print_r($oneline);
- echo "</pre>";
+ dbgprintf_wrapout("<pre>", false);
+ dbgprintf_wrapout(print_r($oneline, true), true);
+ dbgprintf_wrapout("</pre>", false);
}
$num_lines = array_push($all_lines, $oneline);
if (CITADEL_DEBUG_CITPROTO == 1)
{
- echo "<pre>";
- print_r($oneline);
- echo "</pre>";
-
+ dbgprintf_wrapout("<pre>", false);
+ dbgprintf_wrapout(print_r($oneline, true), true);
+ dbgprintf_wrapout("</pre>", false);
}
$num_lines = array_push($all_lines, $oneline);
}
serv_puts("MSGS " . $mode . "|" . $count);
$responses = read_array();
- print_r($responses);
+ dbgprintf_wrapout(print_r($responses, true), false);
$response = array_shift($responses);
if (CITADEL_DEBUG_CITPROTO == 1)
{
- printf("found ".$num_msgs." messages.");
+ dbgprintf_wrapout("found ".$num_msgs." messages.", true);
}
return array($num_msgs, $response, $responses);
}
serv_puts("MSG4 " . $msgnum);
if (CITADEL_DEBUG_CITPROTO == 1)
- printf ("<div class='ctdldbgRead'>");
+ dbgprintf_wrapout("<div class='ctdldbgRead'>", false);
$response = serv_gets(TRUE);
if (substr($response, 0, 1) != "1") {
while (strcmp($buf = serv_gets(TRUE), "000")) {
if (substr($buf, 0, 4) == "text") {
if (CITADEL_DEBUG_CITPROTO == 1)
- printf ("</div>\n<h3>Message Body Follows</h3><div class='ctdldbgRead'>");
+ dbgprintf_wrapout("</div>\n<h3>Message Body Follows</h3><div class='ctdldbgRead'>", false);
// We're in the text body. New loop here.
- $fields["text"] = ctdl_msg4_from_server();
+ $texts = ctdl_msg4_from_server();
+ $fields["text"] = $texts[0];
+ $fields["formated_text"]=$texts[1];
if (CITADEL_DEBUG_CITPROTO == 1)
- printf ("</div>");
+ dbgprintf_wrapout ("</div>", false);
return array(TRUE, substr($response, 4), $fields);
}
else {
return array(FALSE, substr($response, 4), $fields);
}
+// Load a message from the server.
+function ctdl_fetch_message_rfc822($msgnum) {
+ global $clientsocket;
+
+ serv_puts("MSG2 " . $msgnum);
+
+ if (CITADEL_DEBUG_CITPROTO == 1)
+ dbgprintf_wrapout("<div class='ctdldbgRead'>", false);
+ $response = serv_gets(TRUE);
+
+ if (substr($response, 0, 1) != "1") {
+ return array(FALSE, NULL);
+ }
+ $message = "";
+ $buf="";
+ while ($buf = serv_gets(TRUE)) {
+// dbgprintf_wrapout($buf, true);
+ if ($buf=="000")
+ {
+ $message .= "\n.\n";
+ break;
+ }
+ $message = $message . "\n" . $buf;
+ $buf = "";
+ }
+
+// dbgprintf_wrapout($message, true);
+ // Message terminated prematurely (no text body)
+ return array(TRUE, $message);
+}
+
// Support function for ctdl_fetch_message(). This handles the text body
// portion of the message, converting various formats to HTML as
// appropriate.
function ctdl_msg4_from_server() {
$txt = "";
+ $modified_txt = "";
$msgformat = "text/plain";
$in_body = FALSE;
$txt .= $buf;
}
else if (!strcasecmp($msgformat, "text/plain")) {
- $txt .= "<TT>" . htmlspecialchars($buf) . "</TT><BR>\n" ;
+ $txt .= "\r\n".$buf;
+ $modified_txt .= "<TT>" . htmlspecialchars($buf) . "</TT><BR>\n" ;
+
}
else if (!strcasecmp($msgformat, "text/x-citadel-variformat")) {
if (substr($previous_line, 0, 1) == " ") {
}
}
- return($txt);
+ return(array($txt, $modified_txt));
}