diff --git a/src/server/cache.h b/src/server/cache.h
index 7756389d87da9f71535d684b3e364d9f4f64d91d..24391e24324a1dd2111b8e91b5c3cf29cf95968d 100644
--- a/src/server/cache.h
+++ b/src/server/cache.h
@@ -1,5 +1,5 @@
 /*
- * $Id: cache.h,v 0.7 1991/09/15 10:33:05 linus Exp $
+ * $Id: cache.h,v 0.8 1991/11/10 19:02:48 linus Exp $
  * Copyright (C) 1991  Lysator Academic Computer Association.
  *
  * This file is part of the LysKOM server.
@@ -23,7 +23,7 @@
  * Please mail bug reports to bug-lyskom@lysator.liu.se. 
  */
 /*
- * $Id: cache.h,v 0.7 1991/09/15 10:33:05 linus Exp $
+ * $Id: cache.h,v 0.8 1991/11/10 19:02:48 linus Exp $
  *
  * This file contains the cached data that the server stores.
  * .h file created by ceder 1990-04-18
@@ -252,3 +252,9 @@ dump_cache_stats(FILE *stat_file);
  */
 void
 dump_cache_mem_usage(FILE *stat_file);
+
+/*
+ * Export the highest text_no for searching.
+ */
+int
+query_next_text_num(void);
diff --git a/src/server/call-switch.awk b/src/server/call-switch.awk
index e764faa3b2e16f7177a6e58b958f59b38532796f..46cdbb5f3b7dd64fa33ba0112785962fb896c26e 100644
--- a/src/server/call-switch.awk
+++ b/src/server/call-switch.awk
@@ -1,5 +1,5 @@
 #
-# $Id: call-switch.awk,v 0.3 1991/09/15 10:33:01 linus Exp $
+# $Id: call-switch.awk,v 0.4 1991/11/10 19:02:43 linus Exp $
 # Copyright (C) 1991  Lysator Academic Computer Association.
 #
 # This file is part of the LysKOM server.
@@ -22,7 +22,7 @@
 #
 # Please mail bug reports to bug-lyskom@lysator.liu.se. 
 #
