Jump to content
Pete

ProcessEmailToPage

Recommended Posts

Ok sorted it out to use the Username on the Emailadress field get it working....but the script holds on this error

Error: Call to a member function add() on a non-object (line 360 of /var/www/webxxx/html/rezepte/site/modules/ProcessEmailToPage/ProcessEmailToPage.module)

This error message was shown because you are logged in as a Superuser. Error has been logged. 

it's this lines:

// Iterate through any attachments if we have an images field for this page
if (isset($message['attachment'])) {
    foreach ($message['attachment'] as $attachment) {
        // We need to make the filename safe before continuing
        $attachment['filename'] = $this->sanitizer->pageName($attachment['filename'], true);
        // Write the file directly to the /files/pageid/ folder, then add it to ProcessWire (adds info to the DB)
        if(strlen($attachment['data'])>0){
            file_put_contents($page->images->path . $attachment['filename'], $attachment['data']);
            $page->images->add($page->images->path . $attachment['filename']);
        }
    }
    $page->save();
}

i''ve send a normal email via handy (no html header, footer, signature) with an image attachment....

regards mr-fan

Share this post


Link to post
Share on other sites

@mr-fan,

It looks like you are using my latest version of this module - I was playing around with attachments and embedding them into RTE fields. I think the error is coming from the images field. Does your page have an images field? Is it named "images"?

Share this post


Link to post
Share on other sites

....forgot top tell that i use the lastet version from here...

yes there is a imagefield but named "Bilder" .....is this hardcoded somewhere?

-> and yes until this line the script works and setup the page correctly!!

Thank and regards mr-fan

Share this post


Link to post
Share on other sites

Great - tested -> works....asap i will provide german translation and if some others test the new functions may update this version....looks really good!

Thank you adrian!

If needed i could send you one of the favorite recipes translated.....;)

  • Like 1

Share this post


Link to post
Share on other sites

@mr-fan - thanks for testing. I am not sure this module is getting a lot of use, so I am not expecting many others to test so maybe I'll just submit a PR to Pete to get this new version committed to Github and available from the modules directory.

Share this post


Link to post
Share on other sites

...i will test it with different mailprogs and settings....i find this is a very usefull addon!

but until now it works like a charm!

one thin would maybe a nice option....that may could easy done?

if some emailclient use html tags and u don't want them in the textarea just the clean text transmitted - is there a chance to get a flag for striptags? for the body field and the additional fields - could be a general setting, too.

This would provide more secure to get the content in a usable format.

Best Regards mr-fan

Share this post


Link to post
Share on other sites
if some emailclient use html tags and u don't want them in the textarea just the clean text transmitted - is there a chance to get a flag for striptags? for the body field and the additional fields - could be a general setting, too.

It already strips out all html tags except 

<br><br /><p><strong><b><a><img>

Although looking at this, it should probably be expanded to include <em> and maybe even <b> and <i>

Does this take care of your request, or is it something else I am not understanding? Or is the stripping of tags not working for you?

Share this post


Link to post
Share on other sites

Oh that explains some questions....i use many different textareas for testing - if i test modules i don't only break it down to just my usecase since i'm testing addons in my former cms for a long time and for many devs.

(making stupid userthings is one of my strenght - so i'm finding a way down to murphy's law.)

i used textareas with different markups like MarkDown and there i was getting tags that are allowed <br> and so on -> MarkDown isn' working korrekt there and show the tags in cleartext.

But this is a very special test/usecase.

i found the code for this - if someone read's this threat he could finaly set it for such usecases to get special results.

Thanks again for your work and response!

