I'm getting an ImapProtocolException with a message:
"Unexpected token in IMAP response: [qstring: "Multipart message"]" when issuing zInbox.Fetch(uids, MailKit.MessageSummaryItems.UniqueId Or MailKit.MessageSummaryItems.BodyStructure Or MailKit.MessageSummaryItems.Envelope)
But on the other hand if I use GetMessage(uids) all goes fine, no error.
Here is ProtocolLogger from Fetch (you can notice no Fetch Completed message):
C: A00000790 UID FETCH 97824 (UID ENVELOPE BODYSTRUCTURE)
S: * 24320 FETCH (UID 97824 ENVELOPE ("Mon, 26 Oct 2015 16:48:44 +0000" "NFe" ((NIL NIL "fatsc" "makrocentral.com.br")) NIL NIL ((NIL NIL "fiscal" "generale.ind.br")) NIL NIL NIL "<20151026164845.43268801F3AD#mail-smtp08-mia.tpn.terra.com>") BODYSTRUCTURE (("text" "plain" ("charset" "ISO-8859-1") NIL "Message text" "Quoted-printable" 227 8 NIL ("inline" NIL) NIL NIL)("application" "octet-stream" ("name" "42151000460986000506550040000387401000387404-nfe.xml") NIL "Attached file: 42151000460986000506550040000387401000387404-nfe.xml" "Base64" 11086 NIL ("attachment" ("filename" "42151000460986000506550040000387401000387404-nfe.xml")) NIL NIL)("application" "pdf" ("name" "42151000460986000506550040000387401000387404-nfe.pdf") NIL "Attached file: 42151000460986000506550040000387401000387404-nfe.pdf" "Base64" 50364 NIL ("attachment" ("filename" "42151000460986000506550040000387401000387404-nfe.pdf")) NIL NIL) "mixed" ("boundary" "017AC96C_005ED075_Synapse_boundary") "Multipart message" NIL))
When using GetMessage(uids), Protocologger give me an interesting info:
S: X-mailer: Synapse - Pascal TCP/IP library by Lukas Gebauer
I already have problems with this mailer when using another library.
As I understand "Fetch" belongs to MailKit and "GetMessage" belongs to MimeKit.
So, is there any work-around to proceed with Fetch instead of use GetMessage?
Loop through ~1500 mails and download each one just to get attachments names take a very long time?
Does anybody here had a similar problems with mailer like this one "Synapse - Pascal TCP/IP library by Lukas Gebauer"?
So I think now have some more info and questions. Since started this thread I'm dealing with BODYSTRUCTURE and not so much clear (at least to me) RFC 3501.
I have back to talk about "Synapse" again, here is string from Log, the that give me Unexpected Token.
S: * 22300 FETCH (UID 32388 ENVELOPE ("Thu, 6 Sep 2018 13:19:10 -0300" "Zebra - XML sent" (("Zebra" NIL "invoice" "zebra.com")) NIL NIL ((NIL NIL "payments" "cat.com")) ((NIL NIL "invoice" "zebra.com") (NIL NIL "mary" "zebra.com")(NIL NIL "igor" "zebra.com")) NIL NIL "<20180906161753.3F4A774030A#proxy.tiger.com>") BODYSTRUCTURE (("text" "plain" ("charset" "UTF-8") NIL "Message text" "Quoted-printable" 209 6 NIL ("inline" NIL) NIL NIL)("text" "xml" ("name" "4441004299066.xml") NIL "4441004299066.xml" "Base64" 10642 137 NIL ("inline" ("filename" "4441004299066.xml")) NIL NIL)("application" "pdf" ("name" "4441004299066.pdf") NIL "4441004299066.pdf" "Base64" 48448 NIL ("inline" ("filename" "4441004299066.pdf")) NIL NIL) "mixed" ("boundary" "6624CFB2_17170C36_Synapse_boundary") "Multipart message" NIL))
As pointed in comments, the problem is at the end part "Multipart message" NIL, on the other hand a BodyStructure that works fine can end with "NIL NIL" or **"NIL pt-br".
So, ok, now the question is. What should be the last 2 fields in BodyStructure string?
In mean time I found this:
1) "Multipart message" is coming from "Content-Description" of message header
2) "pt-br" is coming from "Content-Language" of message header
I totally agree to follow RFC, but looks like the last 2 values are not clear from where they should came from.
I mean Content-Language or Language-Tag? Content-Disposition or Content-Description?
Since Exchanges Server and outlook,office365.com become widely used, to me sounds I have to stay using GetMessage and forget about Fetch.
The problem is that the IMAP server responded with a completely broken response.
According to the IMAP specification, the multipart syntax following the "mixed" token should be:
body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang
[SP body-fld-loc *(SP body-extension)]]]
; MUST NOT be returned on non-extensible
; "BODY" fetch
body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
body-fld-dsp = "(" string SP body-fld-param ")" / nil
body-fld-lang = nstring / "(" string *(SP string) ")"
body-fld-loc = nstring
but what we got was: ("boundary" "017AC96C_005ED075_Synapse_boundary") "Multipart message" NIL)
This essentially breaks down into the following types of tokens:
body-fld-param [SP] string [SP] nil
Notice how "Multipart message" is not allowed. What should be there is either a NIL or something like: ("inline" ("name" "value"))
In other words, your IMAP server is not speaking grammatically correct IMAP. There's no way that MailKit can understand what your IMAP server is trying to say.
Note: the problem is the IMAP server, not the Synapse Mailer in this case.
Related
I have a code which calls a boolean function.
can_process = done_recently?(load)
Here is how the done_recently function looks.
def done_recently?(load)
time_window = 10000
load['terminatedAt'] && (load['terminatedAt'] > time_window.minutes.ago.utc.iso8601)
end
In my json data, inside
"load": [{ "terminatedAt": null }]
among lots of other data . This json data is converted into a hash before calling these functions.
What will the done_recently? function return(true/false)? I am new to ruby so i am getting a little confused. please help me out.
I have tried replicating in irb but got confused midway because of some errors.
When your input is { "terminatedAt": null } then
def done_recently?(load)
time_window = 10000
load['terminatedAt'] && (load['terminatedAt'] > time_window.minutes.ago.utc.iso8601)
end
will return nil. nil is returned because the first part of load['terminatedAt'] && ... evaluates to nil which is considered falsy and there for the second part after the && will not be evaluated anymore and the nil is returned immediately.
after pressing the "button2" works correctly but after a while lua turns off
error: [Lua] Error in “LUA”: attempt to call a nil value
local webHookURL = Menu.TextBox("Webhook", "Webhook URL", 148, "", "Enter your webhook URL")
local message = ("Hello!")
local function hook(msg)
Http.PostAsync(string.format("%s",webHookURL:GetString()),
string.format("content=%s",msg))
Cheat.AddNotify("neverlose.cc", "Shared! Well done!")
end
button2:RegisterCallback(function()
hook(message)
end)
The error message doesn't indicate at which line the calling is happening?
A trivial workaround is to test it before:
if type(var_that_will_be_called) == "function" then
var_that_will_be_called ()
end
But that doesn't really solve the problem, just avoid the error...
So in my rails form there are several rows of 2 textfields. For the form to save ok, at least one of the pair of textfields needs to be filled out.
So
nil nil
10 20
nil nil
nil nil
is valid.
This:
nil nil
nil nil
nil nil
nil nil
is invalid
This:
nil 10
nil nil
nil nil
nil nil
is invalid
Here is the method I am using to check all the fields (note that single_field and aggregate_field are strings and are the field names):
def no_values_present?(single_field, aggregate_field)
self.lo_item.lo_line_items.each do |item|
return false if "!item.#{single_field}".nil? && "!item.#{aggregate_field}".nil?
end
true
end
But I guess this doesn't work as it will return true or false several times and will determine that a row is invalid even though a previous row may have been valid.
I need an overall true or false.
How can this be achieved?
Try leveraging any? or none? from the Enumerable module.
Your code could be rewritten as
def no_values_present?(single_field, aggregate_field)
self.lo_item.lo_line_items.none? { |item|
!(item.send(single_field).nil?) && !(item.send(aggregate_field).nil?)
}
end
although I think that it would be clearer to have the condition be positive and to return true when there is a match found. I would write
def any_pairs_present?(single_field, aggregate_field)
self.lo_item.lo_line_items.any? { |item|
!(item.send(single_field).nil?) && !(item.send(aggregate_field).nil?)
}
end
Note that "!item.#{single_field}" will never be nil because it will always be a string! If you want to access instance fields dynamically then one way to do that is with send, but for other options you could look here which suggests the alternatives of instance_eval and instance_variable_get.
The function looks ok, but there seems to be syntax errors, I'd also make a few amendments:
def form_valid?(single_field, aggregate_field)
self.lo_item.lo_line_items.each do |item|
return true if !item.send(single_field).nil? && !item.send(aggregate_field)
end
false
end
Trying to work on blockchain-wallet ruby api methods as in doc https://github.com/Tolsi/blockchain-wallet-ruby/blob/master/lib/blockchain/wallet.rb where am stuck with passing Json parameters for payment and sendmany methods.
recipients = {"1H8fsmAgVhUt567I65hGJPkMbnCCy5": "1000000"}
wallet = Blockchain::Wallet.new("b14d36af-2fa6-4d76-91b5-ff70b8370ec7", "n$grJ74hAshfggnb6864%j78##^hChttp://ya.ru#contentpurl", nil)
wallet.sendmany(recipients, from = nil, shared = nil, fee = nil, note = nil)
Got error despite substituting the required,
Invalid Recipients JSON. Please make sure it is url encoded and consult the docs. (WebAPI::WebApiException)
How to solve the problem ?
In the Blockchain::Wallet gem code, I found this:
def build_url(operation_name, params)
#url + operation_name + "?" + params.map { |param, value| "#{param}=#{value}" if value }.join("&")
end
I believe the way it's being built, you will need to transform in JSON and also encode your recipients string:
require 'json'
require 'uri'
recipients = {"1H8fsmAgVhUt567I65hGJPkMbnCCy5" => "1000000"}
wallet = Blockchain::Wallet.new("b14d36af-2fa6-4d76-91b5-ff70b8370ec7", "n$grJ74hAshfggnb6864%j78##^hChttp://ya.ru#contentpurl", nil)
wallet.sendmany(URI.encode(JSON.generate(recipients)))
The recipient will be "%7B%221H8fsmAgVhUt567I65hGJPkMbnCCy5%22:%221000000%22%7D".
References:
https://github.com/Tolsi/blockchain-wallet-ruby/blob/master/lib/blockchain/web_api.rb
https://blockchain.info/api/blockchain_wallet_api
UPDATE: Try remove the URI.encode if this does not work.
In my rails contoller I have this code:
if Photo.find(params[:photo_id]).patient_id == nil
.........
else
.........
So at the time I get a error when there are no params[:photo_id]:
Couldn't find Photo without an ID
I know that I could fix it with: For example:
if(params[:photo_id]) && (Photo.find(params[:photo_id]).patient_id == nil)
But now I tried to write an exception "how its called I think":
if Photo.find(params[:photo_id]).patient_id == nil rescue false
That throws a new error:
syntax error, unexpected modifier_rescue, expecting keyword_then or ';' or '\n' if
So what did a wrong?(I'm beginner in programming!)
You just need some parens.
if (Photo.find(params[:photo_id]).patient_id == nil rescue false)
...
end
The syntax is wrong. Try:
begin
if Photo.find(params[:photo_id]).patient_id == nil
.........
else
.........
rescue
false
end
Photo.find_by_id(params[:photo_id]).try(:patient_id)
Avoid using exceptions for situations that are not exceptional... and by the sounds of it, you're expecting to occasionally to have a Photo that doesn't get found.