Skip to content

Commit 3f980d8

Browse files
authored
Update ESP32-CAM_Gmail.ino
1 parent 0226bd5 commit 3f980d8

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

ESP32-CAM_Gmail/ESP32-CAM_Gmail.ino

+15-32
Original file line numberDiff line numberDiff line change
@@ -235,37 +235,20 @@ String SendCapturedImage(String myRecipient, String mySubject) {
235235
return getBody;
236236
}
237237

238-
//https://github.com/zenmanenergy/ESP8266-Arduino-Examples/
239-
String urlencode(String str)
240-
{
241-
String encodedString="";
242-
char c;
243-
char code0;
244-
char code1;
245-
char code2;
246-
for (int i =0; i < str.length(); i++){
247-
c=str.charAt(i);
248-
if (c == ' '){
249-
encodedString+= '+';
250-
} else if (isalnum(c)){
251-
encodedString+=c;
252-
} else{
253-
code1=(c & 0xf)+'0';
254-
if ((c & 0xf) >9){
255-
code1=(c & 0xf) - 10 + 'A';
256-
}
257-
c=(c>>4)&0xf;
258-
code0=c+'0';
259-
if (c > 9){
260-
code0=c - 10 + 'A';
261-
}
262-
code2='\0';
263-
encodedString+='%';
264-
encodedString+=code0;
265-
encodedString+=code1;
266-
//encodedString+=code2;
267-
}
268-
yield();
238+
//https://www.arduino.cc/reference/en/libraries/urlencode/
239+
String urlencode(String str) {
240+
const char *msg = str.c_str();
241+
const char *hex = "0123456789ABCDEF";
242+
String encodedMsg = "";
243+
while (*msg != '\0') {
244+
if (('a' <= *msg && *msg <= 'z') || ('A' <= *msg && *msg <= 'Z') || ('0' <= *msg && *msg <= '9') || *msg == '-' || *msg == '_' || *msg == '.' || *msg == '~') {
245+
encodedMsg += *msg;
246+
} else {
247+
encodedMsg += '%';
248+
encodedMsg += hex[(unsigned char)*msg >> 4];
249+
encodedMsg += hex[*msg & 0xf];
269250
}
270-
return encodedString;
251+
msg++;
252+
}
253+
return encodedMsg;
271254
}

0 commit comments

Comments
 (0)