🐝 My patches for macos etc...
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.4 KiB

  1. /*
  2. * meli - managesieve REPL
  3. *
  4. * Copyright 2020 Manos Pitsidianakis
  5. *
  6. * This file is part of meli.
  7. *
  8. * meli is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * meli is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with meli. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #[macro_use]
  22. extern crate melib;
  23. use melib::*;
  24. use std::collections::VecDeque;
  25. extern crate xdg_utils;
  26. #[macro_use]
  27. extern crate serde_derive;
  28. extern crate linkify;
  29. extern crate uuid;
  30. extern crate serde_json;
  31. extern crate smallvec;
  32. extern crate termion;
  33. use melib::backends::imap::managesieve::new_managesieve_connection;
  34. use melib::Result;
  35. #[macro_use]
  36. pub mod types;
  37. use crate::types::*;
  38. #[macro_use]
  39. pub mod terminal;
  40. use crate::terminal::*;
  41. #[macro_use]
  42. pub mod command;
  43. use crate::command::*;
  44. pub mod state;
  45. use crate::state::*;
  46. pub mod components;
  47. use crate::components::*;
  48. #[macro_use]
  49. pub mod conf;
  50. use crate::conf::*;
  51. #[cfg(feature = "sqlite3")]
  52. pub mod sqlite3;
  53. pub mod jobs;
  54. pub mod mailcap;
  55. pub mod plugins;
  56. use futures::executor::block_on;
  57. /// Opens an interactive shell on a managesieve server. Suggested use is with rlwrap(1)
  58. ///
  59. /// # Example invocation:
  60. /// ```sh
  61. /// ./manage_sieve server_hostname server_username server_password server_port");
  62. /// ```
  63. ///
  64. /// `danger_accept_invalid_certs` is turned on by default, so no certificate validation is performed.
  65. fn main() -> Result<()> {
  66. let mut args = std::env::args().skip(1).collect::<Vec<String>>();
  67. if args.len() != 2 {
  68. eprintln!("Usage: manage_sieve CONFIG_PATH ACCOUNT_NAME");
  69. std::process::exit(1);
  70. }
  71. let (config_path, account_name) = (
  72. std::mem::replace(&mut args[0], String::new()),
  73. std::mem::replace(&mut args[1], String::new()),
  74. );
  75. std::env::set_var("MELI_CONFIG", config_path);
  76. let settings = conf::Settings::new()?;
  77. if !settings.accounts.contains_key(&account_name) {
  78. eprintln!(
  79. "Account not found. available accounts: {}",
  80. settings
  81. .accounts
  82. .keys()
  83. .cloned()
  84. .collect::<Vec<String>>()
  85. .join(", ")
  86. );
  87. std::process::exit(1);
  88. }
  89. let mut conn = new_managesieve_connection(&settings.accounts[&account_name].account)?;
  90. block_on(conn.connect())?;
  91. let mut res = String::with_capacity(8 * 1024);
  92. let mut input = String::new();
  93. println!("managesieve shell: use 'logout'");
  94. loop {
  95. use std::io;
  96. use std::io::Write;
  97. input.clear();
  98. print!("> ");
  99. io::stdout().flush().unwrap();
  100. match io::stdin().read_line(&mut input) {
  101. Ok(_) => {
  102. if input.trim().eq_ignore_ascii_case("logout") {
  103. break;
  104. }
  105. block_on(conn.send_command(input.as_bytes()))?;
  106. block_on(conn.read_lines(&mut res, String::new()))?;
  107. println!("out: {}", res.trim());
  108. }
  109. Err(error) => println!("error: {}", error),
  110. }
  111. }
  112. Ok(())
  113. }