Name
imap_get — get messages from a IMAP4 mail server.
Synopsis
array
imap_get
(
|
in host varchar , |
in user varchar , | |
in password varchar , | |
in command varchar , | |
in folder_id varchar , | |
in list vector , | |
in
use_ssl
integer
) ; |
Description
imap_get
is used used to work with mail server
running the IMAP4 version 4rev1 as defined in rfc3501.
Parameters
host
The host to connect with. IP address or hostname:port. There is no default for port, so to connect to the standard port for IMAP, use <hostname/IP address>:143
user
string user id in remote host.
password
string password in remote host.
command
Command string . Valid values are ' list ', 'delete ', 'create ', 'select ', 'expunge ', 'rename ', 'fetch ', ' message_delete ', ' message_copy '.
folder_id
IMAP4 mail box ID (e.g. 'INBOX', 'Draft' and etc) to work with.
list
A list of items to work with, depends on the command.
use_ssl
Use SSL connection, 1 - use, 0 - do not use.
Return Types
Depends on the command value:
-
list : - list of mail boxes in selected mail box (needs folder_id, if folder_id = '' work with root of mail account). list - empty vector.
Returns: A vector of strings containing name attributes, hierarchy delimiter, name of mailbox or empty vector.
See more specification details .
Example
SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','list','INBOX', vector (), 1); imap_get VARCHAR _______________________________________________________________________________ vector(0x00491f08) 1 Rows. -- 2090 msec. SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','list','INBOX', vector (), 1)[0]; aref VARCHAR _______________________________________________________________________________ (\HasNoChildren) "/" "INBOX" 1 Rows. -- 1997 msec.
-
delete : deletes the selected mail box (needs folder_id). list - empty vector.
Returns: Empty vector.
See more specification details .
Example
SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','delete','SomeBox', vector (), 1); imap_get VARCHAR _______________________________________________________________________________ vector() 1 Rows. -- 2090 msec.
-
create : creates a new mail box in the selected mail box (needs folder_id). list - empty vector.
Returns: Empty vector.
See more specification details .
Example
SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','create','INBOX/SomeBox', vector (), 1); imap_get VARCHAR _______________________________________________________________________________ vector() 1 Rows. -- 2090 msec.
-
select : lists all messages in the selected mail box (needs folder_id). list - empty vector.
This command gets the header fields of messages:
UID FLAGS INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS (DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL)]
Returns: A vector of vectors containing: UID, header fields and data separated by ' ', Data of BODY.PEEK information (the last requested parameter - BODY.PEEK[HEADER.FIELDS (DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL)]).
Example
SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','select', 'INBOX', vector (), 1); imap_get VARCHAR _______________________________________________________________________________ vector(0x004435a0) 1 Rows. -- 2293 msec. SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','select', 'INBOX', vector (), 1)[0]; aref VARCHAR _______________________________________________________________________________ vector(139,0x00443d50,0x00494758) 1 Rows. -- 2293 msec. SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','select', 'INBOX', vector (), 1)[0][1]; aref VARCHAR _______________________________________________________________________________ RFC822.SIZE 89126 INTERNALDATE "09-Nov-2011 22:47:59 +0000" FLAGS (NonJunk \Seen) BODY[HEADER.FIELDS (DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL)] {368} 1 Rows. -- 2230 msec. SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','select', 'INBOX', vector (), 1)[0][2]; aref VARCHAR _______________________________________________________________________________ Message-ID: <4EBB0319.1050200@openlinksw.com> Date: Wed, 09 Nov 2011 23:47:53 +0100 From: demo <demo@openlinksw.com> To: "ods.check@gmail.com" <ods.check@gmail.com> Subject: test from OL account with attached image Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha1; boundary="------------ms000205010302050500060406" 1 Rows. -- 2200 msec.
-
expunge : expunges (deletes messages marked for deletion) the selected mail box (needs folder_id). list - empty vector.
Returns: An empty vector.
Example
SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','expunge', 'INBOX', vector (), 1); imap_get VARCHAR _______________________________________________________________________________ vector() 1 Rows. -- 3541 msec.
-
rename : renames selected mail box. folder_id is not used, folder_id = ''. list - vector of 2 names: old and new.
Returns: Empty vector.
See more specification details .
Example
SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','rename', '', vector ('Travel', 'New Travel'), 1); imap_get VARCHAR _______________________________________________________________________________ vector() 1 Rows. -- 2013 msec.
-
fetch : fetches messages from the selected mail box (needs folder_id). folder_id is id of selected mail box, list - vector of UIDs of messages.
Returns: A vector of vectors containing: UID and data of BODY.PEEK[] information (full message data).
Example Get the list and UIDs of messages:
SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','select', 'INBOX', vector (), 1)[0]; aref VARCHAR _______________________________________________________________________________ vector(139,0x00443d50,0x00494758) 1 Rows. -- 2215 msec.
Then get full data of message by its mail box id and UID:
SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','fetch', 'INBOX', vector (139), 1); imap_get VARCHAR _______________________________________________________________________________ vector(0x00442410) 1 Rows. -- 3807 msec. SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','fetch', 'INBOX', vector (139), 1) [0][1]; aref VARCHAR _______________________________________________________________________________ Warning 01004: [OpenLink][Virtuoso ODBC Driver]CL077: Data truncated in column 1 of the result-setr(aref, type 242) at line 1 of Top-Level: select imap_get ('imap.gmail.com:993','ods.check','openlink','fetch', 'INBOX', vector (139), 1)[0][1] Delivered-To: ods.check@gmail.com Received: by 43.18.75.3 with SMTP id um9cs133471icb; Wed, 9 Nov 2011 14:48:00 -0800 (PST) Received: by 101.43.13.258 with SMTP id d19mr8062565vdh.48.1320878879524; Wed, 09 Nov 2011 14:47:59 -0800 (PST) Return-Path: <demo@openlinksw.com> Received: from mail.openlinksw.com (mail.openlinksw.com. [25.138.12.16])by mx.google.com with ESMTPS id pm6si1474987vcb.111.2013.04.12.81.63.84 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 Nov 2011 14:47:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of demo@openlinksw.com designates 81.134.67.27 as permitted sender) client-ip=25.138.12.16; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of demo@openlinksw.com designates 25.138.12.16 as permitted sender) smtp.mail=demo@openlinksw.com Received: from example.com ([152.114.12.11] helo=[152.114.12.146]) by mail.openlinksw.com with esmtp (Exim 4.74) (envelope-from <demo@openlinksw.com>) id 1ROGw0-0004Oj-5a for ods.check@gmail.com; Wed, 09 Nov 2011 17:47:58 -0500 Message-ID: <4EBB0319.1050200@openlinksw.com> Date: Wed, 09 Nov 2011 23:47:53 +0100 From: demo <demo@openlinksw.com> User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: "ods.check@gmail.com" <ods.check@gmail.com> Subject: test from OL account with attached image Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha1; boundary="------------ms000205010302050500060406" This is a cryptographically signed message in MIME format. --------------ms000205010302050500060406 Content-Type: multipart/mixed; boundary="------------080604090408010101040005" This is a multi-part message in MIME format. --------------080604090408010101040005 Content-Type: multipart/alternative; boundary="------------060001020305030405060601" --------------060001020305030405060601 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable *simple test* --------------060001020305030405060601 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <html> <head> <meta http-equiv=3D"content-type" content=3D"text/html; charset=3DISO=-8859-1"> </head> <body bgcolor=3D"#FFFFFF" text=3D"#000000"> <b>simple test</b><br> </body> </html> --------------060001020305030405060601-- --------------080604090408010101040005 Content-Type: image/png; name="a1.png" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="a1.png" iVBORw0KGgoAAAANSUhEUgAAAyAAAAFNCA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pwRBjh2l8RAIAAcAY37KzJGHZdSqCJSlK4Y7t rRukrdpWxKlXh3JWx9CD4bhhx6jYuGWHdKg80gbCkR0lFQDw3YbtdSju/TegaPqGjTuCkYzt BQkkDtOe6CAiEIrsPKDKVFRt88btR7Zt/mtFIeL0n89AHUTVA2s378ht0jxuURfXlSjOP4Mk I8vhlLKfthYBqyvDqTU98PPW/J 1 Rows. -- 3338 msec.
-
message_delete : deletes messages from mail box (needs folder_id). folder_id is id of selected mail box, list - vector of UIDs of messages.
Returns: empty vector.
Example
SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','message_delete', 'INBOX', vector(139), 1); imap_get VARCHAR _______________________________________________________________________________ vector() 1 Rows. -- 2262 msec.
-
message_copy : copies messages from select mail box to another. folder_id is id of selected mail box, list - vector of: first vector item is an id of target mail box, and UIDs of messages.
Returns: empty vector.
Example
SQL> select imap_get ('imap.gmail.com:993','ods.check','openlink','message_copy', 'INBOX', vector('Travel', 139), 1); imap_get VARCHAR _______________________________________________________________________________ vector() 1 Rows. -- 2262 msec.
Errors
Table 24.62. Errors signalled by all commands
SQLState | Error Code | Error Text | Description |
---|---|---|---|
IM001 | Cannot resolve host in imap_get | ||
IM002 | Cannot connect in imap_get | ||
IM003 | No response from remote IMAP server | ||
IM004 | Could not login to remote IMAP server. Please check user or password parameters. | ||
IM005 | CAPABILITY command to remote IMAP server failed | ||
IM010 | Failed reading output of LIST command on remote IMAP server | ||
IM007 | Cannot resolve host in imap_get | ||
IM008 | Cannot resolve host in imap_get |
Table 24.63. Errors signalled by command "delete":
SQLState | Error Code | Error Text | Description |
---|---|---|---|
IM011 | There must be folder name to delete (5th argument) | ||
IM012 | DELETE command to remote IMAP server failed |
Table 24.64. Errors signalled by command "create":
SQLState | Error Code | Error Text | Description |
---|---|---|---|
IM015 | There must be folder name to create (5th argument) | ||
IM016 | CREATE command to remote IMAP server failed |
Table 24.65. Errors signalled by command "select":
SQLState | Error Code | Error Text | Description |
---|---|---|---|
IM019 | SELECT command to remote IMAP server failed | ||
IM027 | Failed reading output of FETCH command on remote IMAP server |
Table 24.66. Errors signalled by command "expunge":
SQLState | Error Code | Error Text | Description |
---|---|---|---|
IM020 | EXPUNGE command to remote IMAP server failed |
Table 24.67. Errors signalled by command "rename":
SQLState | Error Code | Error Text | Description |
---|---|---|---|
IM028 | There must be 2 string items in vector of argument 6 (old folder name to rename and a new name) | ||
IM029 | There must be 2 string items in vector of argument 6 (old folder name to rename and a new name) | ||
IM030 | command to remote IMAP server failed |
Table 24.68. Errors signalled by command "fetch":
SQLState | Error Code | Error Text | Description |
---|---|---|---|
IM032 | SELECT command to remote IMAP server failed | ||
IM033 | No messages in list | ||
IM034 | There must be integer items in vector of argument 6 |
Table 24.69. Errors signalled by command "delete":
SQLState | Error Code | Error Text | Description |
---|---|---|---|
IM035 | Error in IMAP command UID STORE |
Table 24.70. Errors signalled by incorrect command value:
SQLState | Error Code | Error Text | Description |
---|---|---|---|
IM042 | No such command (5th parameter) in protocol |