Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rspamd support #266

Open
MHillyer opened this issue Sep 9, 2024 · 2 comments
Open

rspamd support #266

MHillyer opened this issue Sep 9, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@MHillyer
Copy link
Collaborator

MHillyer commented Sep 9, 2024

No description provided.

@MHillyer MHillyer converted this from a draft issue Sep 9, 2024
@MHillyer MHillyer added this to the Fall 24 Release milestone Sep 9, 2024
@MHillyer MHillyer added the enhancement New feature or request label Sep 11, 2024
@wez wez removed their assignment Sep 16, 2024
@djc
Copy link
Contributor

djc commented Oct 20, 2024

@wez here's my super minimal rspamd client:

pub struct RspamdClient {
    client: reqwest::Client,
    url: String,
}

impl RspamdClient {
    pub fn new(rspamd_origin: &str) -> anyhow::Result<Self> {
        Ok(Self {
            client: reqwest::Client::new(),
            url: format!("{}/checkv2", rspamd_origin),
        })
    }

    pub async fn check(
        &self,
        from: &str,
        ip: IpAddr,
        helo: Option<&str>,
        message: Bytes,
    ) -> Result<Response, reqwest::Error> {
        let mut request = self
            .client
            .get(&self.url)
            .header("From", from)
            .header("IP", ip.to_string());
        if let Some(helo) = helo {
            request = request.header("Helo", helo);
        }

        request
            .body(message)
            .send()
            .await?
            .error_for_status()?
            .json::<Response>()
            .await
    }
}

#[derive(Deserialize)]
pub struct Response {
    pub score: f32,
}

@wez
Copy link
Collaborator

wez commented Oct 21, 2024

Thanks! I think we could fairly trivially write a little lua script that lives in assets/policy-extras/rspamd.lua that uses https://docs.kumomta.com/reference/kumo.http/build_client/ (which is a wrapper around reqwest) under the covers. Just pass in a Message and it can extract the ip from the metadata and the from field from the message sender. https://docs.kumomta.com/reference/connectionmeta/

We don't currently capture the ehlo string in the connection metadata, but we probably should and then we could use that here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

3 participants