Module: TempmailSdk::Providers::MaildropCc
- Defined in:
- lib/tempmail_sdk/providers/maildrop_cc.rb
Overview
maildrop.cc GraphQL API 渠道 — https://maildrop.cc 无认证,公共邮箱
Constant Summary collapse
- CHANNEL =
"maildrop-cc"- DOMAIN =
"maildrop.cc"- GRAPHQL_URL =
"https://api.maildrop.cc/graphql"- HEADERS =
{ "Accept" => "application/json", "Content-Type" => "application/json", "Origin" => "https://maildrop.cc", "Referer" => "https://maildrop.cc/", "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
- LOCAL_CHARS =
("a".."z").to_a + ("0".."9").to_a
Class Method Summary collapse
- .do_graphql(query) ⇒ Object
-
.generate_email ⇒ EmailInfo
创建 maildrop.cc 临时邮箱.
-
.get_emails(email, token = "") ⇒ Array<Email>
获取邮件列表.
- .inbox_query(mb) ⇒ Object
- .mailbox(email) ⇒ Object
- .message_query(mb, mid) ⇒ Object
- .random_local(n = 10) ⇒ Object
Class Method Details
.do_graphql(query) ⇒ Object
38 39 40 41 42 |
# File 'lib/tempmail_sdk/providers/maildrop_cc.rb', line 38 def do_graphql(query) resp = Http.post(GRAPHQL_URL, headers: HEADERS, json: { "query" => query }) resp.raise_for_status resp.json end |
.generate_email ⇒ EmailInfo
创建 maildrop.cc 临时邮箱
57 58 59 60 |
# File 'lib/tempmail_sdk/providers/maildrop_cc.rb', line 57 def generate_email email = "#{random_local(10)}@#{DOMAIN}" EmailInfo.new(channel: CHANNEL, email: email, token: email) end |
.get_emails(email, token = "") ⇒ Array<Email>
获取邮件列表
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/tempmail_sdk/providers/maildrop_cc.rb', line 66 def get_emails(email, token = "") mb = mailbox(email) raise "maildrop-cc: 邮箱地址为空" if mb.empty? inbox_resp = do_graphql(inbox_query(mb)) items = ((inbox_resp || {})["data"] || {})["inbox"] return [] unless items.is_a?(Array) && !items.empty? items.filter_map do |item| next unless item.is_a?(Hash) mid = (item["id"] || "").to_s raw = { "id" => mid, "from" => item["headerfrom"] || "", "subject" => item["subject"] || "", "date" => item["date"] || "" } # 查询单封详情补全 html 正文 unless mid.empty? begin msg_resp = do_graphql((mb, mid)) msg = ((msg_resp || {})["data"] || {})["message"] if msg.is_a?(Hash) raw = { "id" => msg["id"] || mid, "from" => msg["headerfrom"] || "", "subject" => msg["subject"] || "", "date" => msg["date"] || "", "html" => msg["html"] || "" } end rescue StandardError # 回退使用列表元信息 end end Normalize.normalize_email(raw, email) end end |
.inbox_query(mb) ⇒ Object
44 45 46 47 |
# File 'lib/tempmail_sdk/providers/maildrop_cc.rb', line 44 def inbox_query(mb) mb_s = JSON.generate(mb) "query { inbox(mailbox: #{mb_s}) { id headerfrom subject date } }" end |
.mailbox(email) ⇒ Object
32 33 34 35 36 |
# File 'lib/tempmail_sdk/providers/maildrop_cc.rb', line 32 def mailbox(email) e = (email || "").strip idx = e.index("@") idx ? e[0...idx] : e end |
.message_query(mb, mid) ⇒ Object
49 50 51 52 53 |
# File 'lib/tempmail_sdk/providers/maildrop_cc.rb', line 49 def (mb, mid) mb_s = JSON.generate(mb) mid_s = JSON.generate(mid) "query { message(mailbox: #{mb_s}, id: #{mid_s}) { id headerfrom subject date html } }" end |
.random_local(n = 10) ⇒ Object
28 29 30 |
# File 'lib/tempmail_sdk/providers/maildrop_cc.rb', line 28 def random_local(n = 10) Array.new(n) { LOCAL_CHARS.sample }.join end |