X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=ctdlphp%2Fctdlprotocol.php;h=80b5a3219739f227664bb79942009ca944a0d5e1;hb=fa2dd842abb5feedea3e2253255722fcaecc3c6f;hp=7770364112ffe252bf9ff5c583a8be43e992a79e;hpb=94912e04015f434aa68951d24a34a078771a8384;p=citadel.git diff --git a/ctdlphp/ctdlprotocol.php b/ctdlphp/ctdlprotocol.php index 777036411..80b5a3219 100644 --- a/ctdlphp/ctdlprotocol.php +++ b/ctdlphp/ctdlprotocol.php @@ -1,24 +1,86 @@ -// This program is released under the terms of the GNU General Public License. +// 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 +//-------------------------------------------------------------------------------- // // serv_gets() -- generic function to read one line of text from the server // -function serv_gets() { +function serv_gets($readblock=FALSE) { global $clientsocket; $buf = fgets($clientsocket, 4096); // Read line $buf = substr($buf, 0, (strlen($buf)-1) ); // strip trailing LF + if (CITADEL_DEBUG_CITPROTO == 1) { + if (!$readblock) dbgprintf_wrapin("
\n", false); + dbgprintf_wrapin($buf, true); + if (!$readblock) dbgprintf_wrapin ("\n
\n", false); + else dbgprintf_wrapin ("
\n", false); + } return $buf; } +// +// serv_get_n() -- generic function to read a binary blob from the server +// +function serv_get_n($nBytes) { + global $clientsocket; + + if (CITADEL_DEBUG_CITPROTO == 1) { + dbgprintf_wrapin ("
\n", false); + dbgprintf_wrapin("reading ".$nBytes." bytes from server\n", true); + dbgprintf_wrapin ("
\n", false); + } + $buf = fread($clientsocket, $nBytes); + if (CITADEL_DEBUG_CITPROTO == 1) { + if (!$buf) dbgprintf_wrapin ("
\n", false); + dbgprintf_wrapin($buf, true); + if (!$buf) dbgprintf_wrapin ("
\n", false); + else dbgprintf_wrapin ("
\n", false); + } + return $buf; +} // // serv_puts() -- generic function to write one line of text to the server @@ -27,25 +89,192 @@ function serv_puts($buf) { global $clientsocket; fwrite($clientsocket, $buf . "\n", (strlen($buf)+1) ); + fflush($clientsocket); + if (CITADEL_DEBUG_CITPROTO == 1) { + dbgprintf_wrapin("
", false); + dbgprintf_wrapin($buf, true); + dbgprintf_wrapin("
\n", false); + } } +function read_array() { + $nLines = 0; + if (CITADEL_DEBUG_CITPROTO == 1) + dbgprintf_wrapout("
\n", false); + $buf = serv_gets(TRUE); + $ret = array(); + while (strcasecmp($buf, "000")){ + array_push($ret, $buf); + $buf = serv_gets(TRUE); + $nLines++; + } + if (CITADEL_DEBUG_CITPROTO == 1){ + dbgprintf_wrapout("read ".$nLines." lines from the server.\n", true); + dbgprintf_wrapout ("
\n", false); + } + return $ret; +} +function read_binary() { + $nLines = 0; + if (CITADEL_DEBUG_CITPROTO == 1) + dbgprintf_wrapout ("
\n", false); + $buf = serv_gets(TRUE); + + if (CITADEL_DEBUG_CITPROTO == 1){ + dbgprintf_wrapout("status line from the server\n", true); + } + + $statusline = explode(" ", $buf); + + if ($statusline[0] == 600) + { + $buf = serv_get_n($statusline[1]); + + } + if (CITADEL_DEBUG_CITPROTO == 1) + dbgprintf_wrapout ("
\n", false); + return array($statusline, $buf); +} + + + +// +// text_to_server() -- sends a block of text to the server. Assumes that +// the server just sent back a SEND_LISTING response code +// and is now expecting a 000-terminated series of lines. +// Set 'convert_to_html' to TRUE to convert the block of +// text to HTML along the way. // -// Identify ourselves to the Citadel server (do this once after connection) +function text_to_server($thetext, $convert_to_html) { + + // HTML mode + if ($convert_to_html) { + + // Strip CR's; we only want the LF's + $thetext = trim($thetext, "\r"); + + // Replace hard line breaks with
's + $thetext = str_replace("\n", "
\n", $thetext); + + } + + // Either mode ... send it to the server now + $one_line = strtok($thetext, "\n"); + while ($one_line !== FALSE) { + $one_line = trim($one_line, "\n\r"); + if ($one_line == "000") $one_line = "-000" ; + serv_puts($one_line); + $one_line = strtok("\n"); + } + + serv_puts("000"); // Tell the server we're done... + + serv_puts("ECHO echo test."); // FIXME + echo "Echo test: " . serv_gets() . "
\n" ; + +} + +//-------------------------------------------------------------------------------- +// protocol commands +//-------------------------------------------------------------------------------- + + +// +// Identify ourselves to the Citadel server (do one once after connection) +/* http://www.citadel.org/doku.php/documentation:appproto:connection#iden.identify.the.client.software */ // -function ctdl_iden() { +function ctdl_iden($client_info) { global $clientsocket; + if (count($client_info) != 5) + die("ctdl_iden takes 5 arguments!"); // Identify client and hostname - serv_puts("IDEN 0|8|001|PHP web client|" . $_SERVER['REMOTE_ADDR'] ); + serv_puts("IDEN ".implode('|', $client_info)); $buf = serv_gets(); +} +function ctdl_MessageFormatsPrefered($formatlist){ // Also express our message format preferences - serv_puts("MSGP text/html|text/plain"); + serv_puts("MSGP ".implode("|", $formatlist)); $buf = serv_gets(); } +/* http://www.citadel.org/doku.php/documentation:appproto:connection#noop.no.operation */ +function ctdl_noop(){ + // Also express our message format preferences + serv_puts("NOOP "); + $buf = serv_gets(); +} + +/* http://www.citadel.org/doku.php/documentation:appproto:connection#quit.quit */ +function ctdl_quit(){ + // Also express our message format preferences + serv_puts("QUIT "); + $buf = serv_gets(); +} + + +/* http://www.citadel.org/doku.php/documentation:appproto:connection#mesg.read.system.message */ +function ctdl_gtls(){ + // Also express our message format preferences + serv_puts("GTLS "); + $buf = serv_gets(); + return $buf; +} + + +/* http://www.citadel.org/doku.php/documentation:appproto:connection#qnop.quiet.no.operation */ +/* this seems to be dangerous. ask IG +function ctdl_qnoop(){ + // Also express our message format preferences + serv_puts("QNOP "); +} +*/ + +/* http://www.citadel.org/doku.php/documentation:appproto:connection#echo.echo.something */ +function ctdl_doecho($echotext){ + // Also express our message format preferences + serv_puts("ECHO ".$echotext); + $buf = serv_gets(); + +} + +/* http://www.citadel.org/doku.php/documentation:appproto:connection#time.get.server.local.time */ +/* TODO: what are the other two params? doku is incomplete here. */ +function ctdl_time(){ + // Also express our message format preferences + serv_puts("TIME"); + $buf = serv_gets(); + +} + + +/* http://www.citadel.org/doku.php/documentation:appproto:connection#qdir.query.global.directory */ +function ctdl_qdir($who){ + // Also express our message format preferences + serv_puts("QDIR ".$who); + $buf = serv_gets(); + return array((substr($buf, 0, 1) == "2"), $buf); +} + + +/* http://www.citadel.org/doku.php/documentation:appproto:connection#auto.autocompletion.of.email.addresses */ +function ctdl_auto($who){ + // Also express our message format preferences + serv_puts("AUTO ".$who); + $buf = serv_gets(); + if (substr($buf, 0, 1) == "1") { + $reply = read_array(); + if (count($reply) == 0) + return false; + return $reply; + } + else + return false; +} + // @@ -53,13 +282,20 @@ function ctdl_iden() { // Returns an array with two variables: // 0. TRUE or FALSE to determine success or failure // 1. String error message (if relevant) +/* http://www.citadel.org/doku.php/documentation:appproto:connection#user.send.user.name */ +/* http://www.citadel.org/doku.php/documentation:appproto:connection#pass.send.password */ + // function login_existing_user($user, $pass) { global $clientsocket; 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)); } @@ -113,26 +349,15 @@ function create_new_user($user, $pass) { function become_logged_in($server_parms) { $_SESSION["logged_in"] = 1; - $tok = strtok($server_parms, "|"); - if ($tok) $thisline["username"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["axlevel"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["calls"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["posts"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["userflags"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["usernum"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["lastcall"] = $tok; + $tokens = explode("|", $server_parms); + + $oneline["username"] = $tokens[0]; + $oneline["axlevel"] = $tokens[1]; + $oneline["calls"] = $tokens[2]; + $oneline["posts"] = $tokens[3]; + $oneline["userflags"] = $tokens[4]; + $oneline["usernum"] = $tokens[5]; + $oneline["lastcall"] = $tokens[6]; ctdl_goto("_BASEROOM_"); } @@ -142,57 +367,115 @@ function become_logged_in($server_parms) { // // Learn all sorts of interesting things about the Citadel server to // which we are connected. +/* http://www.citadel.org/doku.php/documentation:appproto:connection#info.get.server.info */ // function ctdl_get_serv_info() { serv_puts("INFO"); - $buf = serv_gets(); - if (substr($buf, 0, 1) == "1") { - $i = 0; - do { - $buf = serv_gets(); - if ($i == 1) $_SESSION["serv_nodename"] = $buf; - if ($i == 2) $_SESSION["serv_humannode"] = $buf; - if ($i == 3) $_SESSION["serv_fqdn"] = $buf; - if ($i == 4) $_SESSION["serv_software"] = $buf; - if ($i == 6) $_SESSION["serv_city"] = $buf; - if ($i == 7) $_SESSION["serv_sysadmin"] = $buf; - $i = $i + 1; - } while (strcasecmp($buf, "000")); + $reply = read_array(); + if ((count($reply) == 23) && + substr($reply[0], 0, 1) == "1") { + $server_info=array(); + $server_info["serv_nodename"] = $reply[1]; + $server_info["serv_humannode"] = $reply[2]; + $server_info["serv_fqdn"] = $reply[3]; + $server_info["serv_software"] = $reply[4]; + $server_info["serv_city"] = $reply[6]; + $server_info["serv_sysadmin"] = $reply[7]; + if (CITADEL_DEBUG_CITPROTO == 1) + { + dbgprintf_wrapout("
", false);
+			dbgprintf_wrapout(print_r($server_info, true), true);
+			dbgprintf_wrapout("
", false); + } + return $server_info; + } + else + { + 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"); } +} + +// +// Learn all sorts of interesting things about the Citadel server to +// which we are connected. +/* http://www.citadel.org/doku.php/documentation:appproto:connection#info.get.server.info */ +// +function ctdl_get_registration_info() { + serv_puts("GREG"); + $reply = read_array(); + dbgprintf_wrapout(print_r($reply, true), true); +// die ("didn't understand the reply to the INFO command"); } // // Display a system banner. (Returns completed HTML.) -// (This is probably temporary because it outputs more or less finalized +// (One is probably temporary because it outputs more or less finalized // markup. For now it's just usable.) // +/* http://www.citadel.org/doku.php/documentation:appproto:connection#mesg.read.system.message */ function ctdl_mesg($msgname) { global $clientsocket; $msgtext = "
\n"; serv_puts("MESG " . $msgname); - $response = serv_gets(); + $response = read_array(); - if (substr($response, 0, 1) == "1") { - while (strcmp($buf = serv_gets(), "000")) { - $msgtext .= "" . htmlspecialchars($buf) - . "
\n" ; - } + if (substr($response[0], 0, 1) == "1") { + array_shift($response); // throw away the status code. + $msgtext .= "" . implode( "
\n" ,$response); } else { - $msgtext .= "" . substr($response, 4) . "
\n"; + $msgtext .= "" . substr($response[0], 4) . "
\n"; } $msgtext .= "
\n"; 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 = "
\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) { + global $clientsocket; + + serv_puts("MRTG ".$what); + $response = serv_gets(); + + if (substr($response, 0, 1) != "1") { + return array(0, NULL); + } + + $responses = read_array(); + return $responses; +} // // Fetch the list of users currently logged in. +/* http://www.citadel.org/doku.php/documentation:appproto:connection#rwho.read.who.s.online */ // function ctdl_rwho() { global $clientsocket; @@ -206,29 +489,36 @@ function ctdl_rwho() { $all_lines = array(); $num_lines = 0; + + $responses = read_array(); + foreach ($responses as $response) { + $tokens = explode("|", $response); + $oneline = array(); + + $oneline["session"] = $tokens[0]; + $oneline["user"] = $tokens[1]; + $oneline["room"] = $tokens[2]; + $oneline["host"] = $tokens[3]; + $oneline["client"] = $tokens[4]; + $oneline["idlesince"] = $tokens[5]; + $oneline["lastcmd"] = $tokens[6]; + $oneline["flags"] = $tokens[7]; + $oneline["realname"] = $tokens[8]; + $oneline["realroom"] = $tokens[9]; + $oneline["realhostname"] = $tokens[10]; + $oneline["registered"] = $tokens[11]; - while (strcmp($buf = serv_gets(), "000")) { - - $thisline = array(); - - $tok = strtok($buf, "|"); - if ($tok) $thisline["session"] = $tok; + // IGnore the rest of the fields for now. + if (CITADEL_DEBUG_CITPROTO == 1) + { + dbgprintf_wrapout("
", false);
+			dbgprintf_wrapout(print_r($oneline, true), true);
+			dbgprintf_wrapout("
", false);; - $tok = strtok("|"); - if ($tok) $thisline["user"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["room"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["host"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["client"] = $tok; + } - // IGnore the rest of the fields for now. - $num_lines = array_push($all_lines, $thisline); + $num_lines = array_push($all_lines, $oneline); } return array($num_lines, $all_lines); @@ -244,13 +534,44 @@ function ctdl_goto($to_where) { serv_puts("GOTO " . $to_where); $response = serv_gets(); - if (substr($response, 0, 1) == "2") { - $_SESSION["room"] = strtok(substr($response, 4), "|"); - return array(TRUE, substr($response, 0, 3)); + $results = explode ("|", $response); + $status_room = array_shift($results); + $status = substr($status_room, 0, 3); + if (substr($status, 0, 1) == "2") { + $room = substr($status_room, 4); + array_unshift($results, $room); + $room_state=array( + "state" => TRUE, + "statereply" => $status, + "roomname" => $results[ 0], + "nunreadmsg" => $results[ 1], + "nmessages" => $results[ 2], + "rinfopresent" => $results[ 3], + "flags" => $results[ 4], + "msgidmax" => $results[ 5], + "msgidreadmax" => $results[ 6], + "ismailroom" => $results[ 7], + "isroomaide" => $results[ 8], + "nnewmessages" => $results[ 9], + "floorid" => $results[10], + "viewselected" => $results[11], + "defaultview" => $results[12], + "istrashcan" => $results[13]); + + $_SESSION["room"] = $room; + if (CITADEL_DEBUG_CITPROTO == 1) + { + dbgprintf_wrapout("
", false);
+			dbgprintf_wrapout(print_r($room_state, true), true);
+			dbgprintf_wrapout("
", false); + + } + + return $room_state; } else { - return array(FALSE, substr($response, 0, 3)); + return array("state" => FALSE, "statereply" => $status); } } @@ -265,73 +586,108 @@ function ctdl_knrooms() { serv_puts("LKRA"); $response = serv_gets(); - if (substr($response, 0, 1) != "1") { return array(0, NULL); } - + $results = read_array(); $all_lines = array(); $num_lines = 0; - while (strcmp($buf = serv_gets(), "000")) { - - $thisline = array(); + foreach ($results as $result){ + $oneline = array(); + $tokens = explode("|",$result); - $tok = strtok($buf, "|"); - if ($tok) $thisline["name"] = $tok; + $oneline["name"] = $tokens[0]; + $oneline["flags"] = $tokens[1]; + $oneline["floor"] = $tokens[2]; + $oneline["order"] = $tokens[3]; + $oneline["flags2"] = $tokens[4]; + $oneline["access"] = $tokens[5]; - $tok = strtok("|"); - if ($tok) $thisline["flags"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["floor"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["order"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["flags2"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["access"] = $tok; - - if ($thisline["access"] & 8) { - $thisline["hasnewmsgs"] = TRUE; + if ($oneline["access"] & 8) { + $oneline["hasnewmsgs"] = TRUE; } else { - $thisline["hasnewmsgs"] = FALSE; + $oneline["hasnewmsgs"] = FALSE; + } + + if (CITADEL_DEBUG_CITPROTO == 1) + { + dbgprintf_wrapout("
", false);
+			dbgprintf_wrapout(print_r($oneline, true), true);
+			dbgprintf_wrapout("
", false); + } + $num_lines = array_push($all_lines, $oneline); + } + + return array($num_lines, $all_lines); + +} - $num_lines = array_push($all_lines, $thisline); +// +// Fetch the list of known floors. +// +/* http://www.citadel.org/doku.php/documentation:appproto:rooms#lflr.list.all.known.floors */ +function ctdl_knfloors() { + global $clientsocket; + + serv_puts("LFLR"); + $response = serv_gets(); + if (substr($response, 0, 1) != "1") { + return array(0, NULL); + } + + $results = read_array(); + $all_lines = array(); + $num_lines = 0; + + foreach ($results as $result){ + $oneline = array(); + $tokens = explode("|",$result); + + $oneline["id"] = $tokens[0]; + $oneline["name"] = $tokens[1]; + $oneline["nref"] = $tokens[2]; + + if (CITADEL_DEBUG_CITPROTO == 1) + { + dbgprintf_wrapout("
", false);
+			dbgprintf_wrapout(print_r($oneline, true), true);
+			dbgprintf_wrapout("
", false); + } + $num_lines = array_push($all_lines, $oneline); } return array($num_lines, $all_lines); } +/* http://www.citadel.org/doku.php/documentation:appproto:rooms#cflr.create.a.new.floor */ // -// Fetch the list of messages in this room. +// Fetch the list of messages in one room. // Returns: count, response, message array // function ctdl_msgs($mode, $count) { global $clientsocket; serv_puts("MSGS " . $mode . "|" . $count); - $response = serv_gets(); + $responses = read_array(); + dbgprintf_wrapout(print_r($responses, true), false); + + $response = array_shift($responses); + $num_msgs = count($responses); if (substr($response, 0, 1) != "1") { return array(0, substr($response, 4), NULL); } - $msgs = array(); - $num_msgs = 0; - - while (strcmp($buf = serv_gets(), "000")) { - $num_msgs = array_push($msgs, $buf); + if (CITADEL_DEBUG_CITPROTO == 1) + { + dbgprintf_wrapout("found ".$num_msgs." messages.", true); } - - return array($num_msgs, substr($response, 4), $msgs); + return array($num_msgs, $response, $responses); } @@ -340,17 +696,26 @@ function ctdl_fetch_message($msgnum) { global $clientsocket; serv_puts("MSG4 " . $msgnum); - $response = serv_gets(); + + if (CITADEL_DEBUG_CITPROTO == 1) + dbgprintf_wrapout("
", false); + $response = serv_gets(TRUE); if (substr($response, 0, 1) != "1") { return array(FALSE, substr($response, 4), NULL); } $fields = array(); - while (strcmp($buf = serv_gets(), "000")) { + while (strcmp($buf = serv_gets(TRUE), "000")) { if (substr($buf, 0, 4) == "text") { + if (CITADEL_DEBUG_CITPROTO == 1) + dbgprintf_wrapout("
\n

Message Body Follows

", 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) + dbgprintf_wrapout ("
", false); return array(TRUE, substr($response, 4), $fields); } else { @@ -362,17 +727,49 @@ function ctdl_fetch_message($msgnum) { return array(FALSE, substr($response, 4), $fields); } -// Support function for ctdl_fetch_message(). This handles the text body +// 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("
", 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; $previous_line = ""; - while (strcmp($buf = serv_gets(), "000")) { + while (strcmp($buf = serv_gets(TRUE), "000")) { if ($in_body == FALSE) { if (strlen($buf) == 0) { $in_body = TRUE; @@ -388,7 +785,9 @@ function ctdl_msg4_from_server() { $txt .= $buf; } else if (!strcasecmp($msgformat, "text/plain")) { - $txt .= "" . htmlspecialchars($buf) . "
\n" ; + $txt .= "\r\n".$buf; + $modified_txt .= "" . htmlspecialchars($buf) . "
\n" ; + } else if (!strcasecmp($msgformat, "text/x-citadel-variformat")) { if (substr($previous_line, 0, 1) == " ") { @@ -403,7 +802,90 @@ function ctdl_msg4_from_server() { } } - return($txt); + return(array($txt, $modified_txt)); +} + + + +function download_attachment($msgnum, $attindex) +{ + $command = "DLAT ".$msgnum."|".$attindex; + serv_puts($command); + $reply = read_binary(); + return $reply; + +} + + +function enter_message_0($msgHdr, $contentType, $data) +{ + $send = array(); + + if (isset($msgHdr['newusermail'])) + array_unshift($send, $msgHdr['newusermail']); + else + array_unshift($send, ""); + + if (isset($msgHdr['supplied_euid'])) + array_unshift($send, $msgHdr['supplied_euid']); + else + array_unshift($send, ""); + + if (isset($msgHdr['bcc'])) + array_unshift($send, $msgHdr['bcc']); + else + array_unshift($send, ""); + + if (isset($msgHdr['cc'])) + array_unshift($send, $msgHdr['cc']); + else + array_unshift($send, ""); + + if (isset($msgHdr['do_confirm'])) + array_unshift($send, $msgHdr['do_confirm']); + else + array_unshift($send, ""); + + if (isset($msgHdr['newusername'])) + array_unshift($send, $msgHdr['newusername']); + else + array_unshift($send, ""); + + if (isset($msgHdr['subject'])) + array_unshift($send, $msgHdr['subject']); + else + array_unshift($send, ""); + + if (isset($msgHdr['format_type'])) + array_unshift($send, $msgHdr['format_type']); + else + array_unshift($send, ""); + + if (isset($msgHdr['anon_flag'])) + array_unshift($send, $msgHdr['anon_flag']); + else + array_unshift($send, ""); + + if (isset($msgHdr['recp'])) + array_unshift($send, $msgHdr['recp']); + else + array_unshift($send, ""); + + if (isset($msgHdr['post'])) + array_unshift($send, $msgHdr['post']); + else + array_unshift($send, ""); + + $params = implode('|', $send); + serv_puts("ENT0 ".$params); + + $reply=serv_gets(); + if (substr($reply, 0, 1) != 4) + return array(false, array(), array()); + serv_puts("Content-type: ".$contentType); + serv_puts(""); + serv_puts($data."\r\n"); + serv_puts("000"); }