IMAPMessage.getRecipients() and IMAPMessage.getAllRecipients() return null - imap

I'm writing an IMAP message poller (to be used from within a business app). I'm able to connect, iterate through the messages in Inbox, read their headers and content but calls to getAllRecipients() and getRecipients(Message.RecipientType.TO) always return null.
Message messages[] = inbox.getMessages();
for (Message message : messages) {
IMAPMessage imapMessage = (IMAPMessage) message;
Address[] toRecipients = imapMessage.getRecipients(Message.RecipientType.TO);
Address[] allRecipients = imapMessage.getAllRecipients();
This is puzzling. The messages in the Inbox have been sent with regular mail clients so there is nothing unusual with them.
The IMAP server is running Dovecot.
* OK Dovecot ready.
A0 CAPABILITY
* CAPABILITY IMAP4rev1 SASL-IR SORT THREAD=REFERENCES MULTIAPPEND UNSELECT LITERAL+ IDLE CHILDREN NAMESPACE LOGIN-REFERRALS STARTTLS AUTH=PLAIN
A0 OK Capability completed.
This is the relevant traffic dump captured with Wireshark while doing the above (and also calling imapMessage.getContent()).
A3 SELECT Inbox
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 2 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1277135188] UIDs valid
* OK [UIDNEXT 3] Predicted next UID
A3 OK [READ-WRITE] Select completed.
A4 FETCH 1 (BODYSTRUCTURE)
* 1 FETCH (BODYSTRUCTURE ("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 12 1 NIL NIL NIL))
A4 OK Fetch completed.
A5 FETCH 1 (BODY[TEXT]<0.12>)
* 1 FETCH (BODY[TEXT]<0> {12}
here it is
)
A5 OK Fetch completed.
A6 FETCH 1 (FLAGS)
* 1 FETCH (FLAGS (\Seen))
A6 OK Fetch completed.
A7 FETCH 1 (BODY.PEEK[HEADER])
* 1 FETCH (BODY[HEADER] {399}
Return-Path: <EDITED>
Received: from EDITED; Sat, 5 Jun 2010 15:33:13 -0400
Date: Sat, 5 Jun 2010 15:32:40 -0400
From: EDITED
Message-Id: <EDITED>
Subject: Test Message
Lines: 1
)
A7 OK Fetch completed.
A8 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 1 FETCH (INTERNALDATE "05-Jun-2010 15:33:32 -0400" RFC822.SIZE 411 ENVELOPE ("Sat, 5 Jun 2010 15:32:40 -0400" "Test Message" ((NIL NIL "myediteduser" "myediteddomain")) ((NIL NIL "myediteduser" "myediteddomain")) ((NIL NIL "myediteduser" "myediteddomain")) NIL NIL NIL NIL "<EDITED>"))
A8 OK Fetch completed.
A9 FETCH 2 (BODYSTRUCTURE)
* 2 FETCH (BODYSTRUCTURE (("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 8 0 NIL NIL NIL)("text" "html" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 341 9 NIL NIL NIL) "alternative" ("boundary" "----=_NextPart_000_0003_01CB1137.CCF78C80") NIL NIL))
A9 OK Fetch completed.
Any hints are appreciated. I don't know if there is anything else I should be calling or if there is a setting in the IMAP server. I've looked at all methods of the IMAPMessage in case there was something to run before calling getRecipients() and getAllRecipients() but there was nothing. Also googled for a while and found nothing else I should have called.

Just to close it: this was an issue with the mail server setup and it's now fixed.

Related

Inner join return duplicated record

My table:
Report_Period
Entity
Tag
Users Count
Report_Period_M-1
Report_Period_Q-1
...
2017-06-30
entity 1
X
471
2017-05-31
2017-03-31
...
2020-12-31
entity 2
A
135
2020-11-30
2020-09-30
...
2020-11-30
entity 3
X
402
2020-10-31
2020-08-31
...
What I want:
Report_Period
Entity
Tag
Users Count
Users_Count_M-1
Users_Count_Q-1
...
2017-06-30
entity 1
X
471
450
438
...
2020-12-31
entity 2
A
135
122
118
...
2020-11-30
entity 3
X
402
380
380
...
I have have tried this code but it duplicate records! How can I avoid it?
SELECT M."Entity",M."Tag",M."Report_Period",M."Users Count",
M."Report_Period_M-1",M1."Users Count" AS "Users Count M1",
FROM "DB"."SCHEMA"."PERIOD" M, "DB"."SCHEMA"."PERIOD" M1
WHERE M."Report_Period_M-1"= M1."Report_Period"
Your join clause should include the entity column and tag (I suspect)
SELECT M."Entity",
M."Tag",
M."Report_Period",
M."Users Count",
M."Report_Period_M-1",
M1."Users Count" AS "Users Count M1",
FROM "DB"."SCHEMA"."PERIOD" M,
"DB"."SCHEMA"."PERIOD" M1
WHERE M."Report_Period_M-1"= M1."Report_Period"
AND M."Entity" = M1."Entity"
AND M."Tag" = M1."Tag"

Reading UIDs of NFC Cards in iOS 13

I would like to retrive the UID of MiFare cards. I'm using an iPhone X, Xcode 11 and iOS 13.
I'm aware this wasn't possible (specifically reading the UID) until iOS 13 according to this website: https://gototags.com/blog/apple-expands-nfc-on-iphone-in-ios-13/ and this guy: https://www.reddit.com/r/apple/comments/c0gzf0/clearing_up_misunderstandings_and/
The phones NFC reader is correctly detecting the card however the unique identifier is always returned as empty or nil. I can read the payload however and irrelvant to iOS but I can do this in Android (confirms the card isn't faulty or just odd)
Apple Sample Project: https://developer.apple.com/documentation/corenfc/building_an_nfc_tag-reader_app
func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
if case let NFCTag.miFare(tag) = tags.first! {
session.connect(to: tags.first!) { (error: Error?) in
let apdu = NFCISO7816APDU(instructionClass: 0, instructionCode: 0xB0, p1Parameter: 0, p2Parameter: 0, data: Data(), expectedResponseLength: 16)
tag.queryNDEFStatus(completionHandler: {(status: NFCNDEFStatus, e: Int, error: Error?) in
debugPrint("\(status) \(e) \(error)")
})
tag.sendMiFareISO7816Command(apdu) { (data, sw1, sw2, error) in
debugPrint(data)
debugPrint(error)
debugPrint(tag.identifier)
debugPrint(String(data: tag.identifier, encoding: .utf8))
}
}
}
}
I'm aware these sorts of hacks: CoreNFC not reading UID in iOS
But they are closed and only apply to iOS 11 for a short time in the past.
Ok I have an answer.
tag.identifier isn't empty -- per se -- if you examine from Xcodes debugger it appears empty (0x00 is the value!). It's type is Data and printing it will reveal the length of the Data but not how it's encoded. In this case it's a [UInt8] but stored as a bag of bits, I don't understand why Apple have done it this way -- it's clunky -- I'm sure they have good reasons. I would have stored it as a type String -- after all the whole point of a high level language like Swift is to abstract us away from such hadware implementation details.
The following code will retrive the UID from a MiFare card:
if case let NFCTag.miFare(tag) = tags.first! {
session.connect(to: tags.first!) { (error: Error?) in
let apdu = NFCISO7816APDU(instructionClass: 0, instructionCode: 0xB0, p1Parameter: 0, p2Parameter: 0, data: Data(), expectedResponseLength: 16)
tag.sendMiFareISO7816Command(apdu) { (apduData, sw1, sw2, error) in
let tagUIDData = tag.identifier
var byteData: [UInt8] = []
tagUIDData.withUnsafeBytes { byteData.append(contentsOf: $0) }
var uidString = ""
for byte in byteData {
let decimalNumber = String(byte, radix: 16)
if (Int(decimalNumber) ?? 0) < 10 { // add leading zero
uidString.append("0\(decimalNumber)")
} else {
uidString.append(decimalNumber)
}
}
debugPrint("\(byteData) converted to Tag UID: \(uidString)")
}
}
}
I know you have said that it returns nil but for clarity for future readers:
Assuming it is not a Felica tag, it should be on the identifier field when it is detected:
func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
if case let NFCTag.miFare(tag) = tags.first! {
print(tag.identifier as NSData)
}
}
But in your case, it's empty (see edit below). For most tags the APDU to get the UID of a tag is
0xff // Class
0xca // INS
0x00 // P1
0x00 // P2
0x00 // Le
so you could try using tag.sendMiFareCommand to send that command manually.
Edit: Response from OP, it wasn't empty but was unclear because printing Data in Swift doesn't show in console
In iOS13 I was able read the Tag.identifier value for various MIFARE family's DESfire and UltraLight tags same as #scott-condron's answer, but for various MIFARE Classic ICs (the unknown family member?) my Console shows different error types.
Perhaps private framework APIs similar to the iOS11 work-around in the hack you mentioned would be helpful in these cases, e.g. to intercept and amend the discovery polling routine, but I wouldn't know which ones or how to use them.
Below you can find some test results for MIFARE Classic 4K (emulation) tags, as also reported in this github thread and this MIFARE support thread. Following Table 6 of Application Note #10833, the Select Acknowledge (SAK) value of 0x38 of the emulation tags below translates into 0 0 1 1 1 0 0 0 for bits 8..1, i.e. bits 6, 5, and 4 are 1, and therefore these SAK values classify as Smart MX with CLASSIC 4K as per Figure 3 of Application Note #10834.
an Infineon Classic 4k Emulation successfully logs 1 tags found with the correct UID (31:9A:2F:88), ATQA (0x0200), SAK (detects 0x20, i.e. ISO 14443-4 protocol, and 0x18, i.e. MIFARE 4K, both part of the expected value: 0x38) and respective tag type (both Generic 4A and MiFare classified correctly), but then throws a Stack Error:
error 14:48:08.675369 +0200 nfcd 00000001 04e04390 -
[NFDriverWrapper connectTag:]:1436 Failed to connect to tag:
<NFTagInternal: 0x104e05cd0>-{length = 8, bytes = 0x7bad030077180efa}
{ Tech=A Type=Generic 4A ID={length = 4, bytes = 0x319a2f88}
SAK={length = 1, bytes = 0x20} ATQA={length = 2, bytes = 0x0200} historicalBytes={length = 0, bytes = 0x}}
:
error 14:48:08.682881 +0200 nfcd 00000001 04e04390 -
[NFDriverWrapper connectTag:]:1436 Failed to connect to tag:
<NFTagInternal: 0x104e1d600>-{length = 8, bytes = 0x81ad0300984374f3}
{ Tech=A Type=MiFare ID={length = 4, bytes = 0x319a2f88}
SAK={length = 1, bytes = 0x18} ATQA={length = 2, bytes = 0x0200} historicalBytes={length = 0, bytes = 0x}}
:
default 14:48:08.683150 +0200 nfcd 00000001 04e07470 -
[_NFReaderSession handleRemoteTagsDetected:]:445 1 tags found
default 14:48:08.685792 +0200 nfcd 00000001 04e07470 -
[_NFReaderSession connect:callback:]:507 NFC-Example
:
error 14:48:08.693429 +0200 nfcd 00000001 04e04390 -
[NFDriverWrapper connectTag:]:1436 Failed to connect to tag:
<NFTagInternal: 0x104e05cd0>-{length = 8, bytes = 0x81ad0300984374f3}
{ Tech=A Type=MiFare ID={length = 4, bytes = 0x319a2f88}
SAK=(null) ATQA=(null) historicalBytes={length = 0, bytes = 0x}}
:
error 14:48:08.694019 +0200 NFC-Example 00000002 802e2700 -
[NFCTagReaderSession _connectTag:error:]:568 Error
Domain=NFCError Code=100 "Stack Error" UserInfo={NSLocalizedDescription=Stack Error, NSUnderlyingError=0x2822a86c0
{Error Domain=nfcd Code=15 "Stack Error" UserInfo={NSLocalizedDescription=Stack Error}}}
an NXP SmartMX (Classic 4k emulation) with UID CF:3E:40:04 is discovered initially, but a reception error during ISO 14443-4A presence check (Proc Iso-Dep pres chk ntf: Receiption failed) continuously restarts the discovery polling until the session finally expires, possibly preventing the other SAK value 0x18 (for MIFARE 4K tag type) to be received:
error 10:44:50.650673 +0200 nfcd Proc Iso-Dep pres chk ntf: Receiption failed
:
error 10:44:50.677470 +0200 nfcd 00000001 04e04390 -
[NFDriverWrapper disconnectTag:tagRemovalDetect:]:1448 Failed to disconnect tag:
<NFTagInternal: 0x104f09930>-{length = 8, bytes = 0x07320d00f3041861}
{ Tech=A Type=Generic 4A ID={length = 4, bytes = 0xcf3e4004}
SAK={length = 1, bytes = 0x20} ATQA={length = 2, bytes = 0x0200} historicalBytes={length = 0, bytes = 0x}}
default 10:44:50.677682 +0200 nfcd 00000001 04e04390 -
[NFDriverWrapper restartDiscovery]:1953
an actual NXP Classic 4k with UID 2D:FE:9B:87 remains undetected and throws no error. The discovery polling session for this tag simply times out after 60 seconds and logs the last 128 discovery messages transmitted (Tx) and received (Rx), among which the following pattern is repeated (which does include the expected UID: 2D FE 9B 87):
error 11:42:19.511354 +0200 nfcd 1571305339.350902 Tx '21 03 07 03 FF 01 00 01 01 01 6F 61'
error 11:42:19.511484 +0200 nfcd 1571305339.353416 Rx '41 03 01'
error 11:42:19.511631 +0200 nfcd 1571305339.353486 Rx '00 F6 89'
error 11:42:19.511755 +0200 nfcd 1571305339.362455 Rx '61 05 14'
error 11:42:19.511905 +0200 nfcd 1571305339.362529 Rx '01 80 80 00 FF 01 09 02 00 04 2D FE 9B 87 01 18 00 00 00 00 2D 11'
error 11:42:19.512152 +0200 nfcd 1571305339.362734 Tx '21 06 01 00 44 AB'
error 11:42:19.512323 +0200 nfcd 1571305339.363959 Rx '41 06 01'
error 11:42:19.512489 +0200 nfcd 1571305339.364028 Rx '00 1D 79'
error 11:42:19.512726 +0200 nfcd 1571305339.364300 Rx '61 06 02'
error 11:42:19.512914 +0200 nfcd 1571305339.364347 Rx '00 00 EB 78'

How to join more than 2 regions with Apache Geode?

I've been trying to query some regions and i'm failing to join more than 2 of them. I set that up in a Java test to run them more easily but it fails all the same in pulse.
#Test
public void test_geode_join() throws QueryException {
ClientCache cache = new ClientCacheFactory()
.addPoolLocator(HOST, LOCATOR_PORT)
.setPoolSubscriptionEnabled(true)
.setPdxSerializer(new MyReflectionBasedAutoSerializer())
.create();
{
#SuppressWarnings("unchecked")
SelectResults<StructImpl> r = (SelectResults<StructImpl>) cache.getQueryService()
.newQuery("SELECT itm.itemId, bx.boxId " +
"FROM /items itm, /boxs bx " +
"WHERE itm.boxId = bx.boxId " +
"LIMIT 5")
.execute();
for (StructImpl v : r) {
System.out.println(v);
}
}
{
#SuppressWarnings("unchecked")
SelectResults<StructImpl> r = (SelectResults<StructImpl>) cache.getQueryService()
.newQuery("SELECT bx.boxId, rm.roomId " +
"FROM /boxs bx, /rooms rm " +
"WHERE bx.roomId = rm.roomId " +
"LIMIT 5")
.execute();
for (StructImpl v : r) {
System.out.println(v);
}
}
{
// That fails
#SuppressWarnings("unchecked")
SelectResults<StructImpl> r = (SelectResults<StructImpl>) cache.getQueryService()
.newQuery("SELECT itm.itemId, bx.boxId, rm.roomId " +
"FROM /items itm, /boxs bx, /rooms rm " +
"WHERE itm.boxId = bx.boxId " +
"AND bx.roomId = rm.roomId " +
"LIMIT 5")
.execute();
for (StructImpl v : r) {
System.out.println(v);
}
}
}
The first 2 queries work fine and respond in an instant but the last query holds until it timeouts. I get the following logs
[warn 2018/02/06 17:33:17.155 CET <main> tid=0x1] Pool unexpected socket timed out on client connection=Pooled Connection to hostname:31902: Connection[hostname:31902]#1978504976)
[warn 2018/02/06 17:33:27.333 CET <main> tid=0x1] Pool unexpected socket timed out on client connection=Pooled Connection to hostname2:31902: Connection[hostname2:31902]#1620459733 attempt=2)
[warn 2018/02/06 17:33:37.588 CET <main> tid=0x1] Pool unexpected socket timed out on client connection=Pooled Connection to hostname3:31902: Connection[hostname3:31902]#422409467 attempt=3)
[warn 2018/02/06 17:33:37.825 CET <main> tid=0x1] Pool unexpected socket timed out on client connection=Pooled Connection to hostname3:31902: Connection[hostname3:31902]#422409467 attempt=3). Server unreachable: could not connect after 3 attempts
[info 2018/02/06 17:33:37.840 CET <Distributed system shutdown hook> tid=0xd] VM is exiting - shutting down distributed system
[info 2018/02/06 17:33:37.840 CET <Distributed system shutdown hook> tid=0xd] GemFireCache[id = 1839168128; isClosing = true; isShutDownAll = false; created = Tue Feb 06 17:33:05 CET 2018; server = false; copyOnRead = false; lockLease = 120; lockTimeout = 60]: Now closing.
[info 2018/02/06 17:33:37.887 CET <Distributed system shutdown hook> tid=0xd] Destroying connection pool DEFAULT
And it ends up crashing
org.apache.geode.cache.client.ServerConnectivityException: Pool unexpected socket timed out on client connection=Pooled Connection to hostname3:31902: Connection[hostname3:31902]#422409467 attempt=3). Server unreachable: could not connect after 3 attempts
at org.apache.geode.cache.client.internal.OpExecutorImpl.handleException(OpExecutorImpl.java:798)
at org.apache.geode.cache.client.internal.OpExecutorImpl.handleException(OpExecutorImpl.java:623)
at org.apache.geode.cache.client.internal.OpExecutorImpl.execute(OpExecutorImpl.java:174)
at org.apache.geode.cache.client.internal.OpExecutorImpl.execute(OpExecutorImpl.java:115)
at org.apache.geode.cache.client.internal.PoolImpl.execute(PoolImpl.java:763)
at org.apache.geode.cache.client.internal.QueryOp.execute(QueryOp.java:58)
at org.apache.geode.cache.client.internal.ServerProxy.query(ServerProxy.java:70)
at org.apache.geode.cache.query.internal.DefaultQuery.executeOnServer(DefaultQuery.java:456)
at org.apache.geode.cache.query.internal.DefaultQuery.execute(DefaultQuery.java:338)
at org.apache.geode.cache.query.internal.DefaultQuery.execute(DefaultQuery.java:319)
at local.test.geode.GeodeTest.test_geode_join(GeodeTest.java:226)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
I tried to set timeouts at 60 seconds but i'm still not getting any results.
All regions are configured like this:
Type | Name | Value
------ | --------------- | --------------------
Region | data-policy | PERSISTENT_REPLICATE
| disk-store-name | regionDiskStore1
| size | 1173
| scope | distributed-ack
Am I missing anything here ?
Based on all the information provided, it looks like you are doing everything correct. I tried to reproduce in a simple test (similar test) and the test returns 5 results. However, if one of the predicates did not match, it could cause the query to take a lot longer to join enough rows to find a tuple that matches.
Below is a sample test that does not have an issue, but if I modify the test to put into region3 only portfolios with ID = -1. Then the test "hangs" trying to find 5 rows that fulfill the search criteria (it has to join 1000 * 1000 * 1000 rows which takes awhile to do). In the end the query will not find an p3.ID = p1.ID. Is it possible that the itm.boxIds just do not match box.boxId often enough so it takes a lot longer to find ones that do?
public void testJoinMultipleReplicatePersistentRegionsWithLimitClause() throws Exception {
String regionName = "portfolio";
Cache cache = serverStarterRule.getCache();
assertNotNull(cache);
Region region1 =
cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT).create(regionName + 1);
Region region2 =
cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT).create(regionName + 2);
Region region3 =
cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT).create(regionName + 3);
for ( int i = 0; i < 1000; i++) {
Portfolio p = new Portfolio(i);
region1.put(i, p);
region2.put(i, p);
region3.put(i, p); //modify this line to region3.put(i, new Portfolio(-1)) to cause query to take longer
}
QueryService queryService = cache.getQueryService();
SelectResults results = (SelectResults) queryService
.newQuery("select p1.ID, p2.ID, p3.ID from /portfolio1 p1, /portfolio2 p2, /portfolio3 p3 where p1.ID = p2.ID and p3.ID = p1.ID limit 5").execute();
assertEquals(5, results.size());
}

decodingTCAP message - dialoguePortion

I'm writing an simulator (for learning purposes) for complete M3UA-SCCP-TCAP-MAP stack (over SCTP). So far M3UA+SCCP stacks are OK.
M3UA Based on the RFC 4666 Sept 2006
SCCP Based on the ITU-T Q.711-Q716
TCAP Based on the ITU-T Q.771-Q775
But upon decoding TCAP part I got lost on dialoguePortion.
TCAP is asn.1 encoded, so everything is tag+len+data.
Wireshark decode it differently than my decoder.
Message is:
62434804102f00676b1e281c060700118605010101a011600f80020780a1090607040000010005036c1ba1190201010201163011800590896734f283010086059062859107
Basically, my message is BER-decoded as
Note: Format: hex(tag) + (BER splitted to CLS+PC+TAG in decimal) + hex(data)
62 ( 64 32 2 )
48 ( 64 0 8 ) 102f0067
6b ( 64 32 11 )
28 ( 0 32 8 )
06 ( 0 0 6 ) 00118605010101 OID=0.0.17.773.1.1.1
a0 ( 128 32 0 )
60 ( 64 32 0 )
80 ( 128 0 0 ) 0780
a1 ( 128 32 1 )
06 ( 0 0 6 ) 04000001000503 OID=0.4.0.0.1.0.5.3
6c ( 64 32 12 )
...
So I can see begin[2] message containing otid[8], dialogPortion[11] and componentPortion[12].
otid and ComponentPortion are decoded correctly. But not dialogPortion.
ASN for dialogPortion does not mention any of these codes.
Even more confusing, wireshark decode it differently (oid-as-dialogue is NOT in the dialoguePortion, but as a field after otid, which is NOT as described in ITU-T documentation - or not as I'm understanding it)
Wireshark decoded Transaction Capabilities Application Part
begin
Source Transaction ID
otid: 102f0067
oid: 0.0.17.773.1.1.1 (id-as-dialogue)
dialogueRequest
Padding: 7
protocol-version: 80 (version1)
1... .... = version1: True
application-context-name: 0.4.0.0.1.0.5.3 (locationInfoRetrievalContext-v3)
components: 1 item
...
I can't find any reference for Padding in dialoguePDU ASN.
Can someone point me in the right direction?
I would like to know how to properly decode this message
DialoguePDU format should be simple in this case:
dialogue-as-id OBJECT IDENTIFIER ::= {itu-t recommendation q 773 as(1) dialogue-as(1) version1(1)}
DialoguePDU ::= CHOICE {
dialogueRequest AARQ-apdu,
dialogueResponse AARE-apdu,
dialogueAbort ABRT-apdu
}
AARQ-apdu ::= [APPLICATION 0] IMPLICIT SEQUENCE {
protocol-version [0] IMPLICIT BIT STRING {version1(0)} DEFAULT {version1},
application-context-name [1] OBJECT IDENTIFIER,
user-information [30] IMPLICIT SEQUENCE OF EXTERNAL OPTIONAL
}
Wireshark is still wrong :-). But then... that is display. It displays values correctly - only in the wrong section. Probably some reason due to easier decoding.
What I was missing was definition of EXTERNAL[8]. DialoguePortion is declared as EXTERNAL...so now everything makes sense.
For your message, my very own decoder says:
begin [APPLICATION 2] (x67)
otid [APPLICATION 8] (x4) =102f0067h
dialoguePortion [APPLICATION 11] (x30)
EXTERNAL (x28)
direct-reference [OBJECT IDENTIFIER] (x7) =00118605010101h
encoding:single-ASN1-type [0] (x17)
dialogueRequest [APPLICATION 0] (x15)
protocol-version [0] (x2) = 80 {version1 (0) } spare bits= 7
application-context-name [1] (x9)
OBJECT IDENTIFIER (x7) =04000001000503h
components [APPLICATION 12] (x27)
invoke [1] (x25)
invokeID [INTEGER] (x1) =1d (01h)
operationCode [INTEGER] (x1) = (22) SendRoutingInfo
parameter [SEQUENCE] (x17)
msisdn [0] (x5) = 90896734f2h
Nature of Address: international number (1)
Numbering Plan Indicator: unknown (0)
signal= 9876432
interrogationType [3] (x1) = (0) basicCall
gmsc-Address [6] (x5) = 9062859107h
Nature of Address: international number (1)
Numbering Plan Indicator: unknown (0)
signal= 26581970
Now, wireshark's padding 7 and my spare bits=7 both refer to the the protocol-version field, defined in Q.773 as:
AARQ-apdu ::= [APPLICATION 0] IMPLICIT SEQUENCE {
protocol-version [0] IMPLICIT BIT STRING { version1 (0) }
DEFAULT { version1 },
application-context-name [1] OBJECT IDENTIFIER,
user-information [30] IMPLICIT SEQUENCE OF EXTERNAL
OPTIONAL }
the BIT STRING definition, assigns name to just the leading bit (version1)... the rest (7 bits) are not given a name and wireshark consider them as padding

Retrieving the latest emails with MailCore2

I'm loading my latest emails and I'm saving the latest UID because later if the user reload the list of emails I want to get all the emails from that UID to now... for this, I'm using
UInt64 start = lUid;
UInt64 end = UINT64_MAX;
MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindHeaders;
MCOIndexSet *uids = [MCOIndexSet indexSetWithRange:MCORangeMake(start, end)];
MCOIMAPFetchMessagesOperation *fetchOperation = [imapSession fetchMessagesOperationWithFolder:#"INBOX"
requestKind:requestKind
uids:uids];
this action always return the results but I'm getting the latest email... So I tried to make
UInt64 start = lUid + 1;
but it is exactly the same.
EDIT
I'm looking the logger and the last UID is 34038 so when i made the call the start parameter was 34039... so why im getting the email with id 34038?
2015-01-20 18:33:06.852 App[25022:730644] mailcore - IMAP: 8 UID FETCH 34039:* (UID ENVELOPE BODY.PEEK[HEADER.FIELDS (References)])
Anyone know whats going on?
EDIT 2:
So this is my code
UInt64 start = lUid + 1;
UInt64 end = UINT64_MAX;
MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindHeaders;
MCOIndexSet *uids = [MCOIndexSet indexSetWithRange:MCORangeMake(start, end)];
MCOIMAPFetchMessagesOperation *fetchOperation = [imapSession fetchMessagesOperationWithFolder:#"INBOX"
requestKind:requestKind
uids:uids];
void(^fetchHandler)(NSError *, NSArray *, MCOIndexSet *) = ^(NSError *error, NSArray *fetchedMessages, MCOIndexSet *vanishedMessages) {
if( error ) {
completionHandler(UIBackgroundFetchResultFailed);
NSLog(#"Error downloading message headers:%#", error);
}
NSMutableArray *currentMessages = [NSMutableArray arrayWithArray:fetchedMessages];
if( [currentMessages count] > 0 ) {
MCOIMAPMessage *lastMessage = [fetchedMessages lastObject];
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:#(lastMessage.uid) forKey:#"lastUID"];
[defaults synchronize];
completionHandler(UIBackgroundFetchResultNewData);
}
else {
completionHandler(UIBackgroundFetchResultNoData);
}
};
[fetchOperation start:fetchHandler];
and this is the logger when i execute that call
2015-01-21 18:02:46.723 App[5021:473470] mailcore - IMAP: * OK Gimap ready for requests from 181.167.207.42 b69mb75112208qhb
2015-01-21 18:02:46.725 App[5021:473470] mailcore - IMAP: 1 CAPABILITY
2015-01-21 18:02:46.955 App[5021:473470] mailcore - IMAP: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN
1 OK Thats all she wrote! b69mb75112208qhb
2015-01-21 18:02:46.955 App[5021:473470] mailcore - IMAP: 2 AUTHENTICATE XOAUTH2 dXNlcj1zYW50b21lZ29uemFsb0BnbWFpbC5jb20BYXV0aD1CZWFyZXIgeWEyOS5BZ0VQNnBQNFRJN1ZEMHlwempRNm01bTMwS2J0b0F6VzN6REdBbXc2dmh0VEF1TUJISVVaN3BobEtwY0M4dDlQRVFHcVhETHRlMU5VaFEBAQ==
2015-01-21 18:02:47.267 App[5021:473470] mailcore - IMAP: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT
2 OK santomegonzalo#gmail.com authenticated (Success)
2015-01-21 18:02:47.267 App[5021:473470] mailcore - IMAP: 3 COMPRESS DEFLATE
2015-01-21 18:02:47.518 App[5021:473470] mailcore - IMAP: 3 OK Success
2015-01-21 18:02:47.518 App[5021:473470] mailcore - IMAP: 4 ENABLE CONDSTORE
2015-01-21 18:02:47.767 App[5021:473470] mailcore - IMAP: * ENABLED CONDSTORE
4 OK Success
2015-01-21 18:02:47.767 App[5021:473470] mailcore - IMAP: 5 NAMESPACE
2015-01-21 18:02:48.016 App[5021:473470] mailcore - IMAP: * NAMESPACE (("" "/")) NIL NIL
5 OK Success
2015-01-21 18:02:48.017 App[5021:473470] mailcore - IMAP: 6 ID NIL
2015-01-21 18:02:48.267 App[5021:473470] mailcore - IMAP: * ID ("name" "GImap" "vendor" "Google, Inc." "support-url" "http://support.google.com/mail" "version" "gmail_imap_150113.07_p0" "remote-host" "181.167.207.42")
6 OK Success
2015-01-21 18:02:48.268 App[5021:473470] mailcore - IMAP: 7 SELECT INBOX
2015-01-21 18:02:48.770 App[5021:473470] mailcore - IMAP: * FLAGS (\Answered \Flagged \Draft \Deleted \Seen $MailFlagBit1 $MailFlagBit0 $Phishing $Forwarded $MailFlagBit2 JunkRecorded $NotJunk NotJunk $NotPhishing $Junk)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen $MailFlagBit1 $MailFlagBit0 $Phishing $Forwarded $MailFlagBit2 JunkRecorded $NotJunk NotJunk $NotPhishing $Junk \*)] Flags permitted.
* OK [UIDVALIDITY 617846230] UIDs valid.
* 20472 EXISTS
* 0 RECENT
* OK [UIDNEXT 34091] Predicted next UID.
* OK [HIGHESTMODSEQ 4668463]
7 OK [READ-WRITE] INBO
2015-01-21 18:02:48.771 App[5021:473470] mailcore - IMAP: X selected. (Success)
2015-01-21 18:02:48.771 App[5021:473470] mailcore - IMAP: 8 UID FETCH 34092:* (UID ENVELOPE BODY.PEEK[HEADER.FIELDS (References)])
2015-01-21 18:02:49.405 App[5021:473470] mailcore - IMAP: * 20472 FETCH (UID 34090 MODSEQ (4668387) ENVELOPE ("Wed, 21 Jan 2015 20:31:46 -0000" "Subject" (("User" NIL "pullrequests-reply" "company.org")) (("User" NIL "toreply" "company.org")) (("User" NIL "toreply" "company.org")) ((NIL NIL "santomegonzalo" "gmail.com")) NIL NIL "<toreply#company.com>" " <toreply#company.com>") BODY[HEADER.FIELDS (References)] {52}
References: <toreply#company.com
)
8 OK Success

Resources