Skip to content

Commit e6527be

Browse files
committed
FIX: writing data to smtp scheme must use chunks not higher than 16KiB (TLS limitation)
1 parent d044c26 commit e6527be

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/mezz/prot-smtp.reb

+4-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ where's my kibble?}]
6969

7070
system/options/log/smtp: 2
7171

72-
bufsize: 32000 ;-- use a write buffer of 32k for sending large attachments
72+
bufsize: 16384 ;-- use a write buffer of 16KiB (maximum TLS record size!) for sending large attachments
7373

7474
mail-obj: make object! [
7575
from:
@@ -320,7 +320,7 @@ sync-smtp-handler: function [event][
320320
switch/default state [
321321
SENDING [
322322
either not empty? ptr: smtp-ctx/mail/message [
323-
sys/log/debug 'SMTP ["Sending " min bufsize length? ptr " bytes of " length? ptr ]
323+
sys/log/more 'SMTP ["Sending" min bufsize length? ptr "bytes of" length? ptr ]
324324
write client to binary! take/part ptr bufsize
325325
][
326326
sys/log/debug 'SMTP "Sending ends."
@@ -478,6 +478,8 @@ sys/make-scheme [
478478
close port
479479
wait [port 0.1]
480480
do error
481+
port/state: 'ERROR
482+
true
481483
]
482484
close [
483485
port/state: 'CLOSE

src/mezz/prot-tls.reb

+19-5
Original file line numberDiff line numberDiff line change
@@ -2145,10 +2145,23 @@ TLS-client-awake: function [event [event!]][
21452145
return true
21462146
]
21472147
error [
2148-
if all [ctx ctx/state = 'lookup][
2149-
ctx/error: make error! [
2150-
code: 500 type: 'access id: 'cannot-open
2151-
arg1: TCP-port/spec/ref
2148+
unless ctx/error [
2149+
ctx/error: case [
2150+
ctx/state = 'lookup [
2151+
make error! [
2152+
code: 500 type: 'access id: 'cannot-open
2153+
arg1: TCP-port/spec/ref
2154+
]
2155+
]
2156+
'else [
2157+
;@@ needs better error (unknown reason)
2158+
; So far this error is used, when we try to write
2159+
; application data larger than 16KiB!
2160+
make error! [
2161+
code: 500 type: 'access id: 'protocol
2162+
arg1: TCP-port/spec/ref
2163+
]
2164+
]
21522165
]
21532166
]
21542167
send-event 'error TLS-port
@@ -2284,7 +2297,8 @@ do-TLS-write: func[port [port!] value [any-type!] /local ctx][
22842297
log-debug "WRITE"
22852298
ctx: port/extra
22862299
if ctx/protocol = 'APPLICATION [
2287-
2300+
;@@ FIXME: size limit for application data is 16KiB,
2301+
;@@ else server closes connection, which is not detected!
22882302
binary/init ctx/out none ;resets the output buffer
22892303
application-data ctx :value
22902304

0 commit comments

Comments
 (0)