I'm trying to make a SMTP client library and am trying to send email via the command line first.
250 SMTPUTF8
EHLO gmail.com
write to 0x7fb0e6c16130 [0x7fb0ea011a03] (37 bytes => 37 (0x25))
0000 - 17 03 03 00 20 3f a5 65-6f 8a a3 b8 a7 13 7e 70 .... ?.eo.....~p
0010 - 57 a1 7b ca c1 4b 25 56-39 b5 df d6 c4 b7 49 c1 W.{..K%V9.....I.
0020 - 32 f2 f4 5a c5 2..Z.
read from 0x7fb0e6c16130 [0x7fb0ea00d803] (5 bytes => 5 (0x5))
0000 - 17 03 03 00 c2 .....
read from 0x7fb0e6c16130 [0x7fb0ea00d808] (194 bytes => 194 (0xC2))
0000 - 23 b5 8f 8e 31 26 8a dd-98 ce fd 73 58 8b e4 f5 #...1&.....sX...
0010 - 0a d6 8d 7b a8 a0 97 fb-ef 48 84 9b 10 f4 58 2b ...{.....H....X+
0020 - 65 0c 61 29 17 f7 41 0b-c4 59 8a 87 87 4b f7 b9 e.a)..A..Y...K..
0030 - 7a 68 8c f8 1b ec 05 bb-fa 97 dc 81 76 ba 12 86 zh..........v...
0040 - ed a6 6f 06 44 74 e1 80-4c 24 37 a4 06 a6 40 9d ..o.Dt..L$7...#.
0050 - c9 57 b2 2d 6c a7 fe cf-bb 7b 32 4e 01 f2 65 94 .W.-l....{2N..e.
0060 - b5 1f f9 aa eb 73 c6 b8-6c 93 71 89 2c 84 83 ad .....s..l.q.,...
0070 - 73 bb 5a 8b 63 c4 5a 94-d9 65 fa 2e 3b 1a 3d 21 s.Z.c.Z..e..;.=!
0080 - f8 6f 97 f0 61 1d 13 b3-ee 68 cf ed 92 aa dd e0 .o..a....h......
0090 - 86 16 e3 14 71 ef b0 28-74 ec fa ba ad 9f e2 6d ....q..(t......m
00a0 - 05 c1 39 7a 65 71 21 34-e8 a7 be d1 6c 39 68 42 ..9zeq!4....l9hB
00b0 - 84 a2 8d 9e 7c 03 57 49-6f 5b c1 af 78 2d 72 e5 ....|.WIo[..x-r.
00c0 - 47 67 Gg
250-mx.google.com at your service, [2800:e2:37f:ecc6:9426:2eed:fdd4:795b]
250-SIZE 157286400
250-8BITMIME
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
MAIL FROM:kyle#live.com
write to 0x7fb0e6c16130 [0x7fb0ea011a03] (46 bytes => 46 (0x2E))
0000 - 17 03 03 00 29 1a 31 f6-c0 39 da 57 95 3e 85 0c ....).1..9.W.>..
0010 - 48 86 29 1c a5 c2 80 cb-40 79 ef fa 66 dd e7 10 H.).....#y..f...
0020 - 8e dd 14 d2 f3 c8 07 98-ff 06 68 8b 4d b2 ..........h.M.
read from 0x7fb0e6c16130 [0x7fb0ea00d803] (5 bytes => 5 (0x5))
0000 - 17 03 03 00 44 ....D
read from 0x7fb0e6c16130 [0x7fb0ea00d808] (68 bytes => 68 (0x44))
0000 - 4a 7d f0 e2 01 00 00 eb-8b c0 82 70 fd 09 1a 50 J}.........p...P
0010 - 3b b3 fb ab 8a a1 83 df-af cd c8 bb 96 4f eb 19 ;............O..
0020 - 38 19 fa 4c 28 5d 75 f9-a4 d5 20 38 c4 f3 b6 db 8..L(]u... 8....
0030 - cd 44 3f 36 6a 8c f6 79-38 2e d3 2f b2 c4 4d 91 .D?6j..y8../..M.
0040 - 51 e8 2f ff Q./.
555 5.5.2 Syntax error. d7si1665405vsj.297 - gsmtp
The problem is no matter what email address I use I get a syntax error. What am I doing wrong?
Missing brackets enclosing your source mailbox.
The first step in the procedure is the MAIL command.
MAIL FROM:<reverse-path> [SP <mail-parameters> ] <CRLF>
The portion of the first or only argument contains
the source mailbox (between "<" and ">" brackets), which can be
used to report errors (see Section 4.2 for a discussion of error
reporting). If accepted, the SMTP server returns a "250 OK" reply.
-- from RFC 5321 Section 3.3 (emphasis mine)
Change this
MAIL FROM:kyle#live.com
Into this:
MAIL FROM:<kyle#live.com>
That being said..
I'm trying to make a SMTP client library
Please don't do that! Almost every programming language has such libraries already, most often even in the respective stdlib. And the authors of those have generally carefully considered more edge cases than you and I ever could. Do not reinvent the wheel, especially if handling mail (where it is all too easy to cause interoperability issues or new vectors for spam/abuse).
I have a plaintext file that I wish to convert to something I can extract.
00000000 52 61 72 21 1a 07 01 00 f3 e1 82 eb 0b 01 05 07 |Rar!............|
00000010 00 06 01 01 80 80 80 00 3b fd 42 9f 51 02 03 31 |........;.B.Q..1|
00000020 a0 02 06 82 03 80 83 02 20 15 d4 6e 5b 46 b6 57 |........ ..n[F.W|
00000030 80 03 01 09 69 6e 73 74 72 2e 74 78 74 30 01 00 |....instr.txt0..|
00000040 03 0f 44 a5 ce af b3 09 b9 96 44 22 f4 99 ef 04 |..D.......D"....|
This is part of the file which made me believe it is a rar file. I tried using xxd with the -r option to no avail.
I tried the solution from here but it also didn't work.
Any ideas?
To solve my own question, and for future reference.
Use vim's visual block select to copy just the hex values into 'justhexvalues.txt'.
Then use xxd:
xxd -r -p justhexvalues.txt answer.rar
That was it.
I've got a google bigquery looking like this:
#standardSQL
SELECT
timestamp,
CAN_Frame,
TRIM(SPLIT(CAN_Frame)[OFFSET(4)]) AS bytes
FROM
`data.source`
WHERE
LENGTH(CAN_Frame) > 1 and
SUBSTR(TRIM(SPLIT(CAN_Frame)[OFFSET(4)]),1,2) IN ('83', '84')
ORDER BY
timestamp DESC
LIMIT
8000
or like this
#standardSQL
SELECT
*
FROM (
SELECT
timestamp,
CAN_Frame,
REGEXP_EXTRACT(CAN_Frame, r', ([^,]+)$') AS bytes_string,
FROM_HEX(REPLACE(REGEXP_EXTRACT(CAN_Frame, r', ([^,]+)$'), ' ', '')) AS
bytes
FROM `data.source`
)
WHERE SUBSTR(bytes, 1, 1) IN (b'\x83', b'\x84')
ORDER BY timestamp DESC
LIMIT 8000
with the resulting tables:
Row timestamp CAN_Frame bytes
1 2017-09-29 14:31:02 UTC S,48778,410,8, 84 10 00 25 00 21 00 4F 84 10 00
25 00 21 00 4F
2 2017-09-29 14:30:42 UTC S,35847,480,8, 83 80 00 01 00 03 00 0D 83 80 00
01 00 03 00 0D
3 2017-09-29 14:30:40 UTC S,34612,4B2,8, 84 B2 00 27 00 08 00 03 84 B2 00
27 00 08 00 03
or
Row timestamp CAN_Frame bytes_string bytes
1 2017-09-29 14:31:02 UTC S,48778,410,8, 84 10 00 25 00 21 00 4F 84 10 00 25 00 21 00 4F hBAAJQAhAE8=
2 2017-09-29 14:30:42 UTC S,35847,480,8, 83 80 00 01 00 03 00 0D 83 80 00 01 00 03 00 0D g4AAAQADAA0=
3 2017-09-29 14:30:40 UTC S,34612,4B2,8, 84 B2 00 27 00 08 00 03 84 B2 00 27 00 08 00 03 hLIAJwAIAAM=
4 2017-09-29 14:30:39 UTC S,34314,4C0,8, 84 C0 00 1C 00 15 00 07 84 C0 00 1C 00 15 00 07 hMAAHAAVAAc=
My problem and question is now how to split the 8 byte hexa string in a way that let me have the 6th and 7th byte of string beginning with 83, the 8th byte from 83 and the 3rd byte from 84 and the 4th and 5th byte of the string beginning with 84. these datapairs are values with lsb msb in unsigned int that i need to read.
i hope somebody can help me or at least understand my problem.
best regards
#standardSQL
WITH `data.source` AS (
SELECT 'S,0,2B3,8, C2 B3 00 00 00 00 03 DE' AS frame UNION ALL
SELECT 'S,0,3FA,6, 00 E0 04 A5 00 0B' UNION ALL
SELECT 'S,0,440,8, 83 40 4E A5 00 47 00 64' UNION ALL
SELECT 'S,0,450,8, 84 50 01 12 01 19 01 B3' UNION ALL
SELECT 'S,0,4B0,8, 84 B0 4E A5 00 43 00 64'
)
SELECT
frame, bytes, STRING_AGG(b, ' ' ORDER BY p) AS selected_bytes
FROM (
SELECT frame, TRIM(SPLIT(frame)[OFFSET(4)]) AS bytes, SUBSTR(TRIM(SPLIT(frame)[OFFSET(4)]), 1, 2) AS f
FROM `data.source`
WHERE SUBSTR(TRIM(SPLIT(frame)[OFFSET(4)]), 1, 2) IN ('83', '84')
), UNNEST(SPLIT(bytes, ' ')) AS b WITH OFFSET AS p
WHERE CASE f WHEN '83' THEN p IN (5, 6, 7) WHEN '84' THEN p IN (2, 3, 4) END
GROUP BY frame, bytes
-- ORDER BY frame
result is:
frame bytes selected_bytes
S,0,440,8, 83 40 4E A5 00 47 00 64 83 40 4E A5 00 47 00 64 47 00 64
S,0,450,8, 84 50 01 12 01 19 01 B3 84 50 01 12 01 19 01 B3 01 12 01
S,0,4B0,8, 84 B0 4E A5 00 43 00 64 84 B0 4E A5 00 43 00 64 4E A5 00
Update for:
byte 6 and 7 from the string beginning with 83 called Aiout
one column contains byte 8 from the string beginning with 83 and byte 3 from the string beginning with 84 called Biout
one column contains byte 4 and 5 from the string beginning with 84 called Avout
Bvout containing byte 6 and 7 from the string beginning with 84
#standardSQL
WITH `data.source` AS (
SELECT 'S,0,2B3,8, C2 B3 00 00 00 00 03 DE' AS frame UNION ALL
SELECT 'S,0,3FA,6, 00 E0 04 A5 00 0B' UNION ALL
SELECT 'S,0,440,8, 83 40 4E A5 00 47 00 64' UNION ALL
SELECT 'S,0,450,8, 84 50 01 12 01 19 01 B3' UNION ALL
SELECT 'S,0,4B0,8, 84 B0 4E A5 00 43 00 64'
)
SELECT
frame, bytes,
STRING_AGG(CASE WHEN f='83' AND p IN (5, 6) THEN b ELSE '' END, ' ' ORDER BY p) AS Aiout,
STRING_AGG(CASE WHEN (f='83' AND p=7) OR (f='84' AND p=2) THEN b ELSE '' END, ' ' ORDER BY p) AS Biout,
STRING_AGG(CASE WHEN f='84' AND p IN (3, 4) THEN b ELSE '' END, ' ' ORDER BY p) AS Avout,
STRING_AGG(CASE WHEN f='84' AND p IN (5, 6) THEN b ELSE '' END, ' ' ORDER BY p) AS Bvout
FROM (
SELECT frame, TRIM(SPLIT(frame)[OFFSET(4)]) AS bytes, SUBSTR(TRIM(SPLIT(frame)[OFFSET(4)]), 1, 2) AS f
FROM `data.source`
WHERE SUBSTR(TRIM(SPLIT(frame)[OFFSET(4)]), 1, 2) IN ('83', '84')
), UNNEST(SPLIT(bytes, ' ')) AS b WITH OFFSET AS p
GROUP BY frame, bytes
ORDER BY frame
with output as
frame bytes Aiout Biout Avout Bvout
S,0,440,8, 83 40 4E A5 00 47 00 64 83 40 4E A5 00 47 00 64 47 00 64
S,0,450,8, 84 50 01 12 01 19 01 B3 84 50 01 12 01 19 01 B3 01 12 01 19 01
S,0,4B0,8, 84 B0 4E A5 00 43 00 64 84 B0 4E A5 00 43 00 64 4E A5 00 43 00
My program was able to craft and send raw transactions to geth v1.3.3 before, but after I upgrade to geth v1.4.0, calling sendRawTransaction over RPC always returns invalid sender error.
Is transaction serialization (i.e. RLP) changed somehow from v1.3.3 to v1.4.0? Here is a dump of by raw transaction that triggers an invalid user error:
0x0000: F8 CA 80 85 0B A4 3B 74 00 83 01 5F 90 94 08 BE ......;t..._....
0x0010: 24 CD 8D CF 73 F8 FA 5D B4 2B 85 5B 43 70 BD 5C $...s..].+.[Cp.\
0x0020: 44 8B 80 B8 64 B0 70 B9 BA 00 00 00 00 00 00 00 D...d.p.........
0x0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x0040: 00 00 00 00 00 00 00 00 01 87 44 2E B8 96 6A 07 ..........D...j.
0x0050: 0C 31 C1 E8 AE A3 60 F5 35 32 47 81 13 34 31 D4 .1....`.52G..41.
0x0060: 4B FA 0A 0B 1B 9F 13 C6 F5 00 00 00 00 00 00 00 K...............
0x0070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x0080: 00 00 00 00 00 00 00 00 00 1B A0 DE A4 6B 8C E8 .............k..
0x0090: 72 5A 31 49 92 EC 6B 6F C6 89 8C BB D7 A4 B9 8A rZ1I..ko........
0x00A0: 10 D2 F7 9E CE 6B D5 0F C5 19 E9 A0 8F 74 57 C2 .....k.......tW.
0x00B0: 1C DA CB 7D 7A 2B 46 58 98 53 31 C3 4B CF 50 1F ...}z+FX.S1.K.P.
0x00C0: 17 CE 16 80 95 30 38 9B 98 3C 5B B8 .....08..<[.
A more machine readable version of my transaction is:
F8CA80850BA43B740083015F909408BE24CD8DCF73F8FA5DB42B855B4370BD5C448B80B864B070B9BA000000000000000000000000000000000000000000000000000000000000000187442EB8966A070C31C1E8AEA360F535324781133431D44BFA0A0B1B9F13C6F500000000000000000000000000000000000000000000000000000000000000001BA0DEA46B8CE8725A314992EC6B6FC6898CBBD7A4B98A10D2F79ECE6BD50FC519E9A08F7457C21CDACB7D7A2B4658985331C34BCF501F17CE16809530389B983C5BB8
Log from geth gives
I0504 20:22:27.392581 9768 types.go:106] Generated response: *shared.ErrorResponse &{%!s(float64=1) 2.0 %!s(*shared.ErrorObject=&{-32603 Invalid sender})}
I0504 20:22:27.392886 9768 http.go:157] Sending payload: {
"id": 1,
"jsonrpc": "2.0",
"error": {
"code": -32603,
"message": "Invalid sender"
}
}
I believe the JSON RPC stuff changed in geth v1.4.0. I can't tell why this is happening without seeing the full sendRawTransaction you are calling but check out the docs: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendtransaction
Also, this should be migrated to https://ethereum.stackexchange.com/
Posted previously the question with zero responses, so I am replacing it with further clarification and details from my research results based on this MySQL manual entry.
In the past, I've worked with alternate collations that allowed us to specify alternate default sorting. Mysql allows for this down to the column level, but I don't understand something to get it working.
Our customers use a standard set of one character codes in almost all references to any master table, and presenting these codes in the order they need is always very cumbersome and difficult using functions and routines in PHP.
SELECT * FROM myTable order by my_code
NORMAL, default sorting would return this: DESIRED, default sorting should return this:
my_code | Description my_code | Description
1 | Grade 1 P | Pre-Kindergarten
2 | Grade 2 K | Kindergarten
3 | Grade 3 1 | Grade 1
A | Adult 2 | Grade 2
K | Kindergarten 3 | Grade 3
P | Pre-Kindergarten A | Adult
The steps to accomplish this are described in the Docs at 10.4.3. , and examples are shown in the Docs at 10.1.78.
In the steps, it shows this table, and how the weights are specified. This, I think is where I get lost. I've altered the weights as shown below, putting "P" (x50P) and "K" (x4B) before "0" (x30), but all it accomplishes is changing the sorting so that "1" (x31) appears between "P" and "K", all other sorting appears to remain unchanged.
<collation name="latin1_test_ci">
<map>
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
50 4B 30 31 32 33 34 35 36 37 38 39 41 43 55 3A
3B 3C 3D 3E 3F 40 42 44 45 46 47 48 49 4A 4C 4D
4E 4F 51 52 53 54 56 57 58 59 5A 5B 5C 5D 5E 5F
60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
50 51 52 53 54 55 56 57 58 59 5A 7B 7C 7D 7E 7F
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
41 41 41 41 5C 5B 5C 43 45 45 45 45 49 49 49 49
44 4E 4F 4F 4F 4F 5D D7 D8 55 55 55 59 59 DE DF
41 41 41 41 5C 5B 5C 43 45 45 45 45 49 49 49 49
44 4E 4F 4F 4F 4F 5D F7 D8 55 55 55 59 59 DE FF
</map>
</collation>
Sort results WITH the Alternate Collation above
Hex |my_code | Description
32 | 2 |Grade 2
33 | 3 |Grade 3
41 | A |Adult Ed
4B | K |Kindergarten
31 | 1 |Grade 1
50 | P |Pre-K
I realize you said you wanted to change the collation, but this requires no ORDER BY and is worth considering. You can convert these to an ENUM type and they will sort in the order they appear in the ENUM.
CREATE TABLE myTable (
my_code ENUM('P', 'K', '1', '2', '3', 'A'),
...
)
Using numbers in ENUMs is strongly discouraged, so you'll have to be careful. The main issue is that numbers can be treated as an index or a value in the ENUM. So it's behavior depends on it's type, leading to unexpected results.
This table are weights table. If you want that P i less than K, then put 00 weight to P and 01 weight to K. To put a weight you should assign a value in 'letter position': for P position 50. Sample to put P as first order letter:
<collation name="latin1_test_ci">
<map>
FF FF FF FF FF FF FF 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
00 51 52 53 54 55 56 57 58 59 5A 7B 7C 7D 7E 7F <-- first weight
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
41 41 41 41 5B 5D 5B 43 45 45 45 45 49 49 49 49
44 4E 4F 4F 4F 4F 5C D7 5C 55 55 55 59 59 DE DF
41 41 41 41 5B 5D 5B 43 45 45 45 45 49 49 49 49
44 4E 4F 4F 4F 4F 5C F7 5C 55 55 55 59 59 DE FF
</map>
</collation>
Edit: Adding test and compete table.
The complete table for should be:
<collation name="latin1_test_ci">
<map>
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 02 03 04 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
40 05 42 43 44 45 46 47 48 49 4A 01 4C 4D 4E 4F
00 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
50 51 52 53 54 55 56 57 58 59 5A 7B 7C 7D 7E 7F
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
41 41 41 41 5B 5D 5B 43 45 45 45 45 49 49 49 49
44 4E 4F 4F 4F 4F 5C D7 5C 55 55 55 59 59 DE DF
41 41 41 41 5B 5D 5B 43 45 45 45 45 49 49 49 49
44 4E 4F 4F 4F 4F 5C F7 5C 55 55 55 59 59 DE FF
</map>
</collation>
* Testing: *
mysql> create table b (a varchar(1) collate latin1_test_ci );
mysql> insert into b values
-> ( 'P' ),
-> ('K'),
-> ('A'),
-> ('1'),
-> ('2'),
-> ('3');
mysql> SHOW COLLATION LIKE 'latin1_test_ci';
+----------------+---------+----+---------+----------+---------+
| Collation | Charset | Id | Default | Compiled | Sortlen |
+----------------+---------+----+---------+----------+---------+
| latin1_test_ci | latin1 | 56 | | | 0 |
+----------------+---------+----+---------+----------+---------+
1 row in set (0.00 sec)
mysql> select * from b order by a;
+------+
| a |
+------+
| P |
| K |
| 1 |
| 2 |
| 3 |
| A |
+------+
6 rows in set (0.00 sec)
I don't think you need a custom collation to accomplish your goals.
To order the result set:
ORDER BY FIELD(my_code, 'P','K','1','2','3','4','5','6',
'7','8','9','10','11','12','A')
To limit the result set:
WHERE my_code IN('K','1','2','3','4','5')
If you'll be writing this sort of functionality into a lot of queries, a helper function might be a good idea:
DELIMITER $$
CREATE FUNCTION `f_position`(in_char CHAR(1)) RETURNS INTEGER
BEGIN
RETURN FIELD(in_char, 'P','K','1','2','3','4','5','6',
'7','8','9','10','11','12','A');
END$$
DELIMITER ;
Just make sure that all possible codes are referenced in the function, and are placed in the order that you want.
With a helper function like that, you can write queries like so:
WHERE f_position(grade) BETWEEN f_position('K') AND f_position('5')
ORDER BY f_position(grade)
The only downside to using a helper function to limit result sets like that (as opposed to the WHERE grade IN(...)) is that the function call would prevent any indexes on the column "grade" from being used.