MCPcopy Create free account
hub / github.com/SmingHub/Sming / onReadyToSendData

Method onReadyToSendData

Sming/Components/Network/src/Network/SmtpClient.cpp:134–272  ·  view source on GitHub ↗

Protected Methods

Source from the content-addressed store, hash-verified

132
133// Protected Methods
134void SmtpClient::onReadyToSendData(TcpConnectionEvent sourceEvent)
135{
136 switch(state) {
137 case eSMTP_StartTLS: {
138 sendString(F("STARTTLS\n\n"));
139 state = eSMTP_Banner;
140 break;
141 }
142
143 case eSMTP_SendAuth: {
144 auto authPlain = [this]() {
145 // base64('\0' + username + '\0' + password)
146 String token = '\0' + url.User + '\0' + url.Password;
147 String hash = base64_encode(token);
148 sendString(F("AUTH PLAIN ") + hash + "\r\n");
149 state = eSMTP_SendingAuth;
150 };
151
152 auto authCramMd5 = [this]() {
153 // Slower cram-md5 authentication
154 sendString(F("AUTH CRAM-MD5\r\n"));
155 state = eSMTP_RequestingAuthChallenge;
156 };
157
158 DEFINE_FSTR_LOCAL(methodPlain, "PLAIN")
159 DEFINE_FSTR_LOCAL(methodCramMd5, "CRAM-MD5")
160 if(useSsl) {
161 if(authMethods.contains(methodPlain)) {
162 authPlain();
163 } else if(authMethods.contains(methodCramMd5)) {
164 authCramMd5();
165 }
166 } else if(authMethods.contains(methodCramMd5)) {
167 authCramMd5();
168 } else if(authMethods.contains(methodPlain)) {
169 authPlain();
170 }
171
172 if(state == eSMTP_SendAuth) {
173 state = eSMTP_Ready;
174 }
175
176 break;
177 }
178
179 case eSMTP_SendAuthResponse: {
180 // Calculate the CRAM-MD5 response
181 // base64.b64encode("user " +hmac.new(password, base64.b64decode(challenge), hashlib.md5).hexdigest())
182
183 auto digest = Crypto::HmacMd5(url.Password).calculate(authChallenge);
184 String token = url.User + ' ' + Crypto::toString(digest);
185 sendString(base64_encode(token) + "\r\n");
186 state = eSMTP_SendingAuth;
187
188 break;
189 }
190
191 case eSMTP_Ready: {

Callers

nothing calls this directly

Calls 7

toStringFunction · 0.70
FFunction · 0.50
base64_encodeFunction · 0.50
containsMethod · 0.45
calculateMethod · 0.45
countMethod · 0.45
dequeueMethod · 0.45

Tested by

no test coverage detected