Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) fixed bug described by Huppi in http://forum.yacy-websuche.de/viewtopic.php?t=239 *) added a preview function to message system *) removed some old comments, I hope that's OK
low012c8e5a4a6b793
diff --git a/htroot/MessageSend_p.html b/htroot/MessageSend_p.htmlindex 795181d19..1abab826a 100644--- a/htroot/MessageSend_p.html+++ b/htroot/MessageSend_p.html@@ -6,9 +6,9 @@</head><body id="MessageSend">#%env/templates/header.template%#- <h2>Send message</h2>#(mode)#<!-- =========================== write message =========================== -->+ <h2>Send message</h2>#(permission)#<!-- we have no permission to send the message --><p>You cannot send a message to <strong>#[peerName]#</strong>.<br />@@ -21,7 +21,7 @@You are allowed to send me a message ≤ #[messagesize]# kb and anattachment ≤ #[attachmentsize]#.</tt></p>-+<form action="MessageSend_p.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8"><fieldset><legend>Your Message</legend>@@ -46,6 +46,67 @@<input type="hidden" name="messagesize" value="#[messagesize]#" /><input type="hidden" name="attachmentsize" value="#[attachmentsize]#" /><input name="new" type="submit" value="Enter" />+ <input type="submit" name="preview" value="Preview" />+ </fieldset>+ </form>+ ::+ <!-- peer cannot respond -->+ <p>+ You cannot send a message to <strong>#[peerName]#</strong>.<br />+ The peer is alive but cannot respond. Sorry.+ </p>+ #(/permission)#+ ::+ <!-- =========================== preview message =========================== -->+ <h2>Preview message</h2>+ #(permission)#+ <!-- we have no permission to send the message -->+ <p>You cannot send a message to <strong>#[peerName]#</strong>.<br />+ The peer does not respond. It was now removed from the peer-list.+ </p>+ ::+ <!-- we have the permission to send the message -->+ <p>The peer <b>#[peerName]#</b> is alive and responded:</p>+ <p><tt class="MessageBackground">#[response]#+ You are allowed to send me a message ≤ #[messagesize]# kb and an+ attachment ≤ #[attachmentsize]#.</tt>+ </p>++ <p>The message has not been sent yet!</p>++ <dl class="pairs">+ <dt>Subject:</dt><dd>#[subject]#</dd>+ <dt>Message:</dt>+ <dd>+ #[previewmessage]#+ </dd>+ </dl>++ <form action="MessageSend_p.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">+ <fieldset>+ <legend>Your Message</legend>+ <dl>+ <dt>+ <label for="subject">Subject:</label>+ </dt>+ <dd>+ <input name="subject" id="subject" type="text" size="80" maxlength="80" value="#[subject]#" />+ </dd>+ <dt>+ <label for="message">Text:</label>+ </dt>+ <dd>+ <textarea name="message" id="message" cols="80" rows="8">#[message]#</textarea>+ <p class="help">+ You can use <a href="WikiHelp.html" onclick="window.open('WikiHelp.html','WikiHelp','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480');return false;">Wiki Code</a> here.+ </p>+ </dd>+ </dl>+ <input type="hidden" name="hash" value="#[hash]#" />+ <input type="hidden" name="messagesize" value="#[messagesize]#" />+ <input type="hidden" name="attachmentsize" value="#[attachmentsize]#" />+ <input name="new" type="submit" value="Enter" />+ <input type="submit" name="preview" value="Preview" /></fieldset></form>::@@ -57,6 +118,7 @@#(/permission)#::<!-- =========================== send message =========================== -->+ <h2>Send message</h2>#(status)#<!-- Message send successfully -->diff --git a/htroot/MessageSend_p.java b/htroot/MessageSend_p.javaindex 9196b4dc7..75e65cac2 100644--- a/htroot/MessageSend_p.java+++ b/htroot/MessageSend_p.java@@ -67,20 +67,22 @@ public class MessageSend_p {public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {serverObjects prop = new serverObjects();- //String body = "";if ((post == null) || (post.get("hash","").length() == 0)) {- prop.put("mode",2);- // prop.put("body", "<p>You cannot call this page directly. Instead, use a link on the <a href=\"Network.html\">Network</a> page.</p>");+ prop.put("mode",2);return prop;}String hash = post.get("hash", "");String subject = post.get("subject", "");String message = post.get("message", "");-- if (message.length() == 0) {- prop.put("mode", 0);-++ if ((message.length() == 0) || (post.containsKey("preview"))) {+ if (post.containsKey("preview")) {+ prop.put("mode", 1);+ } else {+ prop.put("mode", 0);+ }+// open an editor page for the message// first ask if the other peer is online, and also what kind of document it acceptsHashMap result = yacyClient.permissionMessage(hash);@@ -96,56 +98,48 @@ public class MessageSend_p {elsepeerName = targetPeer.get(yacySeed.NAME,"nameless");}-- prop.put("mode_permission_peerName", peerName);++ prop.put("mode_permission_peerName", peerName);String response = (result == null) ? "-1" : (String) result.get("response");if ((response == null) || (response.equals("-1"))) {- prop.put("mode_permission",0);-// we don't have permission or other peer does not exist- //body += "<p>You cannot send a message to '" + peerName + "'. The peer does not respond. It was now removed from the peer-list.</p>";+ prop.put("mode_permission",0);+if (targetPeer != null) {yacyCore.peerActions.peerDeparture(targetPeer);}} else {prop.put("mode_permission",1);-- // write input form- try {- int messagesize = Integer.parseInt((String) result.get("messagesize"));- int attachmentsize = Integer.parseInt((String) result.get("attachmentsize"));-- prop.put("mode_permission_response", response);- prop.put("mode_permission_messagesize", messagesize);- prop.put("mode_permission_attachmentsize", attachmentsize);- prop.put("mode_permission_subject", subject);- prop.put("mode_permission_message", message);- prop.put("mode_permission_hash", hash);--// body += "<p>The peer '" + peerName + "' is alive and responded:<br>";-// body += "'" + response + " You are allowed to send me a message ≤ " + messagesize + " kb and an attachment ≤ " + attachmentsize + ".'</p>";-// body += "<form action=\"MessageSend_p.html\" method=\"post\" enctype=\"multipart/form-data\" accept-charset=\"UTF-8\"><br><br>";-// body += "<p><h3>Your Message</h3></p>";-// body += "<p>Subject:<br><input name=\"subject\" type=\"text\" size=\"80\" maxlength=\"80\" value=\"" + subject + "\"></p>";-// body += "<p>Text:<br><textarea name=\"message\" cols=\"80\" rows=\"8\"></textarea></p>";-// body += "<input type=\"hidden\" name=\"hash\" value=\"" + hash + "\">";-// body += "<input type=\"hidden\" name=\"messagesize\" value=\"" + messagesize + "\">";-// body += "<input type=\"hidden\" name=\"attachmentsize\" value=\"" + attachmentsize + "\">";-// body += "<input name=\"new\" type=\"submit\" value=\"Enter\"></form>";- } catch (NumberFormatException e) {- // "unresolved pattern", the remote peer is alive but had an exception- //body += "<p>The peer '" + peerName + "' is alive but cannot respond. Sorry..</p>";- prop.put("mode_permission",2);- }++ // write input form+ try {+ int messagesize = Integer.parseInt((String) result.get("messagesize"));+ int attachmentsize = Integer.parseInt((String) result.get("attachmentsize"));++ prop.put("mode_permission_response", response);+ prop.put("mode_permission_messagesize", messagesize);+ prop.put("mode_permission_attachmentsize", attachmentsize);+ prop.put("mode_permission_subject", subject);+ prop.put("mode_permission_message", message);+ prop.put("mode_permission_hash", hash);+ if (post.containsKey("preview")) {+ prop.putWiki("mode_permission_previewmessage", message);++ }++ } catch (NumberFormatException e) {+ // "unresolved pattern", the remote peer is alive but had an exception+ prop.put("mode_permission",2);+ }}} else {- prop.put("mode", 1);+ prop.put("mode", 2);// send written message to peertry {prop.put("mode_status", 0);int messagesize = Integer.parseInt(post.get("messagesize", "0"));//int attachmentsize = Integer.parseInt(post.get("attachmentsize", "0"));-+if (messagesize < 1000) messagesize = 1000; // debugif (subject.length() > 100) subject = subject.substring(0, 100);if (message.length() > messagesize) message = message.substring(0, messagesize);@@ -156,23 +150,18 @@ public class MessageSend_p {mb = message.getBytes();}HashMap result = yacyClient.postMessage(hash, subject, mb);-- prop.put("mode_status_response", result.get("response"));-// body += "<p>Your message has been sent. The target peer responded:</p>";-// body += "<p><i>" + result.get("response") + "</i></p>";++ //message has been sent+ prop.put("mode_status_response", result.get("response"));+} catch (NumberFormatException e) {- prop.put("mode_status", 1);+ prop.put("mode_status", 1);+// "unresolved pattern", the remote peer is alive but had an exception- prop.put("mode_status_message", message);-// body += "<p>The target peer is alive but did not receive your message. Sorry..</p>";-// body += "<p>Here is a copy of your message, so you can copy it to save it for further attempts:<br>";-// body += message;-// body += "</p>";+ prop.put("mode_status_message", message);}}- // return rewrite properties- //prop.put("body", body);return prop;}diff --git a/htroot/Messages_p.java b/htroot/Messages_p.javaindex b482ec44f..6483a381c 100644--- a/htroot/Messages_p.java+++ b/htroot/Messages_p.java@@ -74,7 +74,7 @@ public class Messages_p {public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {plasmaSwitchboard switchboard = (plasmaSwitchboard) env;serverObjects prop = new serverObjects();-+// set peer address / namefinal String peerAddress = yacyCore.seedDB.mySeed.getPublicAddress();final String peerName = yacyCore.seedDB.mySeed.getName();@@ -106,10 +106,9 @@ public class Messages_p {} else {prop.put("peersKnown", 0);}-+prop.put("mode", 0);prop.put("mode_error", 0);- //wikiCode wikiTransformer = new wikiCode(switchboard);String action = ((post == null) ? "list" : post.get("action", "list"));messageBoard.entry message;@@ -143,28 +142,26 @@ public class Messages_p {prop.put("mode_messages_"+count+"_date", dateString(message.date()));prop.put("mode_messages_"+count+"_from", message.author());prop.put("mode_messages_"+count+"_to", message.recipient());- //prop.put("mode_messages_"+count+"_subject", wikiTransformer.transform(message.subject()));- //TODO: not needed, when all templates will be cleaned via replaceHTMLprop.put("mode_messages_"+count+"_subject", message.subject());prop.put("mode_messages_"+count+"_category", message.category());prop.put("mode_messages_"+count+"_key", key);prop.put("mode_messages_"+count+"_hash", message.authorHash());-+if (((String)header.get(httpHeader.CONNECTION_PROP_PATH)).endsWith(".rss")) {// set the peer addressprop.put("mode_messages_"+count+"_peerAddress", peerAddress);-+// set the rfc822 dateprop.put("mode_messages_"+count+"_rfc822Date",httpc.dateString(message.date()));-+// also write out the message body (needed for the RSS feed)try {prop.put("mode_messages_"+count+"_body",new String(message.message(), "UTF-8"));} catch (UnsupportedEncodingException e) {// can not happen, because UTF-8 must be supported by every JVM- }+ }}-+dark = !dark;count++;}@@ -180,12 +177,10 @@ public class Messages_p {String key = post.get("object", "");message = switchboard.messageDB.read(key);if (message == null) throw new NullPointerException("Message with ID " + key + " does not exist");-+prop.put("mode_from", message.author());prop.put("mode_to", message.recipient());prop.put("mode_date", dateString(message.date()));- //prop.put("mode_messages_subject", wikiTransformer.transform(message.subject()));- //TODO: not needed, when all templates will be cleaned via replaceHTMLprop.put("mode_subject", message.subject());String theMessage = null;try {diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.javaindex d520ef903..5b6e2a877 100644--- a/source/de/anomic/yacy/yacyClient.java+++ b/source/de/anomic/yacy/yacyClient.java@@ -609,11 +609,11 @@ public final class yacyClient {post.putASIS("myseed", yacyCore.seedDB.mySeed.genSeedStr(salt));post.putASIS("subject", subject);try {- post.put("message", new String(message, "UTF-8"));+ post.putASIS("message", new String(message, "UTF-8"));} catch (UnsupportedEncodingException e) {- post.put("message", new String(message));+ post.putASIS("message", new String(message));}-+// send requesttry {final HashMap result = nxTools.table(