From b66bb4e5a4829e544917b29a5bdfa7af87dafa80 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Sat, 24 Aug 2024 18:12:28 -0300 Subject: [PATCH 01/18] Initial test to change port 25 to 587 --- commands.c | 5 +++++ debug.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/commands.c b/commands.c index bcb9767..f4e18de 100644 --- a/commands.c +++ b/commands.c @@ -922,6 +922,11 @@ static struct mobile_packet *command_tcp_connect_connecting(struct mobile_adapte }; memcpy(addr.host, packet->data, 4); + if (addr.port == 25){ + // printf("Port 25 detected. Replacing to 587\n"); + addr.port=587; + } + int rc = mobile_cb_sock_connect(adapter, conn, (struct mobile_addr *)&addr); if (rc == 0) return NULL; diff --git a/debug.c b/debug.c index a610b28..9dc617b 100644 --- a/debug.c +++ b/debug.c @@ -324,7 +324,7 @@ void mobile_debug_command(struct mobile_adapter *adapter, const struct mobile_pa debug_print(": %u.%u.%u.%u:%u", packet->data[0], packet->data[1], packet->data[2], packet->data[3], - packet->data[4] << 8 | packet->data[5]); + ((packet->data[4] << 8 | packet->data[5]) == 25) ? 587 : (packet->data[4] << 8 | packet->data[5])); packet_end(adapter, packet, 6); } else { if (packet->length < 1) break; From e4dcd4ce3fa77067d31421b8d939ac93c9b0543c Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Sat, 24 Aug 2024 20:58:52 -0300 Subject: [PATCH 02/18] Update debug.c --- debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug.c b/debug.c index 9dc617b..a610b28 100644 --- a/debug.c +++ b/debug.c @@ -324,7 +324,7 @@ void mobile_debug_command(struct mobile_adapter *adapter, const struct mobile_pa debug_print(": %u.%u.%u.%u:%u", packet->data[0], packet->data[1], packet->data[2], packet->data[3], - ((packet->data[4] << 8 | packet->data[5]) == 25) ? 587 : (packet->data[4] << 8 | packet->data[5])); + packet->data[4] << 8 | packet->data[5]); packet_end(adapter, packet, 6); } else { if (packet->length < 1) break; From abee92acecd3b8ae12b6d38c8742a5b7ab83fe5f Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Sat, 24 Aug 2024 21:11:01 -0300 Subject: [PATCH 03/18] Update commands.c --- commands.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commands.c b/commands.c index f4e18de..fc1381e 100644 --- a/commands.c +++ b/commands.c @@ -736,6 +736,8 @@ static struct mobile_packet *command_change_clock(struct mobile_adapter *adapter // Replying with a different command in the header tricks the official GBA // library into never changing its serial mode. Using the REINIT command // forces it to set its serial mode to 8-bit. + mobile_debug_print(adapter,PSTR(" Forcing adapter to keep using 8-bit mode!")); + mobile_debug_endl(adapter); packet->command = MOBILE_COMMAND_REINIT; s->mode_32bit = false; #endif @@ -923,7 +925,8 @@ static struct mobile_packet *command_tcp_connect_connecting(struct mobile_adapte memcpy(addr.host, packet->data, 4); if (addr.port == 25){ - // printf("Port 25 detected. Replacing to 587\n"); + mobile_debug_print(adapter,PSTR(" Replacing port 25 to 587!")); + mobile_debug_endl(adapter); addr.port=587; } From 7f3f9e6ab38cb692466859c3341336d8f57df973 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Sun, 25 Aug 2024 15:34:27 -0300 Subject: [PATCH 04/18] Update commands.c --- commands.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/commands.c b/commands.c index fc1381e..3ffdc55 100644 --- a/commands.c +++ b/commands.c @@ -906,6 +906,11 @@ static struct mobile_packet *command_tcp_connect_begin(struct mobile_adapter *ad } s->connections[conn] = true; + if ((packet->data[4] << 8 | packet->data[5]) == 25){ + mobile_debug_print(adapter,PSTR(" Replacing port 25 to 587!")); + mobile_debug_endl(adapter); + } + b->processing_data[PROCDATA_TCP_CONNECT_CONN] = conn; b->processing = PROCESS_TCP_CONNECT_CONNECTING; return NULL; @@ -920,16 +925,10 @@ static struct mobile_packet *command_tcp_connect_connecting(struct mobile_adapte struct mobile_addr4 addr = { .type = MOBILE_ADDRTYPE_IPV4, - .port = packet->data[4] << 8 | packet->data[5], + .port = ((packet->data[4] << 8 | packet->data[5]) == 25 ? 587 : (packet->data[4] << 8 | packet->data[5])), }; memcpy(addr.host, packet->data, 4); - if (addr.port == 25){ - mobile_debug_print(adapter,PSTR(" Replacing port 25 to 587!")); - mobile_debug_endl(adapter); - addr.port=587; - } - int rc = mobile_cb_sock_connect(adapter, conn, (struct mobile_addr *)&addr); if (rc == 0) return NULL; From 1fbafafedb5ee08474876a9610881292db76affc Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Sun, 25 Aug 2024 21:27:14 -0300 Subject: [PATCH 05/18] Update commands.c --- commands.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commands.c b/commands.c index 3ffdc55..248a9dc 100644 --- a/commands.c +++ b/commands.c @@ -925,8 +925,10 @@ static struct mobile_packet *command_tcp_connect_connecting(struct mobile_adapte struct mobile_addr4 addr = { .type = MOBILE_ADDRTYPE_IPV4, - .port = ((packet->data[4] << 8 | packet->data[5]) == 25 ? 587 : (packet->data[4] << 8 | packet->data[5])), + .port = packet->data[4] << 8 | packet->data[5], }; + if (addr.port == 25) addr.port = 587; + memcpy(addr.host, packet->data, 4); int rc = mobile_cb_sock_connect(adapter, conn, From 5284afc2cfe2fcd12b81ff5ad81ae6bd92bc1cc9 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Sun, 25 Aug 2024 21:28:12 -0300 Subject: [PATCH 06/18] Update commands.c --- commands.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands.c b/commands.c index 248a9dc..a06ab24 100644 --- a/commands.c +++ b/commands.c @@ -736,7 +736,7 @@ static struct mobile_packet *command_change_clock(struct mobile_adapter *adapter // Replying with a different command in the header tricks the official GBA // library into never changing its serial mode. Using the REINIT command // forces it to set its serial mode to 8-bit. - mobile_debug_print(adapter,PSTR(" Forcing adapter to keep using 8-bit mode!")); + mobile_debug_print(adapter, PSTR(" Forcing adapter to keep using 8-bit mode!")); mobile_debug_endl(adapter); packet->command = MOBILE_COMMAND_REINIT; s->mode_32bit = false; @@ -907,7 +907,7 @@ static struct mobile_packet *command_tcp_connect_begin(struct mobile_adapter *ad s->connections[conn] = true; if ((packet->data[4] << 8 | packet->data[5]) == 25){ - mobile_debug_print(adapter,PSTR(" Replacing port 25 to 587!")); + mobile_debug_print(adapter, PSTR(" Replacing port 25 to 587!")); mobile_debug_endl(adapter); } From 6ea19a8de92116c18144679293b5e9f59604c1a5 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Sun, 25 Aug 2024 21:28:50 -0300 Subject: [PATCH 07/18] Update commands.c --- commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands.c b/commands.c index a06ab24..f948144 100644 --- a/commands.c +++ b/commands.c @@ -906,7 +906,7 @@ static struct mobile_packet *command_tcp_connect_begin(struct mobile_adapter *ad } s->connections[conn] = true; - if ((packet->data[4] << 8 | packet->data[5]) == 25){ + if ((packet->data[4] << 8 | packet->data[5]) == 25) { mobile_debug_print(adapter, PSTR(" Replacing port 25 to 587!")); mobile_debug_endl(adapter); } From 85bd014f5bc5d88f43199a3a392cf007af58f134 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Sat, 31 May 2025 23:41:18 -0300 Subject: [PATCH 08/18] First Attemp to trigger custom mail port --- commands.c | 19 +++++++++++++------ config.c | 5 +++++ mobile.h | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/commands.c b/commands.c index f948144..9586026 100644 --- a/commands.c +++ b/commands.c @@ -736,8 +736,10 @@ static struct mobile_packet *command_change_clock(struct mobile_adapter *adapter // Replying with a different command in the header tricks the official GBA // library into never changing its serial mode. Using the REINIT command // forces it to set its serial mode to 8-bit. - mobile_debug_print(adapter, PSTR(" Forcing adapter to keep using 8-bit mode!")); - mobile_debug_endl(adapter); + if (adapter->config.mail_port) { + mobile_debug_print(adapter, PSTR(" Forcing adapter to keep using 8-bit mode!")); + mobile_debug_endl(adapter); + } packet->command = MOBILE_COMMAND_REINIT; s->mode_32bit = false; #endif @@ -906,9 +908,11 @@ static struct mobile_packet *command_tcp_connect_begin(struct mobile_adapter *ad } s->connections[conn] = true; - if ((packet->data[4] << 8 | packet->data[5]) == 25) { - mobile_debug_print(adapter, PSTR(" Replacing port 25 to 587!")); - mobile_debug_endl(adapter); + if (adapter->config.mail_port) { + if ((packet->data[4] << 8 | packet->data[5]) == 25) { + mobile_debug_print(adapter, PSTR(" Replacing port 25 to 587!")); + mobile_debug_endl(adapter); + } } b->processing_data[PROCDATA_TCP_CONNECT_CONN] = conn; @@ -927,8 +931,11 @@ static struct mobile_packet *command_tcp_connect_connecting(struct mobile_adapte .type = MOBILE_ADDRTYPE_IPV4, .port = packet->data[4] << 8 | packet->data[5], }; - if (addr.port == 25) addr.port = 587; + if (adapter->config.mail_port) { + if (addr.port == 25) addr.port = 587; + } + memcpy(addr.host, packet->data, 4); int rc = mobile_cb_sock_connect(adapter, conn, diff --git a/config.c b/config.c index 73249ec..6f7ebbc 100644 --- a/config.c +++ b/config.c @@ -307,3 +307,8 @@ bool mobile_config_get_relay_token(struct mobile_adapter *adapter, unsigned char memcpy(token, adapter->config.relay_token, MOBILE_RELAY_TOKEN_SIZE); return true; } + +void mobile_config_alt_mail(struct mobile_adapter *adapter, bool alt_mail) +{ + adapter->config.mail_port = alt_mail; +} \ No newline at end of file diff --git a/mobile.h b/mobile.h index 43028ab..b84c223 100644 --- a/mobile.h +++ b/mobile.h @@ -426,6 +426,7 @@ void mobile_config_set_relay(struct mobile_adapter *adapter, const struct mobile void mobile_config_get_relay(struct mobile_adapter *adapter, struct mobile_addr *relay); void mobile_config_set_relay_token(struct mobile_adapter *adapter, const unsigned char *token); bool mobile_config_get_relay_token(struct mobile_adapter *adapter, unsigned char *token); +void mobile_config_alt_mail(struct mobile_adapter *adapter, bool alt_mail); // mobile_config_load - Manually force a load of the configuration values // From e809116ee95a777fffd4fffa34222700bed2476e Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Sun, 1 Jun 2025 09:20:59 -0300 Subject: [PATCH 09/18] Add mail_port bool on mobile_adapter_config --- config.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config.h b/config.h index 2a0bd8e..851b312 100644 --- a/config.h +++ b/config.h @@ -34,6 +34,9 @@ struct mobile_adapter_config { // for p2p communication, instead of direct TCP connections struct mobile_addr relay; + // Makes the adapter use port 587 instead 25 for SMTP connections. + bool mail_port: 1; + // Authentication token used for relay connections unsigned char relay_token[MOBILE_RELAY_TOKEN_SIZE]; }; From 2efb6d24141affcbb8a5eec3c683c6a7d70bd8f1 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Fri, 6 Jun 2025 15:42:38 -0300 Subject: [PATCH 10/18] Fix NO32BIT message --- commands.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/commands.c b/commands.c index 9586026..66f4e20 100644 --- a/commands.c +++ b/commands.c @@ -736,10 +736,8 @@ static struct mobile_packet *command_change_clock(struct mobile_adapter *adapter // Replying with a different command in the header tricks the official GBA // library into never changing its serial mode. Using the REINIT command // forces it to set its serial mode to 8-bit. - if (adapter->config.mail_port) { - mobile_debug_print(adapter, PSTR(" Forcing adapter to keep using 8-bit mode!")); - mobile_debug_endl(adapter); - } + mobile_debug_print(adapter, PSTR(" Forcing adapter to keep using 8-bit mode!")); + mobile_debug_endl(adapter); packet->command = MOBILE_COMMAND_REINIT; s->mode_32bit = false; #endif From ab02e2ff52a19673600d023a81f1d2e4166e1908 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Fri, 13 Jun 2025 10:46:27 -0300 Subject: [PATCH 11/18] Added a fallback for SMTP connections --- commands.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/commands.c b/commands.c index 66f4e20..f21a5fb 100644 --- a/commands.c +++ b/commands.c @@ -884,7 +884,8 @@ enum process_tcp_connect { }; enum procdata_tcp_connect { - PROCDATA_TCP_CONNECT_CONN + PROCDATA_TCP_CONNECT_CONN, + PROCDATA_TCP_CONNECT_FALLBACK }; static struct mobile_packet *command_tcp_connect_begin(struct mobile_adapter *adapter, struct mobile_packet *packet) @@ -914,6 +915,7 @@ static struct mobile_packet *command_tcp_connect_begin(struct mobile_adapter *ad } b->processing_data[PROCDATA_TCP_CONNECT_CONN] = conn; + b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 0; b->processing = PROCESS_TCP_CONNECT_CONNECTING; return NULL; } @@ -931,7 +933,9 @@ static struct mobile_packet *command_tcp_connect_connecting(struct mobile_adapte }; if (adapter->config.mail_port) { - if (addr.port == 25) addr.port = 587; + if (!b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK]) { + if (addr.port == 25) addr.port = 587; + } } memcpy(addr.host, packet->data, 4); @@ -940,6 +944,16 @@ static struct mobile_packet *command_tcp_connect_connecting(struct mobile_adapte (struct mobile_addr *)&addr); if (rc == 0) return NULL; if (rc < 0) { + + if (adapter->config.mail_port && addr.port == 587 && !b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK]) { + mobile_debug_print(adapter, PSTR(" Failed to connect to port 587, trying port 25!")); + mobile_debug_endl(adapter); + b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 1; + addr.port = 25; + rc = mobile_cb_sock_connect(adapter, conn, (struct mobile_addr *)&addr); + if (rc == 0) return NULL; + } + mobile_cb_sock_close(adapter, conn); s->connections[conn] = false; return error_packet(packet, 3); From 7f061fa5d524846f16d6673b08a053013ffbeb7c Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Fri, 13 Jun 2025 11:37:35 -0300 Subject: [PATCH 12/18] Added get/set function for the alt mail --- config.c | 7 ++++++- mobile.h | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 6f7ebbc..d0b9a6b 100644 --- a/config.c +++ b/config.c @@ -308,7 +308,12 @@ bool mobile_config_get_relay_token(struct mobile_adapter *adapter, unsigned char return true; } -void mobile_config_alt_mail(struct mobile_adapter *adapter, bool alt_mail) +void mobile_config_set_alt_mail(struct mobile_adapter *adapter, bool alt_mail) { adapter->config.mail_port = alt_mail; +} + +bool mobile_config_get_alt_mail(struct mobile_adapter *adapter, bool *alt_mail) +{ + *alt_mail = adapter->config.mail_port; } \ No newline at end of file diff --git a/mobile.h b/mobile.h index b84c223..578e700 100644 --- a/mobile.h +++ b/mobile.h @@ -426,7 +426,8 @@ void mobile_config_set_relay(struct mobile_adapter *adapter, const struct mobile void mobile_config_get_relay(struct mobile_adapter *adapter, struct mobile_addr *relay); void mobile_config_set_relay_token(struct mobile_adapter *adapter, const unsigned char *token); bool mobile_config_get_relay_token(struct mobile_adapter *adapter, unsigned char *token); -void mobile_config_alt_mail(struct mobile_adapter *adapter, bool alt_mail); +void mobile_config_set_alt_mail(struct mobile_adapter *adapter, bool alt_mail); +void mobile_config_get_alt_mail(struct mobile_adapter *adapter, bool *alt_mail); // mobile_config_load - Manually force a load of the configuration values // From 92e819475e2e18d2eea6a34d29e96bcdee72ba47 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Fri, 13 Jun 2025 11:42:05 -0300 Subject: [PATCH 13/18] Update config.c --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.c b/config.c index d0b9a6b..b1a88cb 100644 --- a/config.c +++ b/config.c @@ -313,7 +313,7 @@ void mobile_config_set_alt_mail(struct mobile_adapter *adapter, bool alt_mail) adapter->config.mail_port = alt_mail; } -bool mobile_config_get_alt_mail(struct mobile_adapter *adapter, bool *alt_mail) +void mobile_config_get_alt_mail(struct mobile_adapter *adapter, bool *alt_mail) { *alt_mail = adapter->config.mail_port; } \ No newline at end of file From f2fe0bc2549339b632c3b573a3389d3b2e2e8cc0 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Fri, 13 Jun 2025 11:56:23 -0300 Subject: [PATCH 14/18] Init the mail port redir --- config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/config.c b/config.c index b1a88cb..0734848 100644 --- a/config.c +++ b/config.c @@ -191,6 +191,7 @@ void mobile_config_init(struct mobile_adapter *adapter) adapter->config.p2p_port = MOBILE_DEFAULT_P2P_PORT; adapter->config.relay = (struct mobile_addr){.type = MOBILE_ADDRTYPE_NONE}; adapter->config.relay_token_init = false; + adapter->config.mail_port = true; memset(adapter->config.relay_token, 0, MOBILE_RELAY_TOKEN_SIZE); } From b50bc838ad26c962711302879ef62d265d4a9b66 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Fri, 13 Jun 2025 16:09:14 -0300 Subject: [PATCH 15/18] Make the Mail Port Redirection saves the config --- config.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 0734848..b2914e4 100644 --- a/config.c +++ b/config.c @@ -107,6 +107,7 @@ static bool config_library_load(struct mobile_adapter *adapter) config->p2p_port |= buffer[0x09] << 8; config->relay.type = buffer[0x0a]; config->relay_token_init = buffer[0x0b]; + config->mail_port = buffer[0x0c]; if (!config_check_addrtype(config->dns1.type)) return false; if (!config_check_addrtype(config->dns2.type)) return false; @@ -159,8 +160,9 @@ static void config_library_save(struct mobile_adapter *adapter) buffer[0x09] = config->p2p_port >> 8; buffer[0x0a] = config->relay.type; buffer[0x0b] = config->relay_token_init; + buffer[0x0c] = config->mail_port; - // 0x0c - 0x19 unused + // 0x0d - 0x19 unused config_library_save_host(&config->dns1, buffer + 0x20, buffer + 0x1a); config_library_save_host(&config->dns2, buffer + 0x30, buffer + 0x1c); @@ -312,6 +314,7 @@ bool mobile_config_get_relay_token(struct mobile_adapter *adapter, unsigned char void mobile_config_set_alt_mail(struct mobile_adapter *adapter, bool alt_mail) { adapter->config.mail_port = alt_mail; + mobile_config_apply(adapter); } void mobile_config_get_alt_mail(struct mobile_adapter *adapter, bool *alt_mail) From 093209af0772c36fcb57e33d739e3bf1c8ca7662 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Tue, 24 Jun 2025 18:10:32 -0300 Subject: [PATCH 16/18] Update commands.c --- commands.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/commands.c b/commands.c index f21a5fb..18cf5f0 100644 --- a/commands.c +++ b/commands.c @@ -907,15 +907,16 @@ static struct mobile_packet *command_tcp_connect_begin(struct mobile_adapter *ad } s->connections[conn] = true; + b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 1; if (adapter->config.mail_port) { if ((packet->data[4] << 8 | packet->data[5]) == 25) { mobile_debug_print(adapter, PSTR(" Replacing port 25 to 587!")); mobile_debug_endl(adapter); + b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 0; } } b->processing_data[PROCDATA_TCP_CONNECT_CONN] = conn; - b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 0; b->processing = PROCESS_TCP_CONNECT_CONNECTING; return NULL; } @@ -945,18 +946,28 @@ static struct mobile_packet *command_tcp_connect_connecting(struct mobile_adapte if (rc == 0) return NULL; if (rc < 0) { - if (adapter->config.mail_port && addr.port == 587 && !b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK]) { + if (!b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK]) { mobile_debug_print(adapter, PSTR(" Failed to connect to port 587, trying port 25!")); mobile_debug_endl(adapter); + + mobile_cb_sock_close(adapter, conn); + if (!mobile_cb_sock_open(adapter, conn, MOBILE_SOCKTYPE_TCP, + MOBILE_ADDRTYPE_IPV4, 0)) { + s->connections[conn] = false; + return error_packet(packet, 3); + } + b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 1; addr.port = 25; rc = mobile_cb_sock_connect(adapter, conn, (struct mobile_addr *)&addr); if (rc == 0) return NULL; } - mobile_cb_sock_close(adapter, conn); - s->connections[conn] = false; - return error_packet(packet, 3); + if (rc < 0) { + mobile_cb_sock_close(adapter, conn); + s->connections[conn] = false; + return error_packet(packet, 3); + } } packet->data[0] = conn; From 6d3b979606ef0a9a70909cd807a7c631ea0c451c Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Tue, 24 Jun 2025 18:24:48 -0300 Subject: [PATCH 17/18] Revert "Update commands.c" This reverts commit 093209af0772c36fcb57e33d739e3bf1c8ca7662. --- commands.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/commands.c b/commands.c index 18cf5f0..f21a5fb 100644 --- a/commands.c +++ b/commands.c @@ -907,16 +907,15 @@ static struct mobile_packet *command_tcp_connect_begin(struct mobile_adapter *ad } s->connections[conn] = true; - b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 1; if (adapter->config.mail_port) { if ((packet->data[4] << 8 | packet->data[5]) == 25) { mobile_debug_print(adapter, PSTR(" Replacing port 25 to 587!")); mobile_debug_endl(adapter); - b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 0; } } b->processing_data[PROCDATA_TCP_CONNECT_CONN] = conn; + b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 0; b->processing = PROCESS_TCP_CONNECT_CONNECTING; return NULL; } @@ -946,28 +945,18 @@ static struct mobile_packet *command_tcp_connect_connecting(struct mobile_adapte if (rc == 0) return NULL; if (rc < 0) { - if (!b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK]) { + if (adapter->config.mail_port && addr.port == 587 && !b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK]) { mobile_debug_print(adapter, PSTR(" Failed to connect to port 587, trying port 25!")); mobile_debug_endl(adapter); - - mobile_cb_sock_close(adapter, conn); - if (!mobile_cb_sock_open(adapter, conn, MOBILE_SOCKTYPE_TCP, - MOBILE_ADDRTYPE_IPV4, 0)) { - s->connections[conn] = false; - return error_packet(packet, 3); - } - b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 1; addr.port = 25; rc = mobile_cb_sock_connect(adapter, conn, (struct mobile_addr *)&addr); if (rc == 0) return NULL; } - if (rc < 0) { - mobile_cb_sock_close(adapter, conn); - s->connections[conn] = false; - return error_packet(packet, 3); - } + mobile_cb_sock_close(adapter, conn); + s->connections[conn] = false; + return error_packet(packet, 3); } packet->data[0] = conn; From d27702c67cd13b3eb6c1c527b57ded7df3fc2042 Mon Sep 17 00:00:00 2001 From: Rafael Zenaro Date: Tue, 24 Jun 2025 19:28:42 -0300 Subject: [PATCH 18/18] Update commands.c --- commands.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/commands.c b/commands.c index f21a5fb..18cf5f0 100644 --- a/commands.c +++ b/commands.c @@ -907,15 +907,16 @@ static struct mobile_packet *command_tcp_connect_begin(struct mobile_adapter *ad } s->connections[conn] = true; + b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 1; if (adapter->config.mail_port) { if ((packet->data[4] << 8 | packet->data[5]) == 25) { mobile_debug_print(adapter, PSTR(" Replacing port 25 to 587!")); mobile_debug_endl(adapter); + b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 0; } } b->processing_data[PROCDATA_TCP_CONNECT_CONN] = conn; - b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 0; b->processing = PROCESS_TCP_CONNECT_CONNECTING; return NULL; } @@ -945,18 +946,28 @@ static struct mobile_packet *command_tcp_connect_connecting(struct mobile_adapte if (rc == 0) return NULL; if (rc < 0) { - if (adapter->config.mail_port && addr.port == 587 && !b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK]) { + if (!b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK]) { mobile_debug_print(adapter, PSTR(" Failed to connect to port 587, trying port 25!")); mobile_debug_endl(adapter); + + mobile_cb_sock_close(adapter, conn); + if (!mobile_cb_sock_open(adapter, conn, MOBILE_SOCKTYPE_TCP, + MOBILE_ADDRTYPE_IPV4, 0)) { + s->connections[conn] = false; + return error_packet(packet, 3); + } + b->processing_data[PROCDATA_TCP_CONNECT_FALLBACK] = 1; addr.port = 25; rc = mobile_cb_sock_connect(adapter, conn, (struct mobile_addr *)&addr); if (rc == 0) return NULL; } - mobile_cb_sock_close(adapter, conn); - s->connections[conn] = false; - return error_packet(packet, 3); + if (rc < 0) { + mobile_cb_sock_close(adapter, conn); + s->connections[conn] = false; + return error_packet(packet, 3); + } } packet->data[0] = conn;