Browse Source

Working tbot

main
notplants 1 year ago
parent
commit
b4db882407
  1. 4
      .cargo/config
  2. 6
      @
  3. 477
      Cargo.lock
  4. 18
      Cargo.toml
  5. 15
      debian/peach-tbot.service
  6. 52
      gmail.py
  7. 77
      src/email.rs
  8. 56
      src/main.rs
  9. 70
      src/tele.rs

4
.cargo/config

@ -0,0 +1,4 @@
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
objcopy = { path ="aarch64-linux-gnu-objcopy" }
strip = { path ="aarch64-linux-gnu-strip" }

6
@

@ -0,0 +1,6 @@
# File patterns to ignore; see `git help ignore` for more information.
# Lines that start with '#' are comments.
vpsdeploy.sh
vpsdebdeploy.sh
.env
.mycotbot

477
Cargo.lock generated

@ -9,12 +9,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "autocfg"
version = "0.1.7"
@ -28,10 +22,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "base64"
version = "0.12.3"
name = "bitflags"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
checksum = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23"
[[package]]
name = "bitflags"
@ -40,16 +34,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "bufstream"
version = "0.1.4"
name = "bytes"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8"
checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
[[package]]
name = "bytes"
version = "0.5.6"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040"
[[package]]
name = "cc"
@ -64,17 +58,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "chrono"
version = "0.4.19"
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
"winapi 0.3.9",
]
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cloudabi"
@ -82,7 +69,7 @@ version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
dependencies = [
"bitflags",
"bitflags 1.2.1",
]
[[package]]
@ -140,7 +127,7 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
dependencies = [
"bitflags",
"bitflags 1.2.1",
"fuchsia-zircon-sys",
]
@ -152,9 +139,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "futures"
version = "0.3.7"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95314d38584ffbfda215621d723e0a3906f032e03ae5551e650058dac83d4797"
checksum = "a9d5813545e459ad3ca1bff9915e9ad7f1a47dc6a91b627ce321d5863b7dd253"
dependencies = [
"futures-channel",
"futures-core",
@ -167,9 +154,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.7"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0448174b01148032eed37ac4aed28963aaaa8cfa93569a08e5b479bbc6c2c151"
checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25"
dependencies = [
"futures-core",
"futures-sink",
@ -177,15 +164,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.7"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18eaa56102984bed2c88ea39026cff3ce3b4c7f508ca970cedf2450ea10d4e46"
checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815"
[[package]]
name = "futures-executor"
version = "0.3.7"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5f8e0c9258abaea85e78ebdda17ef9666d390e987f006be6080dfe354b708cb"
checksum = "10f6cb7042eda00f0049b1d2080aa4b93442997ee507eb3828e8bd7577f94c9d"
dependencies = [
"futures-core",
"futures-task",
@ -194,15 +181,15 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.7"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e1798854a4727ff944a7b12aa999f58ce7aa81db80d2dfaaf2ba06f065ddd2b"
checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04"
[[package]]
name = "futures-macro"
version = "0.3.7"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e36fccf3fc58563b4a14d265027c627c3b665d7fed489427e88e7cc929559efe"
checksum = "668c6733a182cd7deb4f1de7ba3bf2120823835b3bcfbeacf7d2c4a773c1bb8b"
dependencies = [
"proc-macro-hack",
"proc-macro2",
@ -212,24 +199,21 @@ dependencies = [
[[package]]
name = "futures-sink"
version = "0.3.7"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e3ca3f17d6e8804ae5d3df7a7d35b2b3a6fe89dac84b31872720fc3060a0b11"
checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23"
[[package]]
name = "futures-task"
version = "0.3.7"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d502af37186c4fef99453df03e374683f8a1eec9dcc1e66b3b82dc8278ce3c"
dependencies = [
"once_cell",
]
checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc"
[[package]]
name = "futures-util"
version = "0.3.7"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abcb44342f62e6f3e8ac427b8aa815f724fd705dfad060b18ac7866c15bb8e34"
checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025"
dependencies = [
"futures-channel",
"futures-core",
@ -238,7 +222,7 @@ dependencies = [
"futures-sink",
"futures-task",
"memchr",
"pin-project 1.0.1",
"pin-project-lite 0.2.6",
"pin-utils",
"proc-macro-hack",
"proc-macro-nested",
@ -251,18 +235,24 @@ version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"libc",
"wasi 0.9.0+wasi-snapshot-preview1",
"wasi",
]
[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
[[package]]
name = "h2"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535"
dependencies = [
"bytes",
"bytes 0.5.6",
"fnv",
"futures-core",
"futures-sink",
@ -284,11 +274,11 @@ checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
[[package]]
name = "http"
version = "0.2.1"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9"
checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11"
dependencies = [
"bytes",
"bytes 1.0.1",
"fnv",
"itoa",
]
@ -299,7 +289,7 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b"
dependencies = [
"bytes",
"bytes 0.5.6",
"http",
]
@ -321,7 +311,7 @@ version = "0.13.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ad767baac13b44d4529fcf58ba2cd0995e36e7b435bc5b039de6f47e880dbf"
dependencies = [
"bytes",
"bytes 0.5.6",
"futures-channel",
"futures-core",
"futures-util",
@ -345,38 +335,13 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed"
dependencies = [
"bytes",
"bytes 0.5.6",
"hyper",
"native-tls",
"tokio",
"tokio-tls",
]
[[package]]
name = "imap"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ae5af85d36c7f2062a5a3abed1fc73142a7cbf04a8cf4248fc672d763148884"
dependencies = [
"base64",
"bufstream",
"chrono",
"imap-proto",
"lazy_static",
"native-tls",
"nom",
"regex",
]
[[package]]
name = "imap-proto"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16a6def1d5ac8975d70b3fd101d57953fe3278ef2ee5d7816cba54b1d1dfc22f"
dependencies = [
"nom",
]
[[package]]
name = "indexmap"
version = "1.6.0"
@ -396,6 +361,15 @@ dependencies = [
"libc",
]
[[package]]
name = "ipnetwork"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02c3eaab3ac0ede60ffa41add21970a7df7d91772c03383aac6c2c3d53cc716b"
dependencies = [
"serde",
]
[[package]]
name = "itoa"
version = "0.4.6"
@ -418,24 +392,11 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lexical-core"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616"
dependencies = [
"arrayvec",
"bitflags",
"cfg-if",
"ryu",
"static_assertions",
]
[[package]]
name = "libc"
version = "0.2.80"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
[[package]]
name = "log"
@ -452,7 +413,7 @@ version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
]
[[package]]
@ -488,7 +449,7 @@ version = "0.6.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"fuchsia-zircon",
"fuchsia-zircon-sys",
"iovec",
@ -550,32 +511,11 @@ version = "0.2.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
"lexical-core",
"memchr",
"version_check 0.9.2",
]
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg 1.0.1",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
@ -587,21 +527,21 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.4.1"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad"
checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
[[package]]
name = "openssl"
version = "0.10.30"
version = "0.10.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4"
checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577"
dependencies = [
"bitflags",
"cfg-if",
"bitflags 1.2.1",
"cfg-if 1.0.0",
"foreign-types",
"lazy_static",
"libc",
"once_cell",
"openssl-sys",
]
@ -611,15 +551,25 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
[[package]]
name = "openssl-src"
version = "111.15.0+1.1.1k"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1a5f6ae2ac04393b217ea9f700cd04fa9bf3d93fae2872069f3d15d908af70a"
dependencies = [
"cc",
]
[[package]]
name = "openssl-sys"
version = "0.9.58"
version = "0.9.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de"
checksum = "313752393519e876837e09e1fa183ddef0be7735868dced3196f4472d536277f"
dependencies = [
"autocfg 1.0.1",
"cc",
"libc",
"openssl-src",
"pkg-config",
"vcpkg",
]
@ -633,6 +583,19 @@ dependencies = [
"num-traits",
]
[[package]]
name = "peach-tbot"
version = "0.1.0"
dependencies = [
"dotenv",
"futures",
"native-tls",
"openssl",
"pnet",
"telegram-bot",
"tokio",
]
[[package]]
name = "phf"
version = "0.7.24"
@ -718,6 +681,12 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b"
[[package]]
name = "pin-project-lite"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905"
[[package]]
name = "pin-utils"
version = "0.1.0"
@ -730,6 +699,94 @@ version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
[[package]]
name = "pnet"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b657d5b9a98a2c81b82549922b8b15984e49f8120cd130b11a09f81b9b55d633"
dependencies = [
"ipnetwork",
"pnet_base",
"pnet_datalink",
"pnet_packet",
"pnet_sys",
"pnet_transport",
]
[[package]]
name = "pnet_base"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e4688aa497ef62129f302a5800ebde67825f8ff129f43690ca84099f6620bed"
[[package]]
name = "pnet_datalink"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59001c9c4d9d23bf2f61afaaf134a766fd6932ba2557c606b9112157053b9ac7"
dependencies = [
"ipnetwork",
"libc",
"pnet_base",
"pnet_sys",
"winapi 0.3.9",
]
[[package]]
name = "pnet_macros"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d894a90dbdbe976e624453fc31b1912f658083778329442dda1cca94f76a3e76"
dependencies = [
"regex",
"syntex",
"syntex_syntax",
]
[[package]]
name = "pnet_macros_support"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b99269a458570bc06a9132254349f6543d9abc92e88b68d8de934aac9481f6c"
dependencies = [
"pnet_base",
]
[[package]]
name = "pnet_packet"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33f8238f4eb897a55ca06510cd71afb5b5ca7b4ff2d7188f1ca855fc1710133e"
dependencies = [
"glob",
"pnet_base",
"pnet_macros",
"pnet_macros_support",
"syntex",
]
[[package]]
name = "pnet_sys"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7589e4c4e7ed72a3ffdff8a65d3bea84e8c3a23e19d0a10e8f45efdf632fff15"
dependencies = [
"libc",
"winapi 0.3.9",
]
[[package]]
name = "pnet_transport"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "326abdfd2e70e8e943bd58087b59686de170cac050a3b19c9fcc84db01690af5"
dependencies = [
"libc",
"pnet_base",
"pnet_packet",
"pnet_sys",
]
[[package]]
name = "ppv-lite86"
version = "0.2.10"
@ -750,11 +807,11 @@ checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a"
[[package]]
name = "proc-macro2"
version = "1.0.24"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
dependencies = [
"unicode-xid",
"unicode-xid 0.2.1",
]
[[package]]
@ -930,21 +987,20 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "regex"
version = "1.4.2"
version = "1.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c"
checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
"thread_local",
]
[[package]]
name = "regex-syntax"
version = "0.6.21"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
[[package]]
name = "remove_dir_all"
@ -955,6 +1011,12 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "rustc-serialize"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
[[package]]
name = "ryu"
version = "1.0.5"
@ -977,7 +1039,7 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69"
dependencies = [
"bitflags",
"bitflags 1.2.1",
"core-foundation",
"core-foundation-sys",
"libc",
@ -1053,27 +1115,70 @@ version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"libc",
"redox_syscall",
"winapi 0.3.9",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "syn"
version = "1.0.48"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
"unicode-xid 0.2.1",
]
[[package]]
name = "syntex"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a30b08a6b383a22e5f6edc127d169670d48f905bb00ca79a00ea3e442ebe317"
dependencies = [
"syntex_errors",
"syntex_syntax",
]
[[package]]
name = "syntex_errors"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04c48f32867b6114449155b2a82114b86d4b09e1bddb21c47ff104ab9172b646"
dependencies = [
"libc",
"log 0.3.9",
"rustc-serialize",
"syntex_pos",
"term",
"unicode-xid 0.0.3",
]
[[package]]
name = "syntex_pos"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fd49988e52451813c61fecbe9abb5cfd4e1b7bb6cdbb980a6fbcbab859171a6"
dependencies = [
"rustc-serialize",
]
[[package]]
name = "syntex_syntax"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7628a0506e8f9666fdabb5f265d0059b059edac9a3f810bda077abb5d826bd8d"
dependencies = [
"bitflags 0.5.0",
"libc",
"log 0.3.9",
"rustc-serialize",
"syntex_errors",
"syntex_pos",
"term",
"unicode-xid 0.0.3",
]
[[package]]
@ -1082,7 +1187,7 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb29fb11ef40c839c1c6b4e9c2ec4f357f9f674491e9df5a8c94f8cc2005f860"
dependencies = [
"bytes",
"bytes 0.5.6",
"futures",
"hyper",
"hyper-tls",
@ -1099,7 +1204,7 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "add65834bee405351f092b18a4647cae05d1c40699570054eadc6d4035d9692c"
dependencies = [
"bytes",
"bytes 0.5.6",
"serde",
"serde-value",
"serde_derive",
@ -1112,7 +1217,7 @@ version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"libc",
"rand 0.7.3",
"redox_syscall",
@ -1121,23 +1226,13 @@ dependencies = [
]
[[package]]
name = "thread_local"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
dependencies = [
"lazy_static",
]
[[package]]
name = "time"
version = "0.1.44"
name = "term"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
checksum = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi 0.3.9",
"kernel32-sys",
"winapi 0.2.8",
]
[[package]]
@ -1146,23 +1241,23 @@ version = "0.2.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd"
dependencies = [
"bytes",
"bytes 0.5.6",
"fnv",
"futures-core",
"iovec",
"lazy_static",
"memchr",
"mio",
"pin-project-lite",
"pin-project-lite 0.1.11",
"slab",
"tokio-macros",
]
[[package]]
name = "tokio-macros"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389"
checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a"
dependencies = [
"proc-macro2",
"quote",
@ -1185,11 +1280,11 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499"
dependencies = [
"bytes",
"bytes 0.5.6",
"futures-core",
"futures-sink",
"log 0.4.11",
"pin-project-lite",
"pin-project-lite 0.1.11",
"tokio",
]
@ -1205,9 +1300,9 @@ version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"log 0.4.11",
"pin-project-lite",
"pin-project-lite 0.1.11",
"tracing-attributes",
"tracing-core",
]
@ -1254,9 +1349,15 @@ version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33"
dependencies = [
"version_check 0.1.5",
"version_check",
]
[[package]]
name = "unicode-xid"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36dff09cafb4ec7c8cf0023eb0b686cb6ce65499116a12201c9e11840ca01beb"
[[package]]
name = "unicode-xid"
version = "0.2.1"
@ -1275,12 +1376,6 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
[[package]]
name = "version_check"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "want"
version = "0.3.0"
@ -1297,24 +1392,6 @@ version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wgbot"
version = "0.1.0"
dependencies = [
"dotenv",
"futures",
"imap",
"native-tls",
"telegram-bot",
"tokio",
]
[[package]]
name = "winapi"
version = "0.2.8"

18
Cargo.toml

@ -1,15 +1,29 @@
[package]
name = "wgbot"
name = "peach-tbot"
version = "0.1.0"
authors = ["Max Fowler <maxhfowler@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[package.metadata.deb]
depends = "$auto"
extended-description = """\
peach-tbot is a microservice to log IP address over telegram \
"""
maintainer-scripts="debian"
systemd-units = { unit-name = "peach-tbot" }
assets = [
["target/release/peach-tbot", "usr/bin/", "755"],
]
[dependencies]
telegram-bot = "0.7"
dotenv = "0.15.0"
futures = "0.3.7"
tokio = { version = "0.2", features = ["macros", "time", "fs"] }
imap = "2.3.0"
native-tls = "0.2.6"
pnet = "0.27.2"
# Added due to reqwest dependency problems when cross-compiling for RPi
openssl = { version = "0.10.32", features = ["vendored"] }

15
debian/peach-tbot.service vendored

@ -0,0 +1,15 @@
[Unit]
Description=peach-tbot
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/peach-tbot
Restart=always
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target

52
gmail.py

@ -1,52 +0,0 @@
import email, getpass, imaplib, os
detach_dir = '.' # directory where to save attachments (default: current)
user = "maxhfowler@gmail.com"
pwd = "hidden"
# connecting to the gmail imap server
m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login(user, pwd)
#
# m.select("wgbot") # here you a can choose a mail box like INBOX instead
m.select("INBOX") # here you a can choose a mail box like INBOX instead
# # use m.list() to get all the mailboxes
#
resp, items = m.search(None,
"ALL") # you could filter using the IMAP rules here (check http://www.example-code.com/csharp/imap-search-critera.asp)
items = items[0].split() # getting the mails id
for emailid in items:
resp, data = m.fetch(emailid,
"(RFC822)") # fetching the mail, "`(RFC822)`" means "get the whole stuff", but you can ask for headers only, etc
email_body = data[0][1] # getting the mail content
mail = email.message_from_bytes(email_body) # parsing the mail content to get a mail object
# Check if any attachments at all
if mail.get_content_maintype() != 'multipart':
continue
print("[" + mail["From"] + "] :" + mail["Subject"])
# we use walk to create a generator so we can iterate on the parts and forget about the recursive headach
for part in mail.walk():
# multipart are just containers, so we skip them
if part.get_content_maintype() == 'multipart':
continue
# is this part an attachment ?
if part.get('Content-Disposition') is None:
continue
# filename = part.get_filename()
filename = mail["From"] + "_hw1answer"
att_path = os.path.join(detach_dir, filename)
# Check if its already there
if not os.path.isfile(att_path):
# finally write the stuff
fp = open(att_path, 'wb')
fp.write(part.get_payload(decode=True))
fp.close()

77
src/email.rs

@ -1,77 +0,0 @@
extern crate imap;
extern crate native_tls;
use telegram_bot::{Api, Error};
use crate::tele::TStruct;
use std::result::Result;
use imap::types::{Fetch, Seq};
use imap::Session;
//fn delete(seq: imap::types::Seq, s: &mut Session<TcpStream>) -> imap::error::Result<()> {
// s.store(format!("{}", seq), "+FLAGS (\\Deleted)")?;
// s.expunge()?;
// Ok(())
//}
pub fn fetch_inbox_top(imap_username: &str, imap_password: &str, telegram: &TStruct) -> imap::error::Result<Option<String>> {
let domain = "imap.gmail.com";
let tls = native_tls::TlsConnector::builder().build().unwrap();
// we pass in the domain twice to check that the server's TLS
// certificate is valid for the domain we're connecting to.
let client = imap::connect((domain, 993), domain, &tls).unwrap();
// the client we have here is unauthenticated.
// to do anything useful with the e-mails, we need to log in
let mut imap_session = client
.login(imap_username, imap_password)
.map_err(|e| e.0)?;
// we want to fetch the first email in the INBOX mailbox
imap_session.select("wgbot")?;
// fetch message number 1 in this mailbox, along with its RFC822 field.
// RFC 822 dictates the format of the body of e-mails
let messages = imap_session.fetch("1", "RFC822")?;
let message = if let Some(m) = messages.iter().next() {
m
} else {
return Ok(None);
};
// extract the message's body
let body = message.body().expect("message did not have a body!");
let body = std::str::from_utf8(body)
.expect("message was not valid utf-8")
.to_string();
println!("{}", body);
let mut split = body.lines();
let split_vec: Vec<&str> = split.collect();
let mut to_return : Option<String> = None;
for line in split_vec {
if line.contains("suchauftrag_detail") {
to_return = Some(String::from(line.trim_start()))
}
}
// now delete the email
let seq : Seq = message.message;
imap_session.store(format!("{}", seq), "+FLAGS (\\Deleted)")?;
imap_session.expunge()?;
// let result : Result<(), Error> = telegram.log("test message 3").await;
// match result {
// Ok(v) => println!("++ logged"),
// Err(e) => println!("++ error logging: {?}", e)
// }
// be nice to the server and log out
imap_session.logout()?;
// Ok(Some(body))
Ok(to_return)
}

56
src/main.rs

@ -4,7 +4,6 @@ use dotenv;
use futures::StreamExt;
use telegram_bot::*;
use telegram_bot::{Api, Message, SendMessage, MessageKind, UpdateKind};
mod email;
mod tele;
use tele::TStruct;
use std::result::Result;
@ -12,62 +11,23 @@ use std::{thread, time};
#[tokio::main]
async fn main() -> Result<(), Error> {
dotenv::dotenv().ok();
dotenv::from_path("/etc/peachtbot.conf").ok();
let token = env::var("TELEGRAM_BOT_TOKEN").expect("TELEGRAM_BOT_TOKEN not set");
let api = Api::new(token);
// api.send(message.text_reply(format!("+ wgbot is booting up")));
let imap_username = env::var("IMAP_USERNAME").expect("imap username is not set");
let imap_password = env::var("IMAP_PASSWORD").expect("imap password is not set");
let telegram_log_id: i64 = env::var("TELEGRAM_LOG_ID").expect("TELEGRAM_LOG_ID is not set").parse().unwrap();
let t: TStruct = TStruct::new(api, telegram_log_id);
t.test();
t.log("++ wgbot is online").await?;
t.log("++ peach-tbot is online").await?;
loop {
println!("++ fetching new emails");
let email = email::fetch_inbox_top(&imap_username, &imap_password, &t);
match email {
Ok(v) => {
println!("positive result");
match v {
Some(x) => {
let log_msg = format!("++ new listing: {}", x);
t.log(&log_msg).await?;
}
None => println!("None returned")
}
},
Err(e) => println!("error: {:?}", e),
}
let wait_time = time::Duration::from_millis(5000);
thread::sleep(wait_time);
}
t.log_ip().await?;
t.poll().await?;
//
// // Fetch new updates via long poll method
// let mut stream = api.stream();
// while let Some(update) = stream.next().await {
// // If the received update contains a new message...
// let update = update?;
// if let UpdateKind::Message(message) = update.kind {
// if let MessageKind::Text { ref data, .. } = message.kind {
// // Print received text message to stdout.
// println!("<{}>: {}", &message.from.first_name, data);
// println!("user id: {}", &message.from.id);
//
// // Answer message with "Hi".
// api.send(message.text_reply(format!(
// "Hi, {}! You just wrote '{}'",
// &message.from.first_name, data
// )))
// .await?;
// }
// }
// }
Ok(())
}

70
src/tele.rs

@ -1,6 +1,11 @@
use telegram_bot::*;
use telegram_bot::{Api, Message, SendMessage, MessageKind, UpdateKind};
use std::result::Result;
use futures::StreamExt;
extern crate pnet;
use pnet::datalink;
use pnet::ipnetwork;
use std::process::Command;
pub struct TStruct {
@ -26,4 +31,69 @@ impl TStruct {
self.api.send(s).await?;
Ok(())
}
pub async fn poll(&self) -> Result<(), telegram_bot::Error>{
// Fetch new updates via long poll method
let mut stream = self.api.stream();
while let Some(update) = stream.next().await {
// If the received update contains a new message...
let update = update?;
if let UpdateKind::Message(message) = update.kind {
if let MessageKind::Text { ref data, .. } = message.kind {
// Print received text message to stdout.
println!("<{}>: {}", &message.from.first_name, data);
println!("user id: {}", &message.from.id);
let command = data.as_str();
if command == "ip" {
self.log_ip().await?;
} else if command == "public" {
self.log("++ attempting to get public ip").await?;
let public_ip = self.public_ip().await;
self.log(&format!("++ public ip: {}", public_ip)).await?
}
else {
// unknown command
self.api.send(message.text_reply(format!(
"unknown command '{}'", data
)))
.await?;
}
}
}
}
Ok(())
}
pub async fn log_ip(&self) -> Result<(), telegram_bot::Error> {
let ifaces= ["eth0", "wlan0"];
self.log("++ attemping to get ip address").await?;
for iface in datalink::interfaces() {
if ifaces.contains(&iface.name.as_str()) {
println!("{}: {:?}", &iface.name, iface);
// loop through ips
for ip in iface.ips {
match ip {
ipnetwork::IpNetwork::V4(ipNetwork) => {
println!("ip: {:?}", ipNetwork.ip());
let log_msg = &format!("++ {} ip: {}", &iface.name, ipNetwork.ip());
println!("{}", log_msg);
self.log(log_msg).await?;
}
_ => {
println!("no match");
}
}
}
}
}
Ok(())
}
pub async fn public_ip(&self) -> String {
let output = Command::new("/usr/bin/curl")
.arg("ifconfig.me")
.output().expect("failed to get public IP");
let command_output = std::str::from_utf8(&output.stdout).expect("Incorrect format");
command_output.to_string()
}
}
Loading…
Cancel
Save