Sample Header Ad - 728x90

How to get subject of gmail letter with curl?

3 votes
1 answer
2382 views
I use curl in my Lua program to get new mail list. I am trying to send request like this
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 )
But only I get is
* 86 FETCH (BODY[HEADER.FIELDS (SUBJECT)] {54}
And I get response like this for any FETCH command. I can get message HEADER if specify UID in url directly like
imaps://%s:%s/INBOX;UID=86/;SECTION=HEADER
It outputs this
Delivered-To: bugaev.nsu@gmail.com

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: 
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
  (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 bugaevamv@mail.ru 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
 bugaevamv@mail.ru designates 217.69.140.238 as permitted sender)
 smtp.mail=bugaevamv@mail.ru; dkim=pass header.i=@mail.ru; 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 ) id 1Yx40N-0001gA-0m for
 bugaev.nsu@gmail.com; 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?= 
To: =?UTF-8?B?0JrQuNGA0LjQu9C7INCR0YPQs9Cw0LXQsg==?= 
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?= 
X-Priority: 3 (Normal)
Message-ID: 
Content-Type: multipart/alternative;
 boundary="--ALT--rUEeoQugXy3WMzk9UAxdG7pumUrVItQl1432605006"
X-Mras: Ok
X-Spam: undefined
But how can I get message SUBJECT this way?
Asked by Kirill Bugaev (151 rep)
Aug 20, 2019, 06:22 AM
Last activity: Jun 15, 2024, 07:07 AM