[Oberon] Revision of OpenSMTP(...) in Oberon.Mail.Mod.

peter at easthope.ca peter at easthope.ca
Sat Apr 29 19:54:23 CEST 2023


Hi,

In A2, Oberon.Mail.Mod has OpenSMTP(...).
https://gitlab.inf.ethz.ch/felixf/oberon/-/blob/main/source/Oberon.Mail.Mod

The module is also in the wikibook.
https://en.wikibooks.org/wiki/Oberon/A2/Oberon.Mail.Mod

OpenSMTP was inherited from ETH Oberon.  Written when SMTP without
authentication was routine.

I'm revising the procedure with two objectives.
(1) Remove an unfavourable RETURN.
(2) Add capability for AUTH PLAIN.

	(* SMTP should connect inside a TLS tunnel connected to smarthost port 
465. *)
	PROCEDURE OpenSMTP1*(VAR S: SMTPSession; host, user, passwd, from: 
ARRAY OF CHAR; port: SIGNED16);
	BEGIN
		IF trace THEN
			Texts.WriteString(W, "--- SMTP"); Texts.WriteLn(W);
			Texts.Append(Oberon.Log, W.buf)
		END;
		IF (port <= 0) OR (port >= 10000) THEN
			port := AltSMTPPort
		END;
		NEW(S);
		S.res := NetTools.Failed; S.C := NIL; S.S := NIL;
		IF (host[0] = "<") OR (host[0] = 0X) THEN
			S.reply := "no smtp-host specified"
		ELSE (* smtp-host name available *)
			IF ~NetTools.Connect(S.C, port, host, TRUE) THEN
				S.reply := "no connection"
			ELSE
				S.S := NetTools.OpenStream(S.C);
				ReadResponse(S);
				IF S.reply[0] # "2" THEN (* Server declined communication *)
					CloseSMTP(S)
				ELSE (* Positive response from server *)
					IF (user[0] = 0X) OR (passwd[0] = 0X) THEN (* Authentication 
impossible *)
						SendCmd(S, "HELO", NetSystem.hostName);
						ReadResponse(S);
						IF S.reply[0] = "2" THEN (* Server cooperating *)
							COPY(from, S.from); S.res := NetTools.Done
						END
					ELSE (* user and passwd available; try to authenticate *)
						SendCmd(S, "EHLO", NetSystem.hostName);
						ReadResponse(S);
						IF S.reply[0] = "2" THEN (* Server cooperating *)
							SendCmd(S, "AUTH", "PLAIN <Base64 encoded user & password>");
							IF S.reply[0] = "2" THEN (* Authentication accepted *)
								COPY(from, S.from); S.res := NetTools.Done
							END
						END
					END
				END
			END
		END
	END OpenSMTP1;

Comments?  Suggestions?

Thx,            ... P.L.


More information about the Oberon mailing list