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

Extract All URLs from a message and return an array. #142

Open
MHillyer opened this issue Feb 23, 2024 · 1 comment
Open

Extract All URLs from a message and return an array. #142

MHillyer opened this issue Feb 23, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@MHillyer
Copy link
Collaborator

MHillyer commented Feb 23, 2024

In speaking with Abusix, their engineer informed us that one thing that would greatly help those using the MTA for anti-abuse, and which is not really available in existing MTAs, is the ability to call a function that would extract all URLs from an email message and return them, making it much easier to do certain lookups and analysis when deciding on the disposition of the message.

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

wez commented Sep 16, 2024

gist of implementation is:

  • See this method for inspiration on how to trigger the message parser:
    pub fn append_text_plain(&self, content: &str) -> anyhow::Result<bool> {
    let data = self.get_data();
    let mut msg = MimePart::parse(data.as_ref().as_ref())?;
    let parts = msg.simplified_structure_pointers()?;
    if let Some(p) = parts.text_part.and_then(|p| msg.resolve_ptr_mut(p)) {
    match p.body()? {
    DecodedBody::Text(text) => {
    let mut text = text.as_str().to_string();
    text.push_str("\r\n");
    text.push_str(content);
    p.replace_text_body("text/plain", &text);
    let new_data = msg.to_message_string();
    self.assign_data(new_data.into_bytes());
    Ok(true)
    }
    DecodedBody::Binary(_) => {
    anyhow::bail!("expected text/plain part to be text, but it is binary");
    }
    }
    } else {
    Ok(false)
    }
    }
  • use a some means to match and extract all urls from the message
  • return it as an array
  • expose it to lua as a method of the message object

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

2 participants