Skip to main content

yopmail_client/
constants.rs

1//! HTTP and protocol constants used to emulate the YOPmail web UI.
2//!
3//! Most constants here exist only to support the internal request/parse logic.
4use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
5use std::time::Duration;
6
7/// Default base URL used by [`YopmailClient`](crate::YopmailClient).
8pub const BASE_URL: &str = "https://yopmail.com";
9/// Default domain used when building full YOPmail addresses.
10pub const DEFAULT_DOMAIN: &str = "yopmail.com";
11/// Version parameter used by the YOPmail inbox/mail endpoints.
12pub(crate) const VERSION: &str = "9.3";
13/// "ad" query parameter used by the YOPmail inbox/mail endpoints.
14pub(crate) const AD_PARAM: i32 = 0;
15/// Default timeout in seconds used by [`default_timeout`].
16pub const DEFAULT_TIMEOUT_SECS: u64 = 30;
17
18/// Build the default HTTP headers used by this client.
19///
20/// This converts [`DEFAULT_HEADERS`] into a `reqwest::header::HeaderMap`, skipping any values that
21/// fail to parse.
22pub(crate) fn default_headers() -> HeaderMap {
23    let mut headers = HeaderMap::new();
24    for (k, v) in DEFAULT_HEADERS {
25        let name = HeaderName::from_static(k);
26        if let Ok(val) = HeaderValue::from_str(v) {
27            headers.insert(name, val);
28        }
29    }
30    headers
31}
32
33/// Default header pairs used by [`default_headers`].
34pub(crate) const DEFAULT_HEADERS: &[(&str, &str)] = &[
35    (
36        "user-agent",
37        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
38    ),
39    (
40        "accept",
41        "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
42    ),
43    ("accept-language", "en-US,en;q=0.5"),
44    ("accept-encoding", "gzip, deflate"),
45    ("connection", "keep-alive"),
46    ("upgrade-insecure-requests", "1"),
47];
48
49/// Extra headers used for inbox listing requests.
50pub(crate) const INBOX_HEADERS: &[(&str, &str)] = &[
51    ("referer", "https://yopmail.com/en/wm"),
52    ("sec-fetch-dest", "iframe"),
53    ("sec-fetch-mode", "navigate"),
54    ("sec-fetch-site", "same-origin"),
55];
56
57/// Extra headers used for mail fetch requests.
58pub(crate) const MAIL_HEADERS: &[(&str, &str)] = &[
59    ("referer", "https://yopmail.com/en/wm"),
60    ("sec-fetch-dest", "iframe"),
61    ("sec-fetch-mode", "navigate"),
62    ("sec-fetch-site", "same-origin"),
63    ("sec-fetch-user", "?1"),
64    ("upgrade-insecure-requests", "1"),
65];
66
67/// Extra headers used for message sending requests.
68pub(crate) const SEND_HEADERS: &[(&str, &str)] = &[
69    ("content-type", "application/x-www-form-urlencoded"),
70    ("origin", "https://yopmail.com"),
71    ("referer", "https://yopmail.com/wm"),
72    ("accept", "*/*"),
73    ("accept-language", "en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7"),
74    ("accept-encoding", "gzip, deflate, br, zstd"),
75    ("sec-fetch-dest", "empty"),
76    ("sec-fetch-mode", "cors"),
77    ("sec-fetch-site", "same-origin"),
78    ("priority", "u=1, i"),
79];
80
81/// Fallback `yp` token used when the login page does not contain an extractable value.
82pub(crate) const FALLBACK_YP_TOKEN: &str = "ZAGplZmp0ZmR3ZQN4ZGx1ZGR";
83
84/// Default request timeout used by the client.
85pub fn default_timeout() -> Duration {
86    Duration::from_secs(DEFAULT_TIMEOUT_SECS)
87}