Module: TempmailSdk::Providers::DropmailClick
- Defined in:
- lib/tempmail_sdk/providers/dropmail_click.rb
Overview
dropmail.click 渠道实现 独立后端临时邮箱,免注册、无鉴权。Token 即邮箱地址本身。
Constant Summary collapse
- CHANNEL =
"dropmail-click"- BASE_URL =
"https://dropmail.click"- DEFAULT_UA =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " \ "(KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36"
Class Method Summary collapse
- .first_val(msg, *keys) ⇒ Object
- .generate_email ⇒ EmailInfo
- .get_emails(email) ⇒ Array<Email>
- .get_ua ⇒ Object
Class Method Details
.first_val(msg, *keys) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/tempmail_sdk/providers/dropmail_click.rb', line 20 def first_val(msg, *keys) keys.each do |key| val = msg[key] return val.to_s if !val.nil? && val != "" end "" end |
.generate_email ⇒ EmailInfo
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tempmail_sdk/providers/dropmail_click.rb', line 29 def generate_email resp = Http.post( "#{BASE_URL}/api/v1/public/mailbox", headers: { "User-Agent" => get_ua, "Accept" => "application/json" } ) resp.raise_for_status data = resp.json raise "dropmail-click: invalid response" unless data.is_a?(Hash) address = data["address"].to_s raise "dropmail-click: missing address" if address.empty? EmailInfo.new( channel: CHANNEL, email: address, token: address, expires_at: data["expires_at"] ) end |
.get_emails(email) ⇒ Array<Email>
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tempmail_sdk/providers/dropmail_click.rb', line 51 def get_emails(email) addr = email.to_s.strip raise "dropmail-click: missing email" if addr.empty? resp = Http.get( "#{BASE_URL}/api/v1/public/mailbox/#{URI.encode_www_form_component(addr)}", headers: { "User-Agent" => get_ua, "Accept" => "application/json" } ) resp.raise_for_status data = resp.json return [] unless data.is_a?(Hash) = data["messages"] return [] unless .is_a?(Array) .select { |m| m.is_a?(Hash) }.map do |msg| row = { "id" => first_val(msg, "id"), "from" => first_val(msg, "from"), "to" => first_val(msg, "address").empty? ? addr : first_val(msg, "address"), "subject" => first_val(msg, "subject"), "text" => first_val(msg, "text"), "html" => first_val(msg, "html"), "date" => first_val(msg, "received_at", "date") } Normalize.normalize_email(row, addr) end end |
.get_ua ⇒ Object
15 16 17 18 |
# File 'lib/tempmail_sdk/providers/dropmail_click.rb', line 15 def get_ua cfg = Config.get_config (cfg.headers || {})["User-Agent"] || DEFAULT_UA end |