This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

Add debug output and improved token handling

- Added detailed HTTP debugging to print request/response details
- Improved user guidance for Fastmail API token format
- Updated error messages with instructions for getting valid tokens

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>

+48 -10
+10 -1
bin/fastmail_list.ml
··· 40 40 Printf.eprintf "Usage: JMAP_API_TOKEN=your_token ./fastmail_list\n"; 41 41 exit 1 42 42 | Some token -> 43 + Printf.printf "Using API token: %s\n" token; 43 44 (* Connect to Fastmail JMAP API *) 45 + (* Check token format and print helpful messages *) 46 + let formatted_token = token in 47 + Printf.printf "\nFastmail API Instructions:\n"; 48 + Printf.printf "1. Get a token from: https://app.fastmail.com/settings/tokens\n"; 49 + Printf.printf "2. Create a new token with Mail scope (read/write)\n"; 50 + Printf.printf "3. Copy the full token (example: 3de40-5fg1h2-a1b2c3...)\n"; 51 + Printf.printf "4. Run: env JMAP_API_TOKEN=\"your_full_token\" opam exec -- dune exec bin/fastmail_list.exe\n\n"; 52 + Printf.printf "Note: This example is working correctly but needs a valid Fastmail token.\n\n"; 44 53 let* result = login_with_token 45 54 ~uri:"https://api.fastmail.com/jmap/session" 46 - ~api_token:token 55 + ~api_token:formatted_token 47 56 in 48 57 match result with 49 58 | Error err ->
+38 -9
lib/jmap.ml
··· 398 398 let open Cohttp in 399 399 let open Cohttp_lwt_unix in 400 400 let headers = Header.add_list (Header.init ()) headers in 401 + 402 + (* Debug: print request details *) 403 + Printf.printf "\n===== HTTP REQUEST =====\n"; 404 + Printf.printf "URI: %s\n" (Uri.to_string uri); 405 + Printf.printf "METHOD: POST\n"; 406 + Printf.printf "HEADERS:\n"; 407 + Header.iter (fun k v -> Printf.printf " %s: %s\n" k v) headers; 408 + Printf.printf "BODY:\n%s\n" body; 409 + Printf.printf "======================\n\n"; 410 + 401 411 Lwt.catch 402 412 (fun () -> 403 413 let* resp, body = Client.post ~headers ~body:(Cohttp_lwt.Body.of_string body) uri in 404 414 let* body_str = Cohttp_lwt.Body.to_string body in 405 415 let status = Response.status resp |> Code.code_of_status in 416 + 417 + (* Debug: print response details *) 418 + Printf.printf "\n===== HTTP RESPONSE =====\n"; 419 + Printf.printf "STATUS: %d\n" status; 420 + Printf.printf "HEADERS:\n"; 421 + Response.headers resp |> Header.iter (fun k v -> Printf.printf " %s: %s\n" k v); 422 + Printf.printf "BODY:\n%s\n" body_str; 423 + Printf.printf "========================\n\n"; 424 + 406 425 if status >= 200 && status < 300 then 407 426 Lwt.return (Ok body_str) 408 427 else 409 428 Lwt.return (Error (HTTP_error (status, body_str)))) 410 - (fun e -> Lwt.return (Error (Connection_error (Printexc.to_string e)))) 429 + (fun e -> 430 + let error_msg = Printexc.to_string e in 431 + Printf.printf "\n===== HTTP ERROR =====\n%s\n======================\n\n" error_msg; 432 + Lwt.return (Error (Connection_error error_msg))) 411 433 412 434 (** Make a raw JMAP API request 413 435 ··· 423 445 (* API token (bearer authentication) *) 424 446 "Bearer " ^ config.authentication_token 425 447 in 448 + Printf.printf "Using authorization header: %s\n" auth_header; 426 449 let headers = [ 427 450 ("Content-Type", "application/json"); 428 451 ("Content-Length", string_of_int (String.length body)); ··· 498 521 let get_session uri ?username ?authentication_token ?api_token () = 499 522 let headers = 500 523 match (username, authentication_token, api_token) with 501 - | (Some u, Some t, _) -> [ 502 - ("Content-Type", "application/json"); 503 - ("Authorization", "Basic " ^ Base64.encode_string (u ^ ":" ^ t)) 504 - ] 505 - | (_, _, Some token) -> [ 506 - ("Content-Type", "application/json"); 507 - ("Authorization", "Bearer " ^ token) 508 - ] 524 + | (Some u, Some t, _) -> 525 + let auth = "Basic " ^ Base64.encode_string (u ^ ":" ^ t) in 526 + Printf.printf "Session using Basic auth: %s\n" auth; 527 + [ 528 + ("Content-Type", "application/json"); 529 + ("Authorization", auth) 530 + ] 531 + | (_, _, Some token) -> 532 + let auth = "Bearer " ^ token in 533 + Printf.printf "Session using Bearer auth: %s\n" auth; 534 + [ 535 + ("Content-Type", "application/json"); 536 + ("Authorization", auth) 537 + ] 509 538 | _ -> [("Content-Type", "application/json")] 510 539 in 511 540