commit - 38d37de2f174a9f5f7bc79467d34f4fbe7a91e8d
commit + f931592c6893feb74ada3d43ecee5d4a2f3353d3
blob - 6834e633d3ce472cb4e6a18b2bd75de2e6a9b34c
blob + f5db540236093c106db82cc03096ed893dbd7b4d
--- docs/rss-email.1.scd
+++ docs/rss-email.1.scd
*--dry-run*
Don't send any emails, just fetch new feed items and mark them as read
+*--no-fetch*
+ Don't fetch any new feed items, just send emails of unsent posts
+
*--urls* _path_
Specifies a custom urls file to be used instead of the default one at
*$XDG_CONFIG_HOME/rss-email/urls*
blob - f7ea58260efe31bcbef82617a7183340f25972da
blob + 15c82241556da71af597256b977c64a5895bb81d
--- src/cli.rs
+++ src/cli.rs
/// Don't send emails
#[clap(long, value_parser)]
pub dry_run: bool,
+ /// Don't fetch feeds
+ #[clap(long, value_parser)]
+ pub no_fetch: bool,
/// Be verbose. Pass multiple times to increase verbosity.
#[clap(short, action = clap::ArgAction::Count)]
pub verbose: u8,
blob - 1563451cab920c6f5c7f26af86242855400b1b4a
blob + d46d7749a93da15b759f443de302779d14f7635e
--- src/config.rs
+++ src/config.rs
pub database_path: String,
pub urls_path: String,
pub dry_run: bool,
+ pub no_fetch: bool,
pub mail_from: String,
pub mail_to: String,
pub smtp_user: String,
database_path: cli.database_path,
urls_path: cli.urls_path,
dry_run: cli.dry_run,
+ no_fetch: cli.no_fetch,
..Default::default()
};
blob - 6921a225e360fb04b65ee9b0143ffe15773917af
blob + 94fa3d15a1396682a4eee9b2de0172d4d5315d3e
--- src/main.rs
+++ src/main.rs
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let config = Arc::new(AppConfig::new()?);
- let urls = BufReader::new(
+ let urls: Vec<String> = BufReader::new(
File::open(config.urls_path.as_str())
.context(format!("File {:?} does not exist", &config.urls_path))?,
)
.lines()
.map(|l| l.unwrap())
- .filter(|l| !l.starts_with('#'));
+ .filter(|l| !l.starts_with('#'))
+ .collect();
let db_path = &config.database_path;
debug!("Establishing connection to database at {:?}", db_path);
sqlx::migrate!("./migrations").run(&pool).await?;
- let mut set = JoinSet::new();
- for u in urls {
- set.spawn(async move { feed::fetch_new(u).await });
+ if !config.no_fetch {
+ fetch_feeds(urls, &pool).await?;
+ } else {
+ info!("Not fetching any feeds as \"--no-fetch\" has been passed");
}
- while let Some(new) = set.join_next().await {
- let posts = new??;
-
- for i in posts.into_iter() {
- let conn = pool.acquire().await?;
- db::insert_item(conn, &i).await.context(format!(
- "Unable to insert item from {:?} with GUID {:?}",
- i.url, i.guid
- ))?;
- }
- }
-
let results = sqlx::query_as!(
models::Post,
"select * from posts where sent != true order by pub_date desc"
Ok(())
}
+async fn fetch_feeds(urls: Vec<String>, pool: &sqlx::Pool<Sqlite>) -> anyhow::Result<()> {
+ let mut set = JoinSet::new();
+ for u in urls {
+ set.spawn(async move { feed::fetch_new(u).await });
+ }
+
+ while let Some(new) = set.join_next().await {
+ let posts = new??;
+
+ for i in posts.into_iter() {
+ let conn = pool.acquire().await?;
+ db::insert_item(conn, &i).await.context(format!(
+ "Unable to insert item from {:?} with GUID {:?}",
+ i.url, i.guid
+ ))?;
+ }
+ }
+
+ Ok(())
+}
+
async fn send_post<'a, E>(
conn: E,
mailer: AsyncSmtpTransport<Tokio1Executor>,
Mail::new(post.title, post.content, post.url)
.send_email(from, to, &mailer)
.await?;
+ } else {
+ info!("Not sending any emails as \"--dry-run\" has been passed");
}
sqlx::query!("update posts set sent = true where guid = ?", post.guid)