Module: TempmailSdk::Providers::Tempinbox

Defined in:
lib/tempmail_sdk/providers/tempinbox.rb

Overview

TempInbox 渠道实现 API: https://endpoint.tempinbox.xyz

Constant Summary collapse

CHANNEL =
"tempinbox"
BASE =
"https://endpoint.tempinbox.xyz"
DOMAINS =

支持的域名列表

%w[tempinbox.xyz thepiratebay.cloud cryptoblad.nl].freeze
HEADERS =
{
  "Accept" => "application/json, text/plain, */*",
  "Cache-Control" => "no-cache",
  "DNT" => "1",
  "Referer" => "https://www.tempinbox.xyz/",
  "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.0.0"
}.freeze

Class Method Summary collapse

Class Method Details

.generate_email(domain = nil) ⇒ EmailInfo

创建临时邮箱

Parameters:

  • domain (String, nil) (defaults to: nil)

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tempmail_sdk/providers/tempinbox.rb', line 33

def generate_email(domain = nil)
  if domain && !domain.to_s.strip.empty?
    d = domain.strip.downcase
    raise "tempinbox: 域名不可用: #{d}" unless DOMAINS.include?(d)

    user = random_user
    addr = "#{user}@#{d}"
    Http.get("#{BASE}/email/#{addr}", headers: HEADERS, timeout: 15).raise_for_status
  else
    resp = Http.get("#{BASE}/email/Random", headers: HEADERS, timeout: 15)
    resp.raise_for_status
    addr = resp.body.strip.delete('"')
  end

  raise "tempinbox: 无效的邮箱地址" if addr.to_s.empty? || !addr.include?("@")

  EmailInfo.new(channel: CHANNEL, email: addr)
end

.get_emails(email) ⇒ Array<Email>

获取邮件列表

Parameters:

  • email (String)

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tempmail_sdk/providers/tempinbox.rb', line 55

def get_emails(email)
  addr = email.to_s.strip
  raise "tempinbox: 邮箱地址为空" if addr.empty?

  resp = Http.get("#{BASE}/messages/#{addr}", headers: HEADERS, timeout: 15)
  resp.raise_for_status
  data = resp.json
  return [] unless data.is_a?(Array)

  data.select { |raw| raw.is_a?(Hash) }.map do |raw|
    Normalize.normalize_email(raw, addr)
  end
end

.random_user(length = 10) ⇒ Object

生成随机用户名



25
26
27
28
# File 'lib/tempmail_sdk/providers/tempinbox.rb', line 25

def random_user(length = 10)
  chars = ("a".."z").to_a + ("0".."9").to_a
  Array.new(length) { chars.sample }.join
end