-# $Id: call-switch.awk,v 0.3 1991/09/15 10:33:01 linus Exp $
+# $Id: call-switch.awk,v 0.4 1991/11/10 19:02:43 linus Exp $
 BEGIN {
     printf("/* Don't edit this file - it is generated automatically");
     printf(" from\n   call-switch.awk and fncdef.txt */\n");
@@ -61,6 +61,8 @@ $1 != "#" {
 	    printf("client->c_local_text_no_p");
 	else if ( $i == "c_misc_info_p" )
 	    printf("client->c_misc_info_p");
+	else if ( $i == "time_date" )
+	    printf("timelocal(&(client->time))");
 	else
 	    printf("\n#error in file server/fncdef.txt\n");
     }
diff --git a/src/server/connections.h b/src/server/connections.h
index 290c4a2d8f7a661d5de792b00809dde7bcde5196..f4c47a8e188ade955d7caa9b8aa86bd0abffa0f2 100644
--- a/src/server/connections.h
+++ b/src/server/connections.h
@@ -1,5 +1,5 @@
 /*
- * $Id: connections.h,v 0.5 1991/09/15 10:32:44 linus Exp $
+ * $Id: connections.h,v 0.6 1991/11/10 19:02:39 linus Exp $
  * Copyright (C) 1991  Lysator Academic Computer Association.
  *
  * This file is part of the LysKOM server.
@@ -23,7 +23,7 @@
  * Please mail bug reports to bug-lyskom@lysator.liu.se. 
  */
 /*
- * $Id: connections.h,v 0.5 1991/09/15 10:32:44 linus Exp $
+ * $Id: connections.h,v 0.6 1991/11/10 19:02:39 linus Exp $
  *
   * connections.h -- The top level of the communication packet.
   *
@@ -87,6 +87,7 @@ typedef struct connection {
     Local_text_no      *c_local_text_no_p; /* Freead by free_parsed(). */
     Priv_bits		priv_bits;
     Conf_type		conf_type;
+    struct tm		time;
 
     /* Protocol independent things. */
     
@@ -123,7 +124,7 @@ Connection * active_connection;
  * This enum describes the result of a function in services.c.
  */
 typedef enum {
-    rt_number,			/* E.g. Pers_no, Conf_no, Text_no, time_t.
+    rt_number,			/* E.g. Pers_no, Conf_no, Text_no.
 				   This is somewhat special in that the
 				   function indicates an error by returning
 				   0 and not FAILURE. */
@@ -147,7 +148,8 @@ typedef enum {
     rt_member_list,
     rt_time_date,
     rt_session_info,
-    rt_session_no
+    rt_session_no,
+    rt_text_no
 } Res_type;
 
 /*
@@ -172,6 +174,7 @@ typedef union {
 	time_t			  time_date;
 	Session_info		  session_info;
 	Session_no		  session_no;
+	Text_no			  text_no;
 } Result_holder;
 
 
diff --git a/src/server/fncdef.txt b/src/server/fncdef.txt
index 259d555365ecb5015749b7fb3d4ecb1c4a051106..51518237ad68980d9e46b57bca23555ae457ded5 100644
--- a/src/server/fncdef.txt
+++ b/src/server/fncdef.txt
@@ -1,5 +1,5 @@
 #
-# $Id: fncdef.txt,v 0.5 1991/09/15 10:32:06 linus Exp $
+# $Id: fncdef.txt,v 0.6 1991/11/10 19:02:35 linus Exp $
 # Copyright (C) 1991  Lysator Academic Computer Association.
 #
 # This file is part of the LysKOM server.
@@ -22,7 +22,7 @@
 #
 # Please mail bug reports to bug-lyskom@lysator.liu.se. 
 #
-# $Id: fncdef.txt,v 0.5 1991/09/15 10:32:06 linus Exp $
+# $Id: fncdef.txt,v 0.6 1991/11/10 19:02:35 linus Exp $
 # 
 # This file is used to describe the functions in services.c. All
 # functions that are reachable from the clients are listed here, together
@@ -93,3 +93,4 @@ success get_session_info num : session_info
 success disconnect	 num
 success who_am_i	 : session_no
 success set_user_area	 num num
+success get_last_text	 time_date : text_no
diff --git a/src/server/internal-connections.c b/src/server/internal-connections.c
index e350304367ba089b837ee971b10d93577e4ce166..cdc1ecf688a7aba19594864a70537b8a1e201825 100644
--- a/src/server/internal-connections.c
+++ b/src/server/internal-connections.c
@@ -1,5 +1,5 @@
 /*
- * $Id: internal-connections.c,v 0.6 1991/10/29 03:16:56 ceder Exp $
+ * $Id: internal-connections.c,v 0.7 1991/11/10 19:02:31 linus Exp $
  * Copyright (C) 1991  Lysator Academic Computer Association.
  *
  * This file is part of the LysKOM server.
@@ -28,7 +28,7 @@
  * Abstract routines on the data type Connection.
  */
 
-static char *rcsid = "$Id: internal-connections.c,v 0.6 1991/10/29 03:16:56 ceder Exp $";
+static char *rcsid = "$Id: internal-connections.c,v 0.7 1991/11/10 19:02:31 linus Exp $";
 
 
 #include "exp.h"
@@ -55,7 +55,8 @@ INTERNAL const Connection EMPTY_CONNECTION =
 		      0, 0, 0, 0, 0, 0, 0,
 		      0, 0, 0, 0, EMPTY_STRING_i, EMPTY_STRING_i,
 		      EMPTY_STRING_i, NULL, NULL, DEFAULT_PRIV_BITS_i,
-		      NULL_CONF_TYPE_i, EMPTY_STRING_i, 0, FALSE, NO_TIME,
+		      NULL_CONF_TYPE_i, EMPTY_tm_i, EMPTY_STRING_i, 0, FALSE,
+		      NO_TIME,
 		      0, FALSE});
 
 static int  no_of_allocated_connections = 0;
diff --git a/src/server/prot-a-output.c b/src/server/prot-a-output.c
index 105038eea0d87a3395c7f0b73ab7d10b1e0d2d24..9292cd3d20f09e8db7c27c7e2aa4e1be10ddaecd 100644
--- a/src/server/prot-a-output.c
+++ b/src/server/prot-a-output.c
@@ -1,5 +1,5 @@
 /*
- * $Id: prot-a-output.c,v 0.5 1991/10/29 14:52:29 linus Exp $
+ * $Id: prot-a-output.c,v 0.6 1991/11/10 19:02:26 linus Exp $
  * Copyright (C) 1991  Lysator Academic Computer Association.
  *
  * This file is part of the LysKOM server.
@@ -28,7 +28,7 @@
  * Written by ceder 1990-07-13
  */
 