(while i'm testing new versions i'll learn a lot from the changes and i enjoy it since modules are written in a really easy way in processwire so that a php noob could understand OOP that simple make sence and isn't that hard or abstract anymore!!)

// Run it through ProcessWire's sanitizer for good measure - restricts only to basic HTML tags
if($this->embedImages == 'TRUE' && $category->imagesField != ''){
	$message_body = $this->sanitizer->textarea($message_body, array('allowableTags' => '<br><br /><p><strong><b><a><img>'));
}
else{
	$message_body = $this->sanitizer->textarea($message_body, array('allowableTags' => '<br><br /><p><strong><b><a>'));
}

Share this post


Link to post
Share on other sites

Great module, however I'm having a problem with attachments.  I have the original image field, however the attachments don't show up.

@Adrian, Is the fork that you are working on the same as what's published on the ProcessWire page for Process Email To Page?

Much Thanks to @Pete and @Adrian for working on this module. 

Share this post


Link to post
Share on other sites

Hi Charles,

I think my fork is well ahead on the attachment functionality. In my limited tests I think it was working in all situations, but I might have missed something - so many different things to consider with different email clients. Anyway, please test my version and let us know how it goes for you.

  • Like 1

Share this post


Link to post
Share on other sites

Adrian,

Your changes made the difference.  It works great now. Thanks a million.

Best Regards,

Charles

  • Like 1

Share this post


Link to post
Share on other sites

Is there a way to get some additional message header information (i.e the FROM Address and the email DATE) to show up and could possibly be mapped to a PW field?

Share this post


Link to post
Share on other sites

Is there a way to get some additional message header information (i.e the FROM Address and the email DATE) to show up and could possibly be mapped to a PW field?

This should be very easy to add. Sorry I don't have time in the next few days and so it will probably have to wait till the new year, but if you are in a hurry, take a look at:

http://flourishlib.com/docs/fMailbox

That shows what you need to add: "received" (date) and "from". If you decide to add this support before I get a chance to look into, please send me a PR :)

It seems like going forward, this module needs to be further configurable so you can decide what fields you want stored and which PW fields you want them added to.

  • Like 1

Share this post


Link to post
Share on other sites

Hi again - I have just committed an update to my fork that supports capturing the received date and the from address (actually I parsed out the name associated with the email address). Is that what you are looking for, or do you actually want the email address? If so, I might need to add an option to choose what is required.

Anyway, let me know if things work for you.

  • Like 1

Share this post


Link to post
Share on other sites

Adrian,

You are indeed a miracle worker and a very talented developer.  Thanks for updating this module!  The new changes are immediately useful and I owe you a depth of gratitude.

Best Regards,

Charles

  • Like 1

Share this post


Link to post
Share on other sites

I think you are way too kind, but I am very glad I could help out a little. Please let me know if you do need access to the from email address, rather than the name and I'll sort that out.

Share this post


Link to post
Share on other sites

Adrian,

From the limited testing I have done so far, it is giving me the email address.  I need to test from other email providers other than Yahoo to see what shows up.  Either way, this is more than what I had yesterday.

I believe that the more functionality that this module has (being able to map email metadata with actual PW fields), the better it will serve the diverse needs of the PW community.  I also hope we can get these changes merged with the published version on the PW website.

Thanks again, as you have made my day. 

Best Regards,

Charles

Share this post


Link to post
Share on other sites

Interesting - maybe the account you are sending from doesn't have a name in the from address field, eg: "John Smith" <john@example.com>

I think it would be great to be able to match up the sender with a PW user account, most likely via their email address. This is easy to do, I just don't know what most people would want and don't want to end up with too many config options. 

I am also not sure just how many people are actually using this module, especially given how effective the PW admin is on mobile devices.

Anyone else out there have any thoughts on this - are others using this module? Should it simply populate a text field with the sender's name/email address, or try to match up to a PW user account? I might need to do some testing of the returned data to see what is actually being returned and match if possible.

Share this post


Link to post
Share on other sites

Ok, I first had the From field mapped to a PW Email Field.   My Yahoo account has the email and name both mapped to my email address, hence that's why the email address showed up.  I then tested on Gmail and MSN and nothing showed up.  I then understood the problem and changed the PW field to a text field and then the name showed up when importing Yahoo, Gmail and MSN emails.

Operator error on my part.  The Name field works great.

Share this post


Link to post
Share on other sites

That makes sense - thanks for clarifying the reason for the email address actually being populated. I have just pushed another update that now has three separate options: name, email, user

The first two are obvious. The third one (user) needs to be pointed to a page field that has "user" as the template of selectable pages. Also, you might want to set Label Field to "name" rather than the default "title". When the page is created, this field will grab the user from the list of PW users based on the email address, which means you then have full access to all other fields in the user template. It also sets the created and modified users on the Settings tab to this user. This should make it pretty powerful for emailing in blog posts and the like.

I probably need to add some checks to deal with the email address not matching a PW user, but I'll wait for the next update for that.

Let me know how it works for you.

This is what the result looks like on the new page:

post-985-0-24194400-1419654832_thumb.png

post-985-0-65063700-1419657201_thumb.png

  • Like 1

Share this post


Link to post
Share on other sites

FYI, I had a problem with the body text not showing up.  I looked at your code and ended up doing a diff to see what was going on.  Somehow the following code was dropped from the update:

$page->{$category->bodyField} = $body;

I added this code to the recent update and then the body text showed up again.

post-756-0-98398500-1419658355_thumb.png

  • Like 1

Share this post


Link to post
Share on other sites

FYI, I had a problem with the body text not showing up.  I looked at your code and ended up doing a diff to see what was going on.  Somehow the following code was dropped from the update:

Oops - sorry about that - fixed that and added a couple of checks around the user detection.

I am thinking the next important addition is treating attached images differently to attached files.

  • Like 1

Share this post


Link to post
Share on other sites

I have just committed another update that has a separate field for attachments that are not images. An email can now contain both and they will be treated separately with images being embedded in the body text when appropriate, but keeping other file types only a "attachments" and stored in the selected files field.

  • Like 1

Share this post


Link to post
Share on other sites

I finally got around to do some thorough testing of the new capabilities.  I tested on Customized Email, Gmail, Yahoo and MSN (Outlook) and everything works great.

I especially like how you treated the attachments and split out the From and email address.  Thanks again for all of the enhancements.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      Repeater Images
      Adds options to modify Repeater fields to make them convenient for "page-per-image" usage. Using a page-per-image approach allows for additional fields to be associated with each image, to record things such as photographer, date, license, links, etc.
      When Repeater Images is enabled for a Repeater field the module changes the appearance of the Repeater inputfield to be similar (but not identical) to an Images field. The collapsed view shows a thumbnail for each Repeater item, and items can be expanded for field editing.
      Screencast

      Installation
      Install the Repeater Images module.
      Setup
      Create an image field to use in the Repeater field. Recommended settings for the image field are "Maximum files allowed" set to 1 and "Formatted value" set to "Single item (null if empty)". Create a Repeater field. Add the image field to the Repeater. If you want additional fields in the Repeater create and add these also. Repeater Images configuration
      Tick the "Activate Repeater Images for this Repeater field" checkbox. In the "Image field within Repeater" dropdown select the single image field. You must save the Repeater field settings to see any newly added Image fields in the dropdown. Adjust the image thumbnail height if you want (unlike the core Images field there is no slider to change thumbnail height within Page Edit). Note: the depth option for Repeater fields is not compatible with the Repeater Images module.
      Image uploads feature
      There is a checkbox to activate image uploads. This feature allows users to quickly and easily add images to the Repeater Images field by uploading them to an adjacent "upload" field.
      To use this feature you must add the image field selected in the Repeater Images config to the template of the page containing the Repeater Images field - immediately above or below the Repeater Images field would be a good position.
      It's recommended to set the label for this field in template context to "Upload images" or similar, and set the visibility of the field to "Closed" so that it takes up less room when it's not being used. Note that when you drag images to a closed Images field it will automatically open. You don't need to worry about the "Maximum files allowed" setting because the Repeater Images module overrides this for the upload field.
      New Repeater items will be created from the images uploaded to the upload field when the page is saved. The user can add descriptions and tags to the images while they are still in the upload field and these will be retained in the Repeater items. Images are automatically deleted from the upload field when the page is saved.
      Tips
      The "Use accordion mode?" option in the Repeater field settings is useful for keeping the inputfield compact, with only one image item open for editing at a time. The "Repeater item labels" setting determines what is shown in the thumbnail overlay on hover. Example for an image field named "image": {image.basename} ({image.width}x{image.height})  
      https://github.com/Toutouwai/RepeaterImages
      https://modules.processwire.com/modules/repeater-images/
    • By EyeDentify
      Hello There Guys.

      I am in the process of getting into making my first modules for PW and i had a question for you PHP and PW gurus in here.

      I was wondering how i could use an external library, lets say TwitterOAuth in my PW module.
      Link to library
      https://twitteroauth.com/

      Would the code below be correct or how would i go about this:
      <?PHP namespace ProcessWire; /* load the TwitterOAuth library from my Module folder */ require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; class EyeTwitter extends WireData,TwitterOAuth implements Module { /* vars */ protected $twConnection; /* extend parent TwitterOAuth contructor $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); */ public function myTwitterConnection ($consumer_key, $consumer_secret, $access_token, $access_token_secret) { /* save the connection for use later */ $this->twConnection = TwitterOAuth::__construct($consumer_key, $consumer_secret, $access_token, $access_token_secret); } } ?> Am i on the right trail here or i am barking up the wrong tree?
      I don´t need a complete solution, i just wonder if i am including the external library the right way.
      If not, then give me a few hint´s and i will figure it out.

      Thanks a bunch.

      /EyeDentify
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
      As of 11 May 2019 ProcessWire versions earlier than 3.x are not supported
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend
       

×
×
  • Create New...