• Resolved marcnyc

    (@marcnyc)


    Hello,
    I LOVE postie! Thank you!

    I make great use of the feature that derives the category from the email’s subject when a word that matches the category slug is found before a semi-colon, like:
    category: Subject

    Because I use Postie to moderate user-submitted content that comes to me via email, every time I forward an email the subject becomes:
    fwd: category: Subject

    Is there a way to tell Postie to ignore Fwd: and start “processing” the subject after that?
    I thought about renaming my category from category to Fwd: category but that is not very elegant and might break with the space anyway, and make a mess of permalinks…

    And if there is no way, then I’d like to make this a feature request pretty please!!!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Wayne Allen

    (@wayneallen-1)

    You could use square brackets or dashes as described here https://postieplugin.com/faq/override-post-categories/

    [category] subject
    -category- subject

    It does leave behind the “fwd:” so that isn’t great. Although you could create a generic category with the slug “fwd” that works pretty well.

    Thread Starter marcnyc

    (@marcnyc)

    I would like a way to get rid of the Fwd:, square brackets or semi-colon…

    Plugin Author Wayne Allen

    (@wayneallen-1)

    Not sure I follow.

    Please describe your ideal solution regardless of what Postie can do today.

    Thread Starter marcnyc

    (@marcnyc)

    Ok, let’s say I was coder for Postie, I would add a Yes/No option in the Settings page to “Remove ‘Fwd:’ from Subject field” and that option would trigger this if/then statement:

    // if subject starts with "fwd:" or "Fwd:"
    if ( substr(strlolower($subject), 0, 4) === 'fwd:' ) {
        $subject = substr($subject, 4); // remove first 4 characters from subject
        $subject = trim($subject); // remove space at the beginning of subject line (because usually the subject of a forwarded email will be "Fwd: Category: Subject")
    }
    // then continue the logic on the subject (match category before semi-colon, remove category, etc...

    I hope that makes sense

    Thread Starter marcnyc

    (@marcnyc)

    just curious, any hope this might be implemented in a future version? is there an “official” way to submit a feature request for this?

    Plugin Author Wayne Allen

    (@wayneallen-1)

    I was working on a way for you to do this and got distracted while testing it.

    Today I released 1.9.53 of Postie which includes a new filter for altering the subject line. See https://postieplugin.com/filter-postie_subject/

    Thread Starter marcnyc

    (@marcnyc)

    Thank you for taking my feature request to heart.
    I’ve upgraded to the new postie just now but I don’t see the option. Is it in the backend or is it something I need to hard-code into the plugin?
    If so where would I put and how do I ensure I don’t loose that when I upgrade to the latest Postie?

    Plugin Author Wayne Allen

    (@wayneallen-1)

    Not an option, you have to write some code.

    See https://postieplugin.com/extending/

    The create a file filterPostie.php in the wp-content directory.

    Put this in the file (untested):

    <?php
    add_filter('postie_subject', 'my_postie_subject');
    
    function my_postie_subject($subject) {
    if ( substr(strlolower($subject), 0, 4) === 'fwd:' ) {
        $subject = substr($subject, 4); // remove first 4 characters from subject
        $subject = trim($subject); // remove space at the beginning of subject line (because usually the subject of a forwarded email will be "Fwd: Category: Subject")
        return $subject;
    }
    }
    Thread Starter marcnyc

    (@marcnyc)

    Thank you for giving us this feature.

    Your filter does work, and so does my function, except for a small typo (I wrote strlolower, instead of strtolower). So for those who might stumble on this post looking to do the same, here is the corrected and tested function:

    I wanted to report back that your filter works and my function does too, with the exception of a small typo (I wrote strlolower, instead of strtolower), so for those who might stumble on this post, the correct function for the filterPostie.php file is:

    
    <?php
    add_filter('postie_subject', 'my_postie_subject');
    
    function my_postie_subject($subject) {
       // match the first four characters from the subject (works with Gmail, other email clients might prepend "Fw:" or "Forward:" or something else) after making it all lowercase to match both "Fwd:" or "fwd:"
       if ( substr(strtolower($subject), 0, 4) === 'fwd:' ) {
        $subject = substr($subject, 4); // remove first 4 characters from subject
        $subject = trim($subject); // remove space at the beginning of subject line (because usually the subject of a forwarded email will be "Fwd: Category: Subject")
        return $subject;
       }
    }
    ?>
    • This reply was modified 4 years, 5 months ago by marcnyc.
    Plugin Author Wayne Allen

    (@wayneallen-1)

    Excellent. Thanks for sharing.

    Thread Starter marcnyc

    (@marcnyc)

    Hey everyone, I wanted to post a correction to my code…

    <?php
    add_filter('postie_subject', 'my_postie_subject');
    
    function my_postie_subject($subject) {
    	// match the first four characters from the subject (works with Gmail, other email clients might prepend "Fw:" or "Forward:" or something else) after making it all lowercase to match both "Fwd:" or "fwd:"
    	if ( substr(strtolower($subject), 0, 4) === 'fwd:' ) {
    		$subject = substr($subject, 4); // remove first 4 characters from subject
    		$subject = trim($subject); // remove space at the beginning of subject line (because usually the subject of a forwarded email will be "Fwd: Category: Subject")
    	}
    	return $subject;
    }
    ?>

    Initially I had the return $subject; line in side the if statement which broke my system because whenever the email was NOT being forwarded it now lost its subject, so that line needs to be last so the subject is returned even if the email is not forwarded.
    Hope that helps

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘question / feature request about categories in subject line’ is closed to new replies.