-static char *rcsid = "$Id: prot-a-output.c,v 0.5 1991/10/29 14:52:29 linus Exp $";
+static char *rcsid = "$Id: prot-a-output.c,v 0.6 1991/11/10 19:02:26 linus Exp $";
 
 
 #include <kom-types.h>
@@ -526,3 +526,10 @@ prot_a_output_session_no(Connection *fp,
 {
     mux_printf(fp, " %lu", (u_long) session_no);
 }
+
+void
+prot_a_output_text_no(Connection *fp,
+		      Text_no text)
+{
+    mux_printf(fp, " %lu", text);
+}
diff --git a/src/server/prot-a-parse-arg-c.awk b/src/server/prot-a-parse-arg-c.awk
index 726aca9412b8700d40e83d81b059c9cd4c395bbe..6136612cbcdc7fc487bf4ac0d619c1fed4c7f3e3 100644
--- a/src/server/prot-a-parse-arg-c.awk
+++ b/src/server/prot-a-parse-arg-c.awk
@@ -1,5 +1,5 @@
 #
-# $Id: prot-a-parse-arg-c.awk,v 0.3 1991/09/15 10:30:20 linus Exp $
+# $Id: prot-a-parse-arg-c.awk,v 0.4 1991/11/10 19:02:22 linus Exp $
 # Copyright (C) 1991  Lysator Academic Computer Association.
 #
 # This file is part of the LysKOM server.
@@ -22,14 +22,14 @@
 #
 # Please mail bug reports to bug-lyskom@lysator.liu.se. 
 #
-# $Id: prot-a-parse-arg-c.awk,v 0.3 1991/09/15 10:30:20 linus Exp $
+# $Id: prot-a-parse-arg-c.awk,v 0.4 1991/11/10 19:02:22 linus Exp $
 BEGIN {
     printf("/* Don't edit this file - it is generated automatically");
     printf(" from\n   prot-a-parse-arg-c.awk and fncdef.txt */\n\n");
     printf("#include <setjmp.h>\n");
     printf("#include <kom-types.h>\n");
     printf("#include \"com.h\"\n");
-    printf("#include \"isc.h\"\n");
+    printf("#include \"isc-interface.h\"\n");
     printf("#include \"connections.h\"\n");
     printf("#include \"isc-parse.h\"\n");
     printf("#include <server/smalloc.h>\n");
@@ -115,6 +115,18 @@ $1 != "#" {
 	    printf("\tif ( parse_nonwhite_char(client) != '}' )\n");
 	    printf("\t    longjmp(parse_env, ISC_PROTOCOL_ERR);\n");
 	}
+	else if ( $i == "time_date" )
+	{
+	    printf("\tclient->time.tm_sec = prot_a_parse_long(client);\n");
+	    printf("\tclient->time.tm_min = prot_a_parse_long(client);\n");
+	    printf("\tclient->time.tm_hour = prot_a_parse_long(client);\n");
+	    printf("\tclient->time.tm_mday = prot_a_parse_long(client);\n");
+	    printf("\tclient->time.tm_mon = prot_a_parse_long(client);\n");
+	    printf("\tclient->time.tm_year = prot_a_parse_long(client);\n");
+	    printf("\tclient->time.tm_wday = prot_a_parse_long(client);\n");
+	    printf("\tclient->time.tm_yday = prot_a_parse_long(client);\n");
+	    printf("\tclient->time.tm_isdst = prot_a_parse_long(client);\n");
+	}
 	else
 	    printf("#error in prot-a-parse-arg-c.awk: not ready yet.\n");
 
diff --git a/src/server/prot-a.c b/src/server/prot-a.c
index 3c3fc006b2237bc1d7355d80e1df71980b042e5b..a71f2f84a74c0c2009df24ee6b035c3f39063e54 100644
--- a/src/server/prot-a.c
+++ b/src/server/prot-a.c
@@ -1,5 +1,5 @@
 /*
- * $Id: prot-a.c,v 0.8 1991/09/21 13:06:53 ceder Exp $
+ * $Id: prot-a.c,v 0.9 1991/11/10 19:02:18 linus Exp $
  * Copyright (C) 1991  Lysator Academic Computer Association.
  *
  * This file is part of the LysKOM server.
@@ -26,7 +26,7 @@
  * Protocol A.
  */
 
-static char *rcsid = "$Id: prot-a.c,v 0.8 1991/09/21 13:06:53 ceder Exp $";
+static char *rcsid = "$Id: prot-a.c,v 0.9 1991/11/10 19:02:18 linus Exp $";
 
 
 #include <stdio.h>
@@ -290,6 +290,7 @@ prot_a_is_legal_fnc(Call_header fnc)
     case call_fnc_disconnect:
     case call_fnc_who_am_i:
     case call_fnc_set_user_area:
+    case call_fnc_get_last_text:
 	return TRUE;
 
     default:
diff --git a/src/server/simple-cache.c b/src/server/simple-cache.c
index 1f2c3ac82156efe4bbef59c97b80fc10c760926b..f6b97a792cb1d0402ed78ac04f40364f714759c6 100644
--- a/src/server/simple-cache.c
+++ b/src/server/simple-cache.c
@@ -1,5 +1,5 @@
 /*
- * $Id: simple-cache.c,v 0.17 1991/09/21 13:06:45 ceder Exp $
+ * $Id: simple-cache.c,v 0.18 1991/11/10 19:02:11 linus Exp $
  * Copyright (C) 1991  Lysator Academic Computer Association.
  *
  * This file is part of the LysKOM server.
@@ -33,7 +33,7 @@
  * New save algorithm by ceder.
  */
 
-static char *rcsid = "$Id: simple-cache.c,v 0.17 1991/09/21 13:06:45 ceder Exp $";
+static char *rcsid = "$Id: simple-cache.c,v 0.18 1991/11/10 19:02:11 linus Exp $";
 
 
 
@@ -844,7 +844,7 @@ cached_create_text( String message)
 }
 
 
-Text_no
+EXPORT Text_no
 traverse_text(Text_no seed)
 {
     Cache_node *node;
@@ -2063,3 +2063,8 @@ dump_cache_stats(FILE *fp)
 }
 
     
+EXPORT int
+query_next_text_num(void)
+{
+    return next_text_num;
+}
diff --git a/src/server/text.c b/src/server/text.c
index 22d51683f33b71a940a595ba7cbdfd49cda86a67..8363e7d266fe430e1e55cdeca77f0eb16c2df265 100644
--- a/src/server/text.c
+++ b/src/server/text.c
@@ -1,5 +1,5 @@
 /*
- * $Id: text.c,v 0.8 1991/10/21 22:29:33 ceder Exp $
+ * $Id: text.c,v 0.9 1991/11/10 19:02:05 linus Exp $
  * Copyright (C) 1991  Lysator Academic Computer Association.
  *
  * This file is part of the LysKOM server.
@@ -28,7 +28,7 @@
  * All atomic calls that deals with texts.
  */
 
-static char *rcsid = "$Id: text.c,v 0.8 1991/10/21 22:29:33 ceder Exp $";
+static char *rcsid = "$Id: text.c,v 0.9 1991/11/10 19:02:05 linus Exp $";
 
 #include <time.h>
 #include <stdlib.h>
@@ -1728,6 +1728,53 @@ delete_text( Text_no text_no )
     return do_delete_text(text_no, text_s);
 }
 
