About this topic

  • Posted by andrew_s1 4 months ago. There are 18 posts. The latest reply is from andrew_s1.
  1. Thank you Rob - good work on taking postie forward.

    I'm working on a plugin to link mailman to buddypress.
    I've written some thoughts on the process.
    I think Postie will do the email-> wordpress job I need, with minor mods. It's a very impressive plugin.

    I'm wrestling with the HEAD revision of postie in the SVN now - it wasn't possible to change settings on a clean install, so I've done some patching to fix that. [edit - just tried another clean install, and it worked fine, as long as I commented out postie-functions.php line 5 - Suhosin does not like that ini_set]

    Anyway, just wanted to check in, let you know what I'm working on.

  2. I've taken a pass at rationalising the options handling, and getting it all working with register_settings and the like, leaving all the database updating to wordpress.

    Here's my diff file

    It touches quite a lot of code - sorry about that. But it does knock the options handling into shape. It strips out all the old database-options handling, apart from the bit that's run at plugin activation, that imports settings from the old database-options. All that's now in the activation call within postie.php.

    I hope this is useful. Feedback very welcome. I don't have legacy postie configs to test it against, but will happily fix any bugs arising from my changes.

  3. Andrew,

    Thanks for the changes. I will look at them soon. I have been working on updating the settings mechanisms. I couldn't get register_settings() to work, but I am using settings_fields. What is the difference really?

    Rob

  4. register_setting allows you to use the WP backend to do these useful tasks:
    database updates, some validation and sanitisation, and handling the _nonce_ fields for security.

    EDIT2: Whereas I add settings_fields('postie-settings') into the main options form, to generate the _nonce_fields for security.

    I did have some difficulty the first time I tried to get register_setting to work, and had to try a few different combinations.

    The key is that (as you can see in my patch) you need to run the register_setting call from a function that is hooked into admin_init. So, in the main body of postie.php I add:

    if (is_admin()) {
      add_action('admin_init','postie_admin_settings');
    }

    and in postie-functions.php, I add:

    function postie_admin_settings() {
      register_setting('postie-settings','postie-settings','postie_validate_settings');
    }

    where the last argument is a validation function.
    Then all of the handling of $_POST variables can be removed from the options form, and options can be submitted/retrieved just using get_option('postie-settings') and update_option('postie_settings,$options);

    NB that in all three cases, register_setting, get_option and update_option, it's singular not plural (e.g. 'option' not 'options') - that catches me out every time!

    But in the case of settings_fields, it's plural "settings" (and "fields"), not singular "setting"!

    Regards,
    Andrew

  5. patch updated here.

    About the options that were previously stored as arrays (e.g. smtp or sig_patterns_list), is it better to store those as arrays, or as strings with array elements joined with a \n separator? From the code, it looks like you're switching to the latter - have I got that right?

    Regards,
    Andrew

  6. Andrew,

    I was switching these to strings because I could not get nested serialized arrays to work. I haven't gotten a chance to look at your patch yet. I was moving towards storing all postie settings in one serialized array, so that there would only be one database lookup necessary. Is that the way register_settings works too?

  7. Hi Rob,
    register_setting will do all the serialisation for you.

    The good news is that I really didn't need to touch much of your options code to get all that working, with serialised options - I just adjusted the place where register_setting was called, and tweaked a couple of other things. Most of my patch is concerned with tidying up the handling of default options, and stripping out the old database-handling of the old-format options.

    I think we can get serialised arrays to work. If we can, would you prefer to stick with those? They all get turned into arrays at processing-time anyway. They'd just get turned into \n-delimited strings for processing in the textarea on the options screen.

    Regards,
    Andrew

  8. I had a chance to look over the patch a little bit. It looks good for the most part. The main thing that I would change is to undo any changes you made to the GetConfig (and GetDBConfig) functions. Under the new settings scheme, I don't use that function any more, except to convert the old-style settings into the new style. So it needs to be left untouched in order to smoothly transition from old style to new style settings.

    If you can get nested serialized arrays to work, that would be great.

    Rob

  9. OK, I'll have a go at this, and get back to you tomorrow, all being well.

    Re GetConfig/GetDBConfig - as the only place the old config is used, is in the activation routine, I moved the relevant code into function activate_postie() in postie.php. But I'll reverse those particular changes, so that you & all postie users can be confident that their old settings will be carried over securely.

    Regards,
    Andrew

  10. revised patch here, with nested serialized arrays, as discusssed.

    I'm still testing: it seems stable so far...

  11. Andrew,

    I have committed your changes into HEAD now. I also fixed the cron updating, which you had noted was not working. Thanks so much for your help. I apologize for the ugly code. Quite a few people had their hands on postie before me, and it also was dormant for a couple years. I have slowly been working on bringing it back up to wordpress standards.

    The reason I started hacking postie in the first place was to use it with mailman lists for a friend. I had it working fairly well, but he never ended up really using it.

    Rob

  12. Thanks for that, Rob, that's great.
    I saw that "html purify" was top of the TODO list in postie-functions: this patch should do it: http://wordpress.pastebin.ca/1843301

    Regards,
    Andrew

  13. Andrew,

    Thanks for that. However, I think that someone had requested this awhile ago, to use this:
    http://htmlpurifier.org/

  14. Ah, ok, I'll just back away from that one slowly then!

  15. Sorry, I let a small problem through with the smtp filter. This patch fixes it, as well as adding in a new feature: if a postie filter returns false, then the email is not turned into a wordpress post: this provides a way for the filter to suppress an email.

  16. Revised patch - sorry for pasting direct code, but pastebin's not online at the moment. Features are as above: smtp fix, and adding a way for a plugin filter to block a post completely. Additionally, this fixes the handling of :end, which isn't handled well for HTML posts currently.

    Index: postie-functions.php
    ===================================================================
    --- postie-functions.php	(revision 220496)
    +++ postie-functions.php	(working copy)
    @@ -173,12 +173,21 @@
           'post_status' => $post_status
       );
       $details = apply_filters('postie_post', $details);
    -  DisplayEmailPost($details);
    -  PostToDB($details,$isReply, $post_to_db,
    -      $custom_image_field);
    -  if ($confirmation_email)
    -    MailToRecipients($mimeDecodedEmail, false,
    -        array($postAuthorDetails['email']), false, false);
    +	if ( empty( $details ) ) {
    +		// It is possible that the filter has removed the post, in which case, it should not be posted.
    +		// And if we created a placeholder post (because this was not a reply to an existing post),
    +		// then it should be removed
    +		if ( !$is_reply ) {
    +			wp_delete_post($post_id);
    +		}
    +	} else {
    +		DisplayEmailPost( $details );
    +		PostToDB( $details,$isReply, $post_to_db, $custom_image_field );
    +		if ($confirmation_email) {
    +			MailToRecipients( $mimeDecodedEmail, false,
    +					array($postAuthorDetails['email']), false, false );
    +		}
    +	}
     }
     /** FUNCTIONS **/
    
    @@ -902,10 +911,11 @@
    
     function checkSMTP($mimeDecodedEmail, $smtpservers) {
    
    -if ( empty( $smtpservers ) ) return true;
    -
    +  if ( empty( $smtpservers ) ) return true;
       foreach ( (array) $mimeDecodedEmail->headers['received'] as $received ) {
    -		if ( in_array( strtolower($received), $smtpservers ) ) return true;
    +		foreach ($smtpservers as $smtp) {
    +			if ( stristr( $received, $smtp ) !== false ) return true;
    +		}
     	}
       return false;
     }
    @@ -954,20 +964,12 @@
     * @param string
     * @param filter
     */
    -function EndFilter( &$content,$filter) {
    -$arrcontent = explode("\n", $content);
    -$i = 0;
    -for ($i = 0; $i<=count($arrcontent); $i++) {
    -  $line = $arrcontent[$i];
    -  $nextline = $arrcontent[$i+1];
    -      if (preg_match("/^$filter/",trim($line))) {
    -          //print("<p>Found in $line");
    -          break;
    -      }
    -  $strcontent .= $line ."\n";
    +function EndFilter( &$content, $end ) {
    +	$pos = strpos( $content, $end );
    +  if ( $pos === false )
    +      return $content;
    +	return $content = substr($content, 0, $pos);
     }
    -  $content = $strcontent;
    -}
    
     //filter content for new lines
     function FilterNewLines ( $content, $convertNewLines=false ) {
  17. I put those changes into trunk.

  18. Thanks Rob.

RSS feed for this topic

Have you read the FAQ?
Have you tried the latest development version (at the bottom)?

Reply

You must log in to post.