컬을 사용하여 Gmail 편지의 제목을 얻는 방법은 무엇입니까?

컬을 사용하여 Gmail 편지의 제목을 얻는 방법은 무엇입니까?

나는 curl새로운 메일링 리스트를 얻기 위해 Lua 프로그램을 사용하고 있습니다. 이런 요청을 보내려고 해요

local head_command = "curl --connect-timeout 30 -fsm 30"
local server       = "imap.gmail.com"
local mail         = "***"
local password     = "***"
local port         = 993
local request      = "-X 'FETCH 86 BODY.PEEK[HEADER.FIELDS (SUBJECT)]'"
local curl = string.format("%s --url 'imaps://%s:%s/INBOX' -u %s:%q %s -k", head_command, server, port, mail, password, request)
helpers.async(curl, function(stdout, exit_code)
  naughty.notify { text = stdout, timeout = 0 }
end )

하지만 내가 얻는 것은

* 86 FETCH (BODY[HEADER.FIELDS (SUBJECT)] {54}

FETCH어떤 명령에 대해서도 이 응답을 받습니다.

URL에 직접 지정하면 메시지를 받을 수 있습니다 HEADER.UID

imaps://%s:%s/INBOX;UID=86/;SECTION=HEADER

이것은 이것을 출력합니다

Delivered-To: [email protected]

Received: by 10.140.91.106 with SMTP id y97csp1976911qgd; Mon, 25 May 2015
 18:50:08 -0700 (PDT)
X-Received: by 10.112.142.232 with SMTP id rz8mr19609586lbb.74.1432605008430;
 Mon, 25 May 2015 18:50:08 -0700 (PDT)
Return-Path: <[email protected]>
Received: from f342.i.mail.ru (f342.i.mail.ru. [217.69.140.238]) by
 mx.google.com with ESMTPS id b3si5030682lbd.117.2015.05.25.18.50.07 for
 <[email protected]> (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256
 bits=128/128); Mon, 25 May 2015 18:50:08 -0700 (PDT)
Received-SPF: pass (google.com: domain of [email protected] designates
 217.69.140.238 as permitted sender) client-ip=217.69.140.238;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of
 [email protected] designates 217.69.140.238 as permitted sender)
 [email protected]; dkim=pass [email protected]; dmarc=pass (p=NONE
 dis=NONE) header.from=mail.ru
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru;
 s=mail2; h=Content-Type:Message-ID:Reply-To:Date:MIME-Version:To:From;
 bh=vOFnL58jZvcsH24k/6XvHT0DhLLtNvAaCxTAZUvggn4=;
 b=GJpRK8wJfOfrrlW6KycI6CDBUPTlQNBSNmAswE+5M67hdePFUeoHkakQdh8ziPtmOPsSWCwLs2spcqXjTkQ1Ny2raWBrbVaaFKPSxzdi7m6JGfwJ3Snkv1DMGBhGVCqBOIwVj7iCdnBEzYQhCMgZ6UvjDNv15PReV5MiJzECnG0=;
Received: from [194.125.255.143] (ident=mail) by f342.i.mail.ru with local
 (envelope-from <[email protected]>) id 1Yx40N-0001gA-0m for
 [email protected]; Tue, 26 May 2015 04:50:07 +0300
Received: from [194.125.255.143] by e.mail.ru with HTTP; Tue, 26 May 2015
 04:50:06 +0300
From: =?UTF-8?B?0JzQsNGA0LjQvdCwINCR0YPQs9Cw0LXQstCw?= <[email protected]>
To: =?UTF-8?B?0JrQuNGA0LjQu9C7INCR0YPQs9Cw0LXQsg==?= <[email protected]>
MIME-Version: 1.0
X-Mailer: Mail.Ru Mailer 1.0
X-Originating-IP: [194.125.255.143]
Date: Tue, 26 May 2015 04:50:06 +0300
Reply-To: =?UTF-8?B?0JzQsNGA0LjQvdCwINCR0YPQs9Cw0LXQstCw?= <[email protected]>
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Content-Type: multipart/alternative;
 boundary="--ALT--rUEeoQugXy3WMzk9UAxdG7pumUrVItQl1432605006"
X-Mras: Ok
X-Spam: undefined

그런데 어떻게 SUBJECT이런 식으로 메시지를 받을 수 있나요?

답변1

나는 문제를 이해한다고 생각합니다. Gmail은 여러 단계로 응답을 보내고, 컬은 먼저 출력만 보냅니다. 메시지 주제를 검색할 수 있는 루아 코드를 작성했습니다. 이 같은

local socket    = require "socket"
local ssl       = require "ssl"
local format    = string.format

local server   = "imap.gmail.com"
local port     = 993
local login    = "[email protected]"
local password = "***"
local params = {
    mode = "client",
    protocol = "tlsv1",
    verify = "none",
    options = "all",
}

local conn = socket.connect(server, port)
conn = ssl.wrap(conn, params)
conn:dohandshake()
conn:settimeout(5)

conn:send(format("123 LOGIN %s %s", login, password) .. '\r\n')
conn:send("123 EXAMINE INBOX" .. '\r\n')
conn:send("123 FETCH 86 BODY.PEEK[HEADER.FIELDS (SUBJECT)]" .. '\r\n')

local result = ""
while result do
    result = conn:receive()
    if result then
        print(result)
    end
end

conn:send("LOGOUT")
conn:close()

그것은 출력한다

* OK Gimap ready for requests from 176.114.188.238 q1mb64314748lfc
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584
123 OK [email protected] authenticated (Success)
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen $NotPhishing $Phishing)
* OK [PERMANENTFLAGS ()] Flags permitted.
* OK [UIDVALIDITY 1] UIDs valid.
* 352 EXISTS
* 0 RECENT
* OK [UIDNEXT 1283] Predicted next UID.
* OK [HIGHESTMODSEQ 218991]
123 OK [READ-ONLY] INBOX selected. (Success)
* 86 FETCH (BODY[HEADER.FIELDS (SUBJECT)] {37}
Subject: =?UTF-8?B?UmVbMTJdOiA=?=

)
123 OK Success

관련 정보