Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/d6y/dropblog
Rust application to generate blog post from email and upload to Dropbox
https://github.com/d6y/dropblog
blog dropbox email thumbnail
Last synced: about 1 month ago
JSON representation
Rust application to generate blog post from email and upload to Dropbox
- Host: GitHub
- URL: https://github.com/d6y/dropblog
- Owner: d6y
- License: gpl-3.0
- Created: 2020-01-07T11:56:15.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-25T08:49:30.000Z (9 months ago)
- Last Synced: 2024-03-25T23:29:30.384Z (9 months ago)
- Topics: blog, dropbox, email, thumbnail
- Language: Rust
- Homepage:
- Size: 167 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Drop blog: email-to-dropbox blog posting
- Connects to an IMAP account and reads an email
- Extracts images and creates thumbnail version
- Turns the email content into a Jerky-style markdown blog post
- Uploads the post and images to Dropbox# Example
```
export OUT_DIR=/tmp/blog
export MEDIA_PATH=media
export POSTS_PATH=_postsmkdir -p $OUT_DIR/$MEDIA_PATH
mkdir -p $OUT_DIR/$POSTS_PATHexport DROPBOX_REFRESH_TOKEN=sup3rsekr3t
export IMAP_PASSWORD=trustno1dropblog [email protected] -e
```This will write files into `/tmp/blog/media` and `/tmp/blog/_post`
and then try to upload them to Dropbox.## Output
```
$ cat /tmp/blog/_posts/2020-01-15-colours.md
---
title: |
colours
author: Richard Dallaway
date: 2020-01-15 21:26
layout: post
comments: true
permalink: /colours
---# Usage
```
% ./target/release/dropblog --help
dropblog 2.0.2USAGE:
dropblog [FLAGS] [OPTIONS] --dropbox-app-key --dropbox-app-secret --media-path --out-dir --password --posts-path --userFLAGS:
-e, --expunge Archive the email after processing
--show-outline Outline the structure of the email as additional output
-h, --help Prints help information
-V, --version Prints version informationOPTIONS:
--hostname
IMAP hostname to connect to [env: IMAP_HOSTNAME=] [default: imap.gmail.com]--port IMAP port number [env: IMAP_PORT=] [default: 993]
--user
Email address (or user account) to check on the IMAP server [env: IMAP_USER=]--password Password for authentication [env: IMAP_PASSWORD]
-m, --mailbox [default: INBOX]
--dropbox-refresh-token Dropbox refresh token [env: DROPBOX_REFRESH_TOKEN]
--dropbox-code
Dropbox code (supplied by user, used once to fetch a refresh token) [env: DROPBOX_CODE]--dropbox-app-key
Dropbox app key (also called client ID) [env: DROPBOX_APP_KEY=]--dropbox-app-secret
Dropbox app secret (also called client secret) [env: DROPBOX_APP_SECRET]--out-dir Existing directory for writing content [env: OUT_DIR=]
--media-path Path into media relative to OUT_DIR [env: MEDIA_PATH=]
--posts-path Path into posts relative to OUT_DIR [env: POSTS_PATH=]
-w, --width Thumbnail width [default: 500]```
# Set up
## Create a dropbox app
You need to create a Dropbox app for yourself, and note the app key and app secret (also called client id and client secret).
[console]: https://www.dropbox.com/developers/apps
## Dropbox offline OAuth dance
You need to generate a long-lived refresh token. This is described in "Implement refresh tokens" at .
The sequence of commands (once you have an app key and secret) is:
1. Set up common environment variables (see `cargo run -- --help` for how to pass them as command line arguments):
```
export OUT_DIR=tmp
export MEDIA_PATH=media
export POSTS_PATH=_postsexport [email protected]
export IMAP_PASSWORD=???export DROPBOX_APP_KEY=???
export DROPBOX_APP_SECRET=???
```2. Run `cargo run` to get the URL for authentication. Follow this URL in a browser, and note the code Dropbox gives you.
3. Run again supplying the code Dropbox gave you:
```
cargo run -- --dropbox-code=CODEHERE
```4. The above gives you a refresh code. You can use this to write posts to Dropbox. E.g.,
```
cargo run -- --dropbox-refresh-token=TOKEN_HERE
```...and that's the command you can run repeatedly (e.g., in a cron job).
## Dependencies
[imagemagik]: https://imagemagick.org/
- You need `convert`, `mogrify` and `identify` from [Imagemagik] on your path.
# Build notes
## Docker build
```
docker build -t dropblog .
docker run -it --rm --name running-dropblog dropblog
```## Linux binary
As we use rustls, the following is the fastest way to build for Linux on macOS:
```
cat .envrc
export CC_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-gcc
export CXX_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-g++
export AR_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-ar
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcccargo build --target x86_64-unknown-linux-gnu --release
```The binary will be in `target/x86_64-unknown-linux-gnu/release/`.
## Alternative Linux binary
As a backup the following is also possible:
```
docker pull clux/muslrust
docker run -v $PWD:/volume -i -t clux/muslrust cargo build --release
```The binary will be:
```
target/x86_64-unknown-linux-musl/release/dropblog
```