IMAP: Return several headers in one command - email

I am new to IMAP commands, but I know that in IMAP you can use this command to get header of a message:
fetch Message_Id (RFC822.HEADER)
or
fetch Message_Id:* (body[header.fields (from to subject date)])
where Message_Id is the message id like: 1, 2, 3 ...
so i need a command that gets the headers of all messages in a selected folder with only one command, that I receive a list of headers, something like this:
fetch * (RFC822.HEADER)
or
fetch *:* (body[header.fields (from to subject date)])
is that possible? is there such a command?

: is for a range. So 1:3 means messages from 1 to 3.
* does not mean "every message", it means "the last message", whatever that may be.
So, the range you want is simply 1:*, from message 1 until the last message.

Related

download only the new content in email reply by google gmail api

I am trying to access Gmail messages via google API.
https://developers.google.com/gmail/api/v1/reference/users/threads
But the payload field returns the base64 of the body of the email. When an email is in a thread, it is usually to reply to a previous email. Therefore only the reply part is useful to show. The reply part can be shown by the GUI interface. Is there a way to get only the reply part via the API?
Unfortunately, there's no direct method of obtaining the last reply for each thread.
If you want to retrieve the last reply of the email threads you should first of all retrieve all the messages by using a GET request like this:
GET https://www.googleapis.com/gmail/v1/users/userId/messages
The request response will look something like this:
{
"messages": [
users.messages Resource
],
"nextPageToken": string,
"resultSizeEstimate": unsigned integer
}
Where the users.messages Resource looks something like this:
{
"id": "",
"threadId": ""
}
Having the list of all the users.messages Resources, the ones which contain the same threadId are the emails which in fact contain replies.
So in order to obtain the last reply, you could find which threadIds appear more than once, and then retrieve the last occurrence of it as it is the last reply. Or if you want all the replies (apart from the original email), you can retrieve all the occurrences apart from the first one (which is represented by the original email).
Lastly, to retrieve the message you can use a GET request like this:
GET https://www.googleapis.com/gmail/v1/users/userId/messages/id
Note: The userId is represented by the email address from which you want to retrieve the emails/replies and the id is represented by the id of the message.
Reference
Users.threads: list;
Users.threads: get;
Users.messages: list;
Users.messages: get.

FIX response with this error: Value is incorrect (out of range) for this tag

When I send the order request on the FIX server as :
8=FIXT.1.1|9=179|35=D|34=34|49=135|52=20200206-04:52:04.406|56=PSE|1=11101401117577|11=1580964724079|38=1000|40=2|44=10.5|54=1|55=AGI|59=0|60=20200206-12:52:04.406|453=1|448=13501100|447=C|452=12|10=009|)
The response that I receive is:
8=FIXT.1.1|9=000362|35=8|49=PSE|56=135|34=34|57=13501100|52=20200206-04:52:04.533|37=NONE|11=1580964724079|453=4|448=13501999|447=C|452=11|448=13501999|447=C|452=36|448=13501100|447=C|452=12|448=135|447=C|452=1|17=1904|150=8|39=8|103=99|1=11101401117577|55=AGI|54=1|38=1000|44=10.5|59=0|528=F|151=0|14=0|60=20200206-04:52:04.356|58=(293): **Orders are not being accepted at this time|10=020|)**
With the PSE error as:
<20200206-04:52:04, FIXT.1.1:135->PSE, error> (Rejecting invalid message: quickfix.IncorrectTagValue: Value is incorrect (out of range) for this tag, field=528 field=528: 8=FIXT.1.1|9=362|35=8|34=34|49=PSE|52=20200206-04:52:04.533|56=135|57=13501100|1=11101401117577|11=1580964724079|14=0|17=1904|37=NONE|38=1000|39=8|44=10.5|54=1|55=AGI|58=(293): Orders are not being accepted at this time|59=0|60=20200206-04:52:04.356|103=99|150=8|151=0|528=F|453=4|448=13501999|447=C|452=11|448=13501999|447=C|452=36|448=13501100|447=C|452=12|448=135|447=C|452=1|10=132|)
<20200206-04:52:04, FIXT.1.1:135->PSE, error> **(Reject sent for Message 34: Value is incorrect (out of range) for this tag**, field=528:528)
According to the documentary the value for 1 should be 14 digit trading account(1=xxxxxxxxxxxxxx) but when I give that, then I had receive the above error.So what value should be given for 1 so the response should be receive.
So what is the solution for this error?
The flow is as follows:
you send a NewOrderSingle
they reply with an ExecutionReport that they don't accept orders at that time
you (and not PSE) reject that ExecutionReport because tag 528 on the ExecutionReport that PSE sent contains a value that is not contained in your data dictionary.
What you need to do is either of
Read PSE's rules of engagement (i.e. their FIX spec) and add all needed tags and values to your data dictionary.
Configure your session to not validate incoming messages (setting ValidateIncomingMessage=N) but this means you would need to do validation by yourself if required. E.g. if you wanted to retrieve values from tag 150/ExecType then you can be sure that only values which are allowed in the data dictionary reach your application. With disabled validation you would need to do these checks by yourself.
Alternatively you could set RejectInvalidMessage=N which also will not reject the message but only log the warning with the validation error.

