Skip to content

Commit

Permalink
Add new sub-command to get email with changes
Browse files Browse the repository at this point in the history
If the user does not use mutt and cannot change the command for sending
mail to our utility, then you can start a fake smtp server that will
receive the email and execute the jira commands.

Signed-off-by: Alexey Gladkov <[email protected]>
  • Loading branch information
legionus committed Oct 19, 2023
1 parent 6e258fd commit 743a019
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ jira issue <ISSUE-123> change \
<field3> set <value3>
```

### Sub-Command: jiramail smtp

An alternative variant for applying changes. If your MUA does not have settings
to change the email sending utility (usually sendmail), then you can run a fake
smtp server.

You can specify a login and password to restrict access to smtp and jira
changes:

```ini
[smtp]
user = <username>
password = <secret>
port = 10025
```

## License

jiramail is licensed under the GNU General Public License (GPL), version 3.
Expand Down
4 changes: 3 additions & 1 deletion jiramail/change.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ def args(self) -> List[str]:
return []

def add_raw(self, line: str) -> None:
if line.endswith("\n"):
if line.endswith("\r\n"):
self.raw.append(line[:-2])
elif line.endswith("\n"):
self.raw.append(line[:-1])
else:
self.raw.append(line)
Expand Down
29 changes: 29 additions & 0 deletions jiramail/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def cmd_info(cmdargs: argparse.Namespace) -> int:
return jiramail.info.main(cmdargs)


def cmd_smtp(cmdargs: argparse.Namespace) -> int:
import jiramail.smtp
return jiramail.smtp.main(cmdargs)


def add_common_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument("-v", "--verbose",
dest="verbose", action='count', default=0,
Expand Down Expand Up @@ -142,6 +147,7 @@ def setup_parser() -> argparse.ArgumentParser:
# jiramail info
sp3_description = """\
retrieves issue information from the jira API.
"""
sp3 = subparsers.add_parser("info",
description=sp3_description,
Expand All @@ -155,6 +161,29 @@ def setup_parser() -> argparse.ArgumentParser:
help="specify the issue to export.")
add_common_arguments(sp3)

# jiramail smtp
sp4_description = """\
fake smtp server for receiving commands in sent emails. This is an alternative,
easier way to send commands.
"""
sp4 = subparsers.add_parser("smtp",
description=sp4_description,
help=sp4_description,
epilog=epilog,
add_help=False)
sp4.set_defaults(func=cmd_smtp)

sp4.add_argument("-n", "--dry-run",
dest="dry_run", action="store_true",
help="do not act, just print what would happen.")
sp4.add_argument("-1", "--one-message",
dest="one_message", action="store_true",
help="exit after processing one incoming email.")
sp4.add_argument("-m", "--mailbox",
dest="mailbox", action="store", default="",
help="path to mailbox to store a reply messages with the status of command execution.")
add_common_arguments(sp4)

return parser


Expand Down
Loading

0 comments on commit 743a019

Please sign in to comment.