Cleanups.

This commit is contained in:
Relintai 2023-09-18 12:14:24 +02:00
parent f12dc3ec22
commit b614c32d3c
3 changed files with 39 additions and 31 deletions

View File

@ -1,3 +1,13 @@
[gd_scene format=2] [gd_scene load_steps=2 format=2]
[ext_resource path="res://SMTP-NodeCode.gd" type="Script" id=1]
[node name="Main" type="Node"] [node name="Main" type="Node"]
script = ExtResource( 1 )
[node name="Button" type="Button" parent="."]
margin_right = 12.0
margin_bottom = 20.0
text = "Send"
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]

View File

@ -1,25 +1,16 @@
extends Node extends Node
## This looks like it was created by a CS student at a university graduation level, export var server = "smtp.gmail.com"
## there are many fantastic code snippets here, please try and mine as much of it as you can, as I have. export var port = 465
export var user = ""
# the debug function is quite smart. export var password = ""
var debug = true export var mymailto = ""
func display(data): export var mymail = "mail.smtp.localhost"
if debug == true:
print("debug: ",data)
export var server = "smtp.gmail.com" # you'll find info on the Gmail SMTP server at www.google.com :)
export var port = 465 # standard SSL port
export var user = "" # put userid for SMTP login
export var password = "" # put password for SMTP login
export var mymailto = "" # put destination address
export var mymail = "mail.smtp.localhost" # I found this at some random stackexchange thread
enum channel {TCP,PACKET} enum channel {TCP,PACKET}
export (channel) var com = channel.TCP export (channel) var com = channel.TCP
var Bocket = null
var Socket = null var Socket = null
var PacketSocket = null var PacketSocket = null
var PacketIn = "" var PacketIn = ""
@ -37,13 +28,14 @@ var thread = null
var authloginbase64="" var authloginbase64=""
var authpassbase64="" var authpassbase64=""
func _ready(): func _ready():
if user != "": authloginbase64=Marshalls.raw_to_base64(user.to_ascii()) if user != "":
if password != "": authpassbase64=Marshalls.raw_to_base64(password.to_ascii()) authloginbase64=Marshalls.raw_to_base64(user.to_ascii())
if password != "":
authpassbase64=Marshalls.raw_to_base64(password.to_ascii())
# This is unbelievably useful. Try using ThreadDeliver without a thread for comparison
func Deliver(data): func Deliver(data):
thread = Thread.new() thread = Thread.new()
thread.start(self,"ThreadDeliver",data) thread.start(self,"ThreadDeliver",data)
@ -63,6 +55,8 @@ func ThreadDeliver(data):
r_code = MAILhello() r_code = MAILhello()
if r_code == OK: if r_code == OK:
print("SMTP_working") print("SMTP_working")
CloseSocket()
return
r_code = MAILauth() r_code = MAILauth()
if r_code == OK: if r_code == OK:
r_code = MAILfrom(mymail) r_code = MAILfrom(mymail)
@ -79,16 +73,9 @@ func ThreadDeliver(data):
display("All done") display("All done")
else: else:
display("ERROR") display("ERROR " + str(r_code))
return r_code return r_code
var Bocket = null
# I added the variable Bocket, as a wrap around the Socket (originally called socket anyway),
# it's an SSL wrapper for Streampeers, I don't know much about these things,
# but you learn a lot by messing around with things.
# I like creating silly names for variables, it keeps me motivated,
# reminds me that creating code is my choice, to do how I please.
func OpenSocket(): func OpenSocket():
var error var error
@ -107,7 +94,7 @@ func OpenSocket():
display(["trying IP ...",ip,error]) display(["trying IP ...",ip,error])
for i in range(1,MaxRetries): for i in range(1,MaxRetries):
print(Socket.get_status()) print("asdasd" + str(Socket.get_status()))
# if Socket.get_status() == Socket.STATUS_ERROR: # if Socket.get_status() == Socket.STATUS_ERROR:
# d.display("Error while requesting connection") # d.display("Error while requesting connection")
@ -118,6 +105,7 @@ func OpenSocket():
if Socket.get_status() == Socket.STATUS_CONNECTED: if Socket.get_status() == Socket.STATUS_CONNECTED:
display("connection up") display("connection up")
print("CONNECTED")
break break
OS.delay_msec(delayTime) OS.delay_msec(delayTime)
@ -244,3 +232,12 @@ func MAILquit():
func bracket(data): func bracket(data):
return "<"+data+">" return "<"+data+">"
func _on_Button_pressed() -> void:
Deliver("TEST MSG!")
var debug = true
func display(data):
if debug == true:
print("debug: ",data)

View File

@ -11,6 +11,7 @@ config_version=4
[application] [application]
config/name="SMTP Node" config/name="SMTP Node"
run/main_scene="res://Main.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[physics] [physics]