Skip to content

Commit

Permalink
final tests before issuing version 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
e3rd committed Jan 28, 2020
1 parent 0451eca commit 2d412a3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Python3.6+ required.
+ [Usage 2 – CSV processor program](#usage-2--csv-processor-program)
+ [Usage 3 – Web service](#usage-3--web-service)
* [Installation and first run](#installation-and-first-run)
+ [Prerequisities](#prerequisities)
+ [Launch as a package:](#launch-as-a-package-)
+ [OR launch from a directory](#or-launch-from-a-directory)
+ [Bash completion](#bash-completion)
+ [Dependencies and troubleshooting](#dependencies-and-troubleshooting)
+ [Customisation](#customisation)
* [Computing fields](#computing-fields)
+ [Computable fields](#computable-fields)
Expand All @@ -43,7 +43,8 @@ Python3.6+ required.
- [PickInput decorator](#pickinput-decorator)
* [Web service](#web-service)
* [Sending files](#sending-files)
+ [Arbitrary e-mail headers, "From" header, GPG signing](#arbitrary-e-mail-headers---from--header--gpg-signing)
+ [Arbitrary e-mail headers, "From" header, GPG signing](#arbitrary-e-mail-headers-from-header-gpg-signing)
+ [Dynamic templates](#dynamic-templates)
* [Examples](#examples)
+ [URL parsing](#url-parsing)
- [Output formats](#output-formats)
Expand Down Expand Up @@ -112,6 +113,14 @@ Access in the browser: http://localhost:26683/?q=example.com

## Installation and first run

### Prerequisities
* You'll be asked to install `dialog` library at the first run if not already present in the system.
* If something is missing on your system, you may find help yourself with this command:
`sudo apt install python3-pip python3-dev python3-tk git xdg-utils dialog whois dnsutils nmap curl build-essential libssl-dev libpcre3 libpcre3-dev swig && pip3 install setuptools wheel uwsgi && pip3 install --upgrade ipython`
* `build-essential` is needed to build `uwsgi` and `envelope`
* `libpcre3 libpcre3-dev` needed to suppress uWSGI warning `!!! no internal routing support, rebuild with pcre support !!!`
* `libssl-dev` needed to be present before building `uwsgi` if you will need to use `--https`
* `python3-dev swig` needed to build `envelope`

### Launch as a package:

Expand Down Expand Up @@ -150,14 +159,6 @@ pip3 install -r requirements.txt --user
2. Copy: [extra/convey-autocompletion.bash](./extra/convey-autocompletion.bash) to `/etc/bash_completion.d/`
3. Restart terminal

### Dependencies and troubleshooting
* You'll be asked to install `dialog` library at the first run if not already present in the system.
* If something is missing on your system, you may find help yourself with this command: `sudo apt install python3-pip python3-dev python3-tk git xdg-utils dialog whois dnsutils nmap curl build-essential libssl-dev libpcre3 libpcre3-dev swig && pip3 install setuptools wheel uwsgi && pip3 install --upgrade ipython`
* `build-essential` is needed to build `uwsgi` and `envelope`
* `libpcre3 libpcre3-dev` needed to suppress uWSGI warning `!!! no internal routing support, rebuild with pcre support !!!`
* `libssl-dev` needed to be present before building `uwsgi` if you will need to use `--https`
* `python3-dev swig` needed to build `envelope`

### Customisation
* Launch convey with [`--help`](docs/convey-help-cmd-output.md) flag to see [further options](docs/convey-help-cmd-output.md).
* A file [`config.ini`](convey/defaults/config.ini) is automatically created in [user config folder](convey/defaults/config.ini). This file may be edited for further customisation. Access it with `convey --config`.
Expand Down Expand Up @@ -403,7 +404,7 @@ Few instruments are included to treat the attachment contents:
{{ print_attachment() }}
```
* **amount(count=2)** – Check if the attachment has at least count number of lines. Header is not counted. Useful when deciding whether the are single row in the result or multiple.
* **amount(count=2)** – Check if the attachment has at least `count` number of lines. Header is not counted. Useful when deciding whether the are single row in the result or multiple.
* **joined(column: int, delimiter=", ")** – Return a column joined by delimiter
* **first_row** – Access first line fields
Example:
Expand Down
18 changes: 11 additions & 7 deletions convey/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ def run(self):
" Prints out the least information possible."
"\n(Ex: if checking single value outputs a single word, prints out just that.)",
action="store_true")
parser.add_argument('-y', '--yes', help="Assume non-interactive mode and the default answer to questions.",
parser.add_argument('-y', '--yes', help="Assume non-interactive mode and the default answer to questions. "
"Will not send e-mails unless --send is on too.",
action="store_true")
parser.add_argument('-H', '--headless',
help="Launch program in a headless mode which imposes --yes and --quiet. No menu is shown.",
action="store_true")
parser.add_argument('--send', help="Automatically send e-mails when split; imposes --yes.",
parser.add_argument('--send', help="Automatically send e-mails when split.",
action=BlankTrueString, nargs="?", metavar="[blank/smtp/otrs]")
parser.add_argument('--send-test', help="Display e-mail message that would be generated for given e-mail.",
nargs=2, metavar=["E-MAIL", "TEMPLATE_FILE"])
Expand Down Expand Up @@ -555,12 +556,12 @@ def change_dialect(s, s2):
self.process()

if args.send and self.parser.is_analyzed and self.parser.is_split and not self.parser.is_processable:
Config.set("yes", True)
#Config.set("yes", True)
see_menu = False
if args.send is not True:
self.send_menu(args.send)
self.send_menu(args.send, send_now=True)
else:
self.send_menu()
self.send_menu(send_now=True)
if args.send_test:
c = Path(args.send_test[1]).read_text()
Path(Config.get_cache_dir(), Config.get("mail_template")).write_text(c)
Expand Down Expand Up @@ -707,14 +708,16 @@ def add_new_column(self, task, add=True):
self.parser.is_processable = True
return target_type

def send_menu(self, method="smtp", test_attachment=None):
def send_menu(self, method="smtp", test_attachment=None, send_now=False):
# choose method SMTP/OTRS
if self.args.csirt_incident:
if Config.get("otrs_enabled", "OTRS"):
method = "otrs"
else:
print("You are using csirt-incident macro but otrs_enabled key is set to False in config.ini. Exiting.")
quit()
elif Config.get("otrs_enabled", "OTRS") and self.args.otrs_id:
method = "otrs"
elif Config.get("otrs_enabled", "OTRS") and not Config.get("yes"):
menu = Menu(title="What sending method do we want to use?", callbacks=False, fullscreen=True)
menu.add("Send by SMTP...")
Expand Down Expand Up @@ -781,8 +784,9 @@ def display_recipients(abroad, text):

if test_attachment:
option = "test"
elif Config.get("yes"):
elif send_now: # XConfig.get("yes")
option = "1"
send_now = False
else:
clear()
menu = Menu("\n".join(info), callbacks=False, fullscreen=False, skippable=False)
Expand Down
16 changes: 9 additions & 7 deletions convey/mail_sender.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Send mails throught OTRS
import http.client
import logging
import re
Expand Down Expand Up @@ -36,6 +35,7 @@ def send_list(self, mails):
""" Send a bunch of e-mail messages """
sent_mails = 0
total_count = 0
status = None

if self.start() is False:
return False
Expand Down Expand Up @@ -219,14 +219,17 @@ def assure_tokens(self):
continue

def process(self, e: envelope):
def assure_str(c):
return c if type(c) is str else ";".join(c)

fields = (
("Action", "AgentTicketForward"),
("Subaction", "SendEmail"),
("TicketID", str(self.parser.otrs_id)),
("Email", getaddresses([e._sender])[0][1]),
# XX delete this option and rename the other: Config.get("email_from", "SMTP")),
("From", e._sender), # XX XConfig.get("email_from_name", "SMTP")
("To", e._to), # mails can be delimited by comma or semicolon
("From", assure_str(e._sender)), # XX XConfig.get("email_from_name", "SMTP")
("To", assure_str(e._to)), # mails can be delimited by comma or semicolon
("Subject", e._subject),
("Body", e._message),
("ArticleTypeID", "1"), # mail-external
Expand All @@ -240,11 +243,10 @@ def process(self, e: envelope):
pass

if e._cc:
fields += ("Cc", e._cc),

# load souboru k zaslani
# attachment_contents = registryRecord.getFileContents() #csv.ips2logfile(mailList.mails[mail])
fields += ("Cc", assure_str(e._cc)),

if e._bcc: # XX not sure if working
fields += ("Bcc", assure_str(e._bcc)),

attachment_contents = ""
if self.parser.attachment_name and len(e._attachments):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name='convey',
version="1.3rc10",
version="1.3",
packages=['convey'],
author='Edvard Rejthar',
author_email='[email protected]',
Expand Down
4 changes: 2 additions & 2 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from pathlib import Path
from subprocess import run, PIPE
from unittest import TestCase
from unittest import TestCase, main

logging.basicConfig(stream=sys.stderr, level=logging.WARNING)

Expand Down Expand Up @@ -71,4 +71,4 @@ def test_dynamic_template(self):


if __name__ == '__main__':
unittest.main()
main()

0 comments on commit 2d412a3

Please sign in to comment.