feat: support http/https proxy for IMAP #21

Merged
thuanle merged 4 commits from feat/issue-9-http-proxy into main 2026-04-28 11:09:03 +07:00
Collaborator

Summary

Extends IMAP_PROXY_URL to support http:// and https:// proxy schemes (via HTTP CONNECT tunnel) in addition to the existing socks5:// support.

Changes:

  • Refactored dialTLSViaSOCKS5 into generic dialTLSViaProxy dispatcher
  • New dialViaCONNECT for HTTP CONNECT tunneling (both http:// and https://)
  • New dialViaSOCKS5 helper preserving existing SOCKS5 behavior
  • Proxy auth via user:pass@ in URL for all schemes
  • Clear errors on failures — never silently falls back to direct dial
  • No new external dependencies

Test plan

go test ./internal/mail/... -v -count=1

All 18 tests pass covering:

# Test Covers
1 UsesDirectDial_WhenProxyUnset No regression when proxy empty
2 UsesProxyDial_WhenProxySet Proxy path selected when configured
3 RejectsUnsupportedScheme e.g. ftp:// → error
4 RejectsMalformedURL Bad URL → error
5 SOCKS5_UsesDialContextWithTimeout SOCKS5 no regression
6 SOCKS5_SetsDeadlineForTLSHandshake TLS deadline set
7 HTTPConnect_ReachesTLSHandshake CONNECT succeeds, TLS to IMAP
8 HTTPConnect_RejectsOnProxyFailure Proxy returns 403 → error
9 HTTPConnect_SendsProxyAuth Basic auth header sent
10 HTTPConnect_DialError Proxy unreachable → error
11 HTTPSConnect_ReachesTLSHandshake TLS to proxy + CONNECT succeeds
go vet ./...
go test ./... -count=1

All pass clean.

Fixes #9

🤖 Generated with Claude Code

## Summary Extends `IMAP_PROXY_URL` to support `http://` and `https://` proxy schemes (via HTTP CONNECT tunnel) in addition to the existing `socks5://` support. **Changes:** - Refactored `dialTLSViaSOCKS5` into generic `dialTLSViaProxy` dispatcher - New `dialViaCONNECT` for HTTP CONNECT tunneling (both `http://` and `https://`) - New `dialViaSOCKS5` helper preserving existing SOCKS5 behavior - Proxy auth via `user:pass@` in URL for all schemes - Clear errors on failures — never silently falls back to direct dial - No new external dependencies ## Test plan ``` go test ./internal/mail/... -v -count=1 ``` All 18 tests pass covering: | # | Test | Covers | |---|------|--------| | 1 | `UsesDirectDial_WhenProxyUnset` | No regression when proxy empty | | 2 | `UsesProxyDial_WhenProxySet` | Proxy path selected when configured | | 3 | `RejectsUnsupportedScheme` | e.g. `ftp://` → error | | 4 | `RejectsMalformedURL` | Bad URL → error | | 5 | `SOCKS5_UsesDialContextWithTimeout` | SOCKS5 no regression | | 6 | `SOCKS5_SetsDeadlineForTLSHandshake` | TLS deadline set | | 7 | `HTTPConnect_ReachesTLSHandshake` | CONNECT succeeds, TLS to IMAP | | 8 | `HTTPConnect_RejectsOnProxyFailure` | Proxy returns 403 → error | | 9 | `HTTPConnect_SendsProxyAuth` | Basic auth header sent | | 10 | `HTTPConnect_DialError` | Proxy unreachable → error | | 11 | `HTTPSConnect_ReachesTLSHandshake` | TLS to proxy + CONNECT succeeds | ``` go vet ./... go test ./... -count=1 ``` All pass clean. Fixes #9 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claudecode added 2 commits 2026-04-28 10:57:27 +07:00
feat: support http/https proxy for IMAP via HTTP CONNECT tunnel
CI / test (pull_request) Successful in 10m47s
CI / fmt (pull_request) Successful in 4m45s
f978ed44b8
Extend IMAP_PROXY_URL to accept http:// and https:// schemes in addition
to the existing socks5:// support. HTTP CONNECT tunneling is used for
both new schemes, with TLS to the proxy for https://. Proxy auth via
user:pass@ in the URL is supported for all schemes.

Refactors dialTLSViaSOCKS5 into a generic dialTLSViaProxy dispatcher.

Fixes #9

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
claudecode requested review from codex 2026-04-28 10:57:34 +07:00
Owner

FAIL

  1. [High] AGENT.md:6, AGENT.md:12, AGENT.md:18, AGENT.md:89, AGENT.md:91 are unrelated to issue #9. This PR is scoped to IMAP proxy support, but it also changes repository process/instruction text (including removing the gh guidance). Our review rules explicitly fail scope creep, so these AGENT.md edits need to be dropped from this PR or moved into a separate issue/PR.

Validation:

  • gofmt -l .: OK
  • go vet ./...: OK
  • go test ./internal/mail/... -count=1: OK
  • go test ./... -count=1: OK

Các dòng agent đó tôi sửa nhầm tree. Tuy nhiên, ok để push vào, giúp các agent chạy ít tốn token hơn

> FAIL > > 1. [High] `AGENT.md:6`, `AGENT.md:12`, `AGENT.md:18`, `AGENT.md:89`, `AGENT.md:91` are unrelated to issue `#9`. This PR is scoped to IMAP proxy support, but it also changes repository process/instruction text (including removing the `gh` guidance). Our review rules explicitly fail scope creep, so these `AGENT.md` edits need to be dropped from this PR or moved into a separate issue/PR. > > Validation: > - `gofmt -l .`: OK > - `go vet ./...`: OK > - `go test ./internal/mail/... -count=1`: OK > - `go test ./... -count=1`: OK Các dòng agent đó tôi sửa nhầm tree. Tuy nhiên, ok để push vào, giúp các agent chạy ít tốn token hơn
codex approved these changes 2026-04-28 11:05:41 +07:00
codex left a comment
Collaborator

PASS

Rechecked after the repo-owner feedback on comment #891: the AGENT.md changes are explicitly accepted, so they are no longer a blocking scope issue for this PR.

No blocking technical issues found in the IMAP proxy implementation.

Validation:

  • gofmt -l .: OK
  • go vet ./...: OK
  • go test ./internal/mail/... -count=1: OK
  • go test ./... -count=1: OK

Non-blocking:

  • AGENT.md:89 has a typo (Alway -> Always), but that can be cleaned up separately if you want.
PASS Rechecked after the repo-owner feedback on comment `#891`: the `AGENT.md` changes are explicitly accepted, so they are no longer a blocking scope issue for this PR. No blocking technical issues found in the IMAP proxy implementation. Validation: - `gofmt -l .`: OK - `go vet ./...`: OK - `go test ./internal/mail/... -count=1`: OK - `go test ./... -count=1`: OK Non-blocking: - `AGENT.md:89` has a typo (`Alway` -> `Always`), but that can be cleaned up separately if you want.
thuanle added 1 commit 2026-04-28 11:07:39 +07:00
fix: typo Alway -> Always in AGENT.md
CI / test (pull_request) Successful in 11m0s
CI / fmt (pull_request) Successful in 4m58s
6af6da1d99
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
thuanle added 1 commit 2026-04-28 11:08:54 +07:00
Merge branch 'main' into feat/issue-9-http-proxy
CI / fmt (pull_request) Successful in 4m42s
CI / vet (pull_request) Successful in 10m35s
CI / test (pull_request) Successful in 12m55s
CI / staticcheck (pull_request) Successful in 11m2s
200bba7549
thuanle merged commit 193868ca23 into main 2026-04-28 11:09:03 +07:00
thuanle deleted branch feat/issue-9-http-proxy 2026-04-28 11:09:03 +07:00
Sign in to join this conversation.
No Reviewers
No labels
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: thuanle/claw-email#21