update by email

pbyjp
pbyjp's picture

Joined: 2002-11-12
Posts: 260
Posted: Thu, 2003-04-24 06:37

Will there be anyway to update the gallery by email?
If I used my mobile phone and sent a picture with some text from it?
This should be a great feature for G2, as you can imagine, if you ve read around these days, so many moblogs are poping up and the next version of movable type will have its own gallery, which could be bad news for Gallery. I hope you guys keep up with the features.
Good luck!
Paul

 
alindeman
alindeman's picture

Joined: 2002-10-06
Posts: 8194
Posted: Thu, 2003-04-24 22:10

We're not really competing with anyone :smile:

Anyway, this could be difficult because Gallery would have to have an interaction with a mail server. While this could be done, it would require yet another PHP extension to be compiled in (IMAP, which is available on some hosts, but not others) :sad: While it could be an optional feature, for versions only with IMAP compiled in, it also introduces a security concern -- how would we know that the email is coming from the person it's coming from (if you didn't already know, email addresses are trivial to spoof :sad:). Sounds like a good idea, but the implementation is more than trivial :sad:

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Thu, 2003-04-24 22:39

What you'd want is for Gallery to automatically add any photos added to a specific directory. Then leave it as a problem for the user to get the images there. And there are plenty of non-php ways to populate that directory.

[actually, if it was an automated process, none of it has to be in PHP]

 
pbyjp
pbyjp's picture

Joined: 2002-11-12
Posts: 260
Posted: Thu, 2003-04-24 23:26

Joan, would you be so kind and expend a bit on your previous message? I would love details. A friend of mine is working on it but finds it a bit hard cos there is no API for Gallery1 (as in, we didn t find one) and if you had any ideas of how to proceed, that would help a great deal.

 
pbyjp
pbyjp's picture

Joined: 2002-11-12
Posts: 260
Posted: Thu, 2003-04-24 23:43

Joan, would you be so kind and expend a bit on your previous message? I would love details. A friend of mine is working on it but finds it a bit hard cos there is no API for Gallery1 (as in, we didn t find one) and if you had any ideas of how to proceed, that would help a great deal. :wink:
cheers

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Fri, 2003-04-25 00:28

The Gallery 1 API is called "read all the files in the classes directory" :wink: as well as "util.php". Then read parts of "init.php" and "session.php".

97% of the functions are one-liners and pretty self-explanatory. (Just ask if there's something you need to understand but don't).

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Fri, 2003-04-25 01:15

Well, once you've got the file in a directory, you can call the following function for each file, then delete it.

And look at imap stuff on php.net for ways of getting it from your email. Or find a non-php script that does that, and it can write the files while the php script reads them.

(needs some work, especially the name and tag stuff)
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>
function log_image($file)
{
$log = new Album();
$err=$log->load("moblog");
if (!$err) {
return;
}
// quick hack: get $tag and $name code from save_photos.php
$tag = "jpg";
$name = "image";
$caption = "Emailed from my mobile at ".date("M d, Y H:i T", time());
$err = $log->addPhoto($file, $tag, $name, $caption);
$log->save();
return;
}
</TD></TR></TABLE><!-- BBCode End -->

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Fri, 2003-04-25 01:30

You might not need an IMAP daemon...

If you're halfway smart with <!-- BBCode Start --><A HREF="http://www.procmail.org/" TARGET="_blank">procmail</A><!-- BBCode End -->... you can filter out the incoming emails into a special directory.

Then have a separate script in your cron job to periodically scan your directory for new items, then add the files à la the addimages.pl script available in the Gallery User Guide.

If you're worried about forged emails... you could always generate a public/private keypair and only accept emails from people with an authorized encrypted message. (Think PGP/GPG).

But maybe I'm getting ahead of myself...

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Fri, 2003-04-25 01:58

Well, you'd never need an imap daemon, unless you were setting up a mailserver.

If you wanted to do the whole thing in PHP, here's another code fragment to get you started.
[it was actually part of an email gateway to phpBB, which worked but was never rolled out, but it shows you the principle of getting using php to read email]
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>
$mbox = imap_open ($server, $username, $password);

$num_msgs=imap_num_msg($mbox);
print "<p>num $num_msgs<p>";
for ($msg_count=1; $msg_count <= $num_msgs; $msg_count++)
{
$headers = explode("
", imap_fetchheader ($mbox, $msg_count));
foreach ($headers as $header_build)
{
$header_build = preg_replace("/:s/", ":", $header_build);
if (preg_match("/:/", $header_build))
{
$vars = preg_split("/:/", $header_build, 2);
if ($vars[1])
{
chop($header[trim($vars[0])] = trim($vars[1]));
}
}
}
$body = imap_fetchbody ($mbox, $msg_count, "1");
$attachments=false;
$structure = imap_fetchstructure ($mbox, $msg_count);
if ($structure.parts > 1)
{
$attachments=true;
}

if (emailToDB($header, $body, $attachments))
{
imap_delete($mbox, $msg_count);
}
}
imap_close($mbox);
</TD></TR></TABLE><!-- BBCode End -->

 
pbyjp
pbyjp's picture

Joined: 2002-11-12
Posts: 260
Posted: Fri, 2003-04-25 13:28

Wouaw, guys! I'm so glad about your input. Thank you milles fois.
My friend is gone on holiday for the next 2 weeks so can't really take in your input but he will as soon as he comes back. I think he has started working on smth in cgi script. I will definitely get him to have a look at the addimages.pl. I had already pointed him to the classes files and utils.php
We know that it's not impossible and that feels good. I feel confident that he will manage to dvp smth, unless you guys really have too much time on your hands and want to give it a serious try too.
He runs <!-- BBCode Start --><A HREF="http://www.bastish.net/mfop" TARGET="_blank">mfop</A><!-- BBCode End --> (Moblogging For Other People) and is already offering a way to post to Movabletype blogs and blogger by email. I pushed him to try to dvp smth for Gallery too as more and more of my friends have started posting from their mobile phones and I figured it was only a matter of weeks before they want to start organising their pics by albums (/categories).
Thanks!

 
Viper_iii
Viper_iii's picture

Joined: 2002-12-31
Posts: 56
Posted: Wed, 2005-06-22 23:45

I guess I don't understand the full process but why can't gallery POP a specific account using a PHP Script > look for emails that have the right subject header > strip and upload the images that it finds are new & tag the processed ones so it doesn't upload an already processed image?

I guess poping an existing mail box isn't a fuction of php but seems that it should be able to and pass the credentials as needed even for a remote mail server. Just a thought.

Let me know when and if there is ever an easy fix. kinda makes it an easy mogallery setup like textamerica uses. I dont like theirs though!!! because its not on my server!!