+/*
+ * Lookup a text according to creation-time.
+ * The text-no of the text created closest before TIME is returned.
+ * The text text-no must not be readable
+ */
+extern Text_no
+get_last_text(time_t time, Text_no *text)
+{
+    Text_no lower = 0;
+    Text_no higher = query_next_text_num();
+
+    while (!(lower + 1 == higher))
+    {
+	Text_stat * text;
+	Text_no try = (lower + higher) / 2;	/* Binary search */
+	int step = 0;		/* Patch to accept nonexisting texts */
+
+        do
+	{
+	    try += step;	/* back and forth around the middle as long */
+				/* until we find an existing text. */
+	    step = (step + ( step > 0 ? 1 : -1)) * (-1);
+	    text = cached_get_text_stat( try );
+	} while (text == NULL && try > lower && try < higher);
+
+	if (try <= lower || try >= higher)
+	    break;		/* We did not find any existing text */
+	
+	if (time > text->creation_time)
+	    lower = try;
+	else			/* The intervall is "halved" */
+	    higher = try;
+    }
+
+    if (lower != 0)
+    {
+	*text = lower;
+	return OK;		/* We found a text */
+    }
+    else
+    {
+	kom_errno = KOM_NO_SUCH_TEXT; /* We did not find a text at all */
+	return FAILURE;
+    }
+}
+
+
 /*
  * Add a recipient to a text.
  */