IMAP UID FETCH BODY.PEEK[] command response

I'm now developing a simple IMAP-client. To recieve message body I'm using command "UID FETCH message-UID BODY.PEEK[]". The question is can I be sure that one of the server responses on the command will be "* message-sequence-number FETCH (UID message-UID BODY[] message-body)"? Or should I be ready to recieve any possible FETCH response (like with message envelope)? I know that I can recieve message flag updates in form of "* message-sequence-number FETCH (FLAGS flags)", I just ignore it now.
Of cause, I've read the standard rfc3501, but did not find out the answer.
You can't be sure that the message exists. But if it does exist, then the server has to send you a FETCH that includes both UID and BODY[], usually but not necessarily in that order. In practice it may also include FLAGS but nothing else.

Intersystems Cache script character limit

what's the character limit (number of characters) which send command has and how can I change it?
If I run a long command , it's not getting send completely and an "S" is appended to the end of the string (and string is cut off)
so is there a way to change/see how many characters we can send?
script:
send: Set tSql="SELECT count(*) AS cc FROM table WHERE id IN
('1111111111','1111111112','1111111113','1111111114','1111111115','1111111116','1111111117','1111111118','1111111119','1111111120','1111111121','1111111122','1111111123','1111111124','1111111125','1111111126','1111111127','1111111128','1111111129','1111111130','1111111131','1111111132','1111111133')"
here's what I get in cache terminal:
Set tSql="SELECT count(*) AS cc FROM table WHERE id IN
('1111111111','1111111112','1111111113','1111111114','1111111115','1111111116','1111111117','1111111118','1111111119','1111111120','1111111121','1111111122','1111111123','1111111124','1111111125','1111111126','1111111127','1111111128','1111111129','1111111130','111S
As you see there's an S appended to the commmand which finally will result into syntax error
The cleaner approach would be to create a class with methods, containing the implementations of whatever you want to achieve and then calling it via:
send: Do ##class*Package.Class).Method(Arguments)
and passing required parameters.
Not sure how it limited, but I can say that, you can split any of your long data by multiple send. And it will looks like below
send: Set tSql="SELECT count(*) AS cc FROM table WHERE id IN
send: ('1111111111','1111111112','1111111113','1111111114','1111111115',
send: '1111111116','1111111117','1111111118','1111111119','1111111120',
send: '1111111121','1111111122','1111111123','1111111124','1111111125',
send: '1111111126','1111111127','1111111128','1111111129','1111111130',
send: '1111111131','1111111132','1111111133')"

FIX server rejecting message saying there is a body length error?

I'm sending a new order message (message type 'D') to my FIX server and it's getting kicked back from 'pre-validation' on the server with the response that the stated message body length does not match the actual message.
In a text editor it appears that the declared body length DOES match the message length (measured between the bodylength tag value, and the delimiter preceding the checksum)
Below is the message I am sending (with sensitive data replaced with an equal number of 'x' characters):
8=FIX.4.4^9=183^35=D^34=2^49=xxxxxxxxxxx^52=20130927-19:57:35.771^56=xxx^1=xxxxxxxx^11=123^21=1^38=10^40=1^52=20130927-19:57:35.770^54=1^55=MSFT^59=1^60=20130927-19:57:35.771^100=xxxx^553=xxxxxxxxxx^10=234^
Here is the Business Reject Message (type 'j') that I immediately get back:
8=FIX.4.4^9=126^35=j^49=xxx^56=xxxxxxxxxxx^34=3^52=20130927-16:09:05.888^43=N^372=D^58=PreValidate Failed body lengh problem^380=4^379=2^45=0^10=007^
(the typo is theirs, not mine)
Here is the code used to build the message:
message = fix.Message()
header = message.getHeader()
header.setField(fix.BeginString('FIX.4.4'))
header.setField(fix.SenderCompID('xxxxxxxxxxx'))
header.setField(fix.TargetCompID('xxx'))
header.setField(fix.MsgType('D'))
message.setField(fix.Account(DEMO_Account_Number))
message.setField(fix.HandlInst('1')) #only valid value is '1'
message.setField(fix.OrderQty(int(Test_Order_Qty)))
message.setField(fix.OrdType('1')) #1=Market, 2=Limit, 3=Stop,4=StopLimit, P=TrailingStop, T=TTO
message.setField(fix.SendingTime(1))
message.setField(fix.Side('1')) #1=Buy, 2=Sell, 5=Sell Short, and 6=Sell Short Exempt.
message.setField(fix.Symbol('MSFT'))
message.setField(fix.TimeInForce('1')) # 0 = Day , 1 = GTC.................
message.setField(fix.TransactTime(1))
message.setField(fix.ExDestination('xxxx'))
message.setField(fix.Username(UserName))
fix.Session_sendToTarget(message)
What might be going wrong here? Why is the server kicking it back?
Thanks.