diff --git a/platform/shell-sync/sync.sh b/platform/shell-sync/sync.sh index 63c9d577..79a5cc61 100644 --- a/platform/shell-sync/sync.sh +++ b/platform/shell-sync/sync.sh @@ -267,3 +267,27 @@ sync_account() { args+=($extra_opts) fi + # Capture the real exit status. Reading $? after an `if` block returns the + # status of the `if` itself (always 0), which silently reported every + # failure as exit 0 and let sync_all treat it as success. + sync_exit=0 + imapsync "${args[@]}" >> "$logfile" 2>&1 || sync_exit=$? + + if [ "$sync_exit" -eq 0 ]; then + log "Account $i: SYNC OK" + echo "$(date +%s)" > "${LOG_DIR}/account${i}.last_success" + SYNC_ACCOUNT_RESULT="success" + rm -f "$pidfile" + return 0 + fi + + log "Account $i: SYNC FAILED (exit $sync_exit)" + echo "$(date +%s)" > "${LOG_DIR}/account${i}.last_failure" + if [ "$src_auth" = "oauth2" ] && [ "$oauth_authorization_detected" = "false" ]; then + log_oauth_authorization_guidance "$i" "$src_provider" "$logfile" + fi + SYNC_ACCOUNT_RESULT="failure" + rm -f "$pidfile" + return "$sync_exit" +} +