<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Vorformatiert Zchn";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
span.HTMLVorformatiertZchn
{mso-style-name:"HTML Vorformatiert Zchn";
mso-style-priority:99;
mso-style-link:"HTML Vorformatiert";
font-family:"Courier New";}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="DE-CH" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">Peter<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">You said “ReadText is external to this byte padding.” Is it?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">RFC 1939 states:<o:p></o:p></span></p>
<pre><span lang="EN-US"> Responses to certain commands are multi-line. In these cases, which<o:p></o:p></span></pre>
<pre><span lang="EN-US"> are clearly indicated below, after sending the first line of the<o:p></o:p></span></pre>
<pre><span lang="EN-US"> response and a CRLF, any additional lines are sent, each terminated<o:p></o:p></span></pre>
<pre><span lang="EN-US"> by a CRLF pair. When all lines of the response have been sent, a<o:p></o:p></span></pre>
<pre><span lang="EN-US"> final line is sent, consisting of a termination octet (decimal code<o:p></o:p></span></pre>
<pre><span lang="EN-US"> 046, ".") and a CRLF pair. If any line of the multi-line response<o:p></o:p></span></pre>
<pre><span lang="EN-US"> begins with the termination octet, the line is "byte-stuffed" by<o:p></o:p></span></pre>
<pre><span lang="EN-US"> pre-pending the termination octet to that line of the response.<o:p></o:p></span></pre>
<pre><span lang="EN-US"> Hence a multi-line response is terminated with the five octets<o:p></o:p></span></pre>
<pre><span lang="EN-US"> "CRLF.CRLF". When examining a multi-line response, the client checks<o:p></o:p></span></pre>
<pre><span lang="EN-US"> to see if the line begins with the termination octet. If so and if<o:p></o:p></span></pre>
<pre><span lang="EN-US"> octets other than CRLF follow, the first octet of the line (the<o:p></o:p></span></pre>
<pre><span lang="EN-US"> termination octet) is stripped away. If so and if CRLF immediately<o:p></o:p></span></pre>
<pre><span lang="EN-US"> follows the termination character, then the response from the POP<o:p></o:p></span></pre>
<pre><span lang="EN-US"> server is ended and the line containing ".CRLF" is not considered<o:p></o:p></span></pre>
<pre><span lang="EN-US"> part of the multi-line response.<o:p></o:p></span></pre>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">As the last line with only “.CRLF” is not considered part of the text, you should delay
</span><span lang="EN-US" style="font-size:11.0pt">Files.Write(R, ch); </span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">in state 3, 4, 5 until you know whether
</span><span lang="EN-US" style="font-size:11.0pt">it’s the termination case or byte-stuffed case.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">BTW: the original code does not copy the starting “.” of a line to the file, but copies over the final CRLF. In most cases, this additional CRLF at the end does not harm but is - strictly speaking
- not correct. <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">br<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Jörg<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">Von:
</span></b><span style="font-size:12.0pt;color:black">joerg.straube@iaeth.ch <joerg.straube@iaeth.ch><br>
<b>Datum: </b>Montag, 13. </span><span lang="EN-US" style="font-size:12.0pt;color:black">November 2023 um 06:08<br>
<b>An: </b>ETH Oberon and related systems <oberon@lists.inf.ethz.ch><br>
<b>Betreff: </b>AW: [Oberon] Removing unnecessary and embedded RETURNs.<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Peter</span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> </span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">The idea with the state machine is good.</span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">One remark:</span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">I don’t understand you remark “ReadText is external to this byte padding”</span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">In my point of view in the ELSE part of state 3 you would have to strip the stuffed period.</span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">In other words: you would have to reposition and copy the Files.Write(R, ch); to almost all your cases</span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> </span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US">br</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US">Jörg</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">Von:
</span></b><span style="font-size:12.0pt;color:black">Oberon <oberon-bounces@lists.inf.ethz.ch> im Auftrag von peter@easthope.ca <peter@easthope.ca><br>
<b>Datum: </b>Sonntag, 12. </span><span lang="EN-US" style="font-size:12.0pt;color:black">November 2023 um 15:58<br>
<b>An: </b>oberon@lists.inf.ethz.ch <oberon@lists.inf.ethz.ch><br>
<b>Betreff: </b>Re: [Oberon] Removing unnecessary and embedded RETURNs.</span><span lang="EN-US"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">This is my alternative Mail.ReadText with no RETURN. ReportError was
<br>
helpful in debugging; probably can be deleted now.<br>
<br>
Apology for the verbose comments. Added to help a non-expert <br>
understand the non-obvious activity. =8~)<br>
<br>
I wonder whether this use of CASE is good practise. Observations? <br>
<br>
Thanks, ... P.L.<br>
<br>
PROCEDURE ReportError(c: CHAR);<br>
BEGIN<br>
Texts.WriteString(W, "Mail.ReadText(): LF absent at CASE "); Texts.Write(W, c);<br>
Texts.Write(W, "."); Texts.WriteLn(W);<br>
Texts.Append(Oberon.Log, W.buf); HALT(6)<br>
END ReportError;<br>
<br>
(* According to Post Office Protocol, the end of a message body is<br>
marked by character sequence CR LF "." CR LF.<br>
A message line can begin with a period. To distinguish from end-of-message,
<br>
the message sender prepends an additional period which is removed before the
<br>
message is displayed to the recipient. ReadText is external to this byte padding.<br>
</span><a href="https://en.wikipedia.org/wiki/Post_Office_Protocol"><span lang="EN-US" style="font-size:11.0pt">https://en.wikipedia.org/wiki/Post_Office_Protocol</span></a><span lang="EN-US" style="font-size:11.0pt"><br>
</span><a href="https://tools.ietf.org/html/rfc1939#section-3"><span lang="EN-US" style="font-size:11.0pt">https://tools.ietf.org/html/rfc1939#section-3</span></a><span lang="EN-US" style="font-size:11.0pt"> *)<br>
PROCEDURE ReadText(S: NetTools.Session; VAR R: Files.Rider);<br>
VAR<br>
buffer: ARRAY BufLen OF CHAR;<br>
len, readLen, i: SIGNED32;<br>
ch: CHAR;<br>
progress: CHAR; (*<br>
"0"= continuing<br>
"1"= CR<br>
"2"= CR LF<br>
"3"= CR LF "."<br>
"4"= CR LF "." CR<br>
"5"= CR LF "." CR LF = end-of-message; or no more characters *)<br>
BEGIN<br>
readLen := 0;<br>
i := readLen;<br>
progress := "0";<br>
WHILE progress < "5" DO (* Write byte to the MailMessages file. *)<br>
IF i = readLen THEN (* More characters required. *)<br>
len := NetSystem.Available(S.C);<br>
IF (len = 0) & (NetSystem.State(S.C) # NetSystem.inout) THEN<br>
progress := "5"<br>
ELSE<br>
IF len > (BufLen-2) THEN readLen := BufLen-2 ELSE readLen := len END;<br>
NetSystem.ReadBytes(S.C, 0, readLen, buffer);<br>
DEC(len, readLen);<br>
i := 0<br>
END<br>
ELSE (* i < readLen. character available *)<br>
ch := buffer[i];<br>
CASE progress OF<br>
"0": IF ch = Strings.CR THEN progress := "1" END |<br>
"1": IF ch = Strings.LF THEN progress := "2" ELSE ReportError(progress) END |<br>
"2": IF ch = Strings.CR THEN progress := "1"<br>
ELSIF ch = "." THEN progress := "3" ELSE progress := "0" END |<br>
"3": IF ch = Strings.CR THEN progress := "4" ELSE progress := "0" END |<br>
"4": IF ch = Strings.LF THEN progress := "5" ELSE ReportError(progress) END<br>
END;<br>
Files.Write(R, ch);<br>
INC(i)<br>
END<br>
END<br>
END ReadText;<br>
<br>
- <br>
VoIP: +1 604 670 0140<br>
work: </span><a href="https://en.wikibooks.org/wiki/User:PeterEasthope"><span lang="EN-US" style="font-size:11.0pt">https://en.wikibooks.org/wiki/User:PeterEasthope</span></a><span lang="EN-US" style="font-size:11.0pt"><br>
<br>
--<br>
Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems<br>
</span><a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon"><span lang="EN-US" style="font-size:11.0pt">https://lists.inf.ethz.ch/mailman/listinfo/oberon</span></a><span lang="EN-US"><o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>