Jump to content

ProcessEmailToPage


Pete

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

Link to comment
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"?

Link to comment
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

Link to comment
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
Link to comment
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.

Link to comment
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

Link to comment
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?

Link to comment
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>'));
}
Link to comment
Share on other sites

  • 4 months later...

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. 

Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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

Link to comment
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.

Link to comment
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.

Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...