Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: BatchUpload via crontab ?  (Read 4894 times)

0 Members and 1 Guest are viewing this topic.

htilly

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
BatchUpload via crontab ?
« on: April 12, 2006, 01:04:39 pm »

Hi !

First my simple question:
Is it possible to make crontab import all pictures in a given directory to a predefined album?
If so, where can I read how to do this or could someone help me out?

What I want to do is to automatically import MMS pictures sent from my mobile phone to coppermine.
Iím 90% done. I.e. - I send an MMS from my phone to, let say mms@mydomain.com. I then have a script picking up the attached picture in the MMS mail and store it in a directory.

The only thing left right now is to get the picture imported into coppermine.

So, I want to have a cronjob that takes all the *.jpg in a given dir and import them to a specific album.

Is this possible in any way ?

BR
Tilly
Logged

htilly

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
Re: BatchUpload via crontab ?
« Reply #1 on: April 12, 2006, 04:18:35 pm »

Hi again,

I browsed thru the forum some more and noticed that quit some few also tried / did some hacks to get MMS/mail upload working.
So I thought I should share the script that Im using to DL the pictures from email sent by a mobile phone.

For the record, I will take no credit for the script since I havenít written it. I used it a long time ago with another album app called "album.pl" but I have forgotten who wrote it in the first place  .

EDIT: I found the original link for the old album:
http://dev.bobbitt.ca/forums/index.php?topic=1132.0
Credits goes to: pcarter


Anyhow.. here is the perl script used for fetching .jpg files in mail.
Ps. It is supposed to fix the URL spring problem as well..



================================================

Code: [Select]
#!c:/Perl/bin/Perl.exe
use Mail::POP3Client;
use MIME::Parser;
use LWP::UserAgent;

###############
# Configuration
###############

#Mail Config
my $pop_user='userid'; # Mailbox UserID
my $pop_pass='password'; # MailBox Password
my $pop_host='pop.myserver.net'; # MailBox Pop3 Server Address
my $mail_address='photos@myserver.net'; # Expected MailTo Address


# File Config
my $picpath='C:/WEB_ROOT/PHOTOS/Phone Pics/'; # Where to store retrieved images
my $logfile='C:/pcspics.log'; # Log File Name/Location
my $desc='descriptions.txt'; # Name of file for Description Text
my $tempdir='C:/Temp';

# Known From Addresses
my %senders = ( '000000000@messaging.sprintpcs.com' => 'UserName1',
'000000000@messaging.sprintpcs.com' => 'UserName2',
'000000000@vzwpix.com' => 'UserName3',
'000000000@messaging.sprintpcs.com' => 'UserName4',
'user@server.net'

my $sprint = 'messaging.sprintpcs.com';
my $sprintnew = 'pm.sprint.com';

###############
# Main
###############

# Open Logfile...
open LogFile, ">>$logfile"||die "cannot open: $!";
print LogFile "==== Started ".localtime()." ====\n";

# Connect to Pop3 Server
$pop = new Mail::POP3Client(USER     => $pop_user,
PASSWORD => $pop_pass,
HOST     => $pop_host );
#Verify Connection
if ($pop->Count() == -1) {
print LogFile "**\nERROR: POP Connection Error\n**\n";
Exit -1;
}

#Loop Through Messages
for ($msg = 1; $msg <= $pop->Count(); $msg++) {

# Check for Mail Address in To: Headers
if ( $pop->Head( $msg ) =~ m/^To:.*$mail_address/im) {
    print LogFile "** Accepted Message # $msg:\n";
   
    # Get From Addy from Header
    foreach ( $pop->Head( $msg ) ) {
  if ( /^From: .*/i ) {
        $from_address=$_;
        print LogFile $from_address, "\n";
        }
    }
               
    #Check provider from From Address..
    if ( $from_address =~/.*$sprint/i ||$from_address =~/.*$sprintnew/i ) {
    print LogFile "Sprint Message\n";
    &getSprintPix();
    }
    else {
    print LogFile "Non-Sprint - assuming MIME.\n";
    &getMimePix();
    }
   
    &writePicFile();
    &parseSender();
    &writeDesc();
    #&deleteMail();
   
   
}
}
   
###############
# End Cleanup
###############
END {
print LogFile "==== Ended ".localtime()."   ====\n";
close LogFile;
if ($pop) {$pop->Close;}
if ($entity) {$entity->purge;}
if ($parser) {$parser->filer->purge;}

}


#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #

sub getSprintPix {
#Loop through message lines to find Line with URL
foreach ( $pop->Body($msg) ) {
#if ( /.*pictures.sprintpcs.com\/\/shareImage/i ) {
#if ( /.*pictures.sprintpcs.com\/shareImage/i ) {
if ( /.*pictures.sprintpcs.com\/mi/i ) {
#Get the URL
$start = index($_, '<img src="');
$start = $start+10;
$end = index($_,'"',$start);
$picurl=substr($_,$start,$end-$start);
$picurl=~s/&amp;/&/; #parse out the http encoding back to norm
#$picurl=~s/_235/_640/; #change the image max size from 235 to 640 (in URL)
$picurl=~s/limitsize=250,250/limitsize=640,640/;
print LogFile "Found URL: $picurl\n";

#Request PIC from web
my $ua = LWP::UserAgent->new;
$ua ->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1');
$accept='text/html, text/plain, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*';

$response = $ua->get($picurl,'Accept'=>$accept);
   
    if ($response->is_success) {
        print LogFile "Successfully retrieved image from web.\n";
        }
    else {
        print LogFile "ERROR: ", $response->status_line, "\n";
    }
$picdata = $response->content;
}
elsif ( /.*&lt;messageText&gt;/i ) {
$start = index($_, 'messageText&gt;');
$start = $start+15;
$end = index($_,'&lt;',$start);
$messagetext=substr($_,$start,$end-$start);
print LogFile "Found MessageText: $messagetext \n";
}
}
}

sub getMimePix {
# Get Message
  $message = $pop->Retrieve($msg);
  $picdata="";  
   
  # Setup Mime Parser
    my $parser = new MIME::Parser;
    # $parser->output_under($tempdir);
    $parser->output_to_core(1);
    $entity = $parser->parse_data($message);
#$entity->dump_skeleton;          # for debugging
 
  #Loop through Mime Entities in Message
for ($i=0;$i<$entity->parts;$i++) {
$mimetype = $entity->parts($i)->effective_type;
print LogFile "Found Mime Type: $mimetype\n";
 
if ($mimetype eq 'image/jpeg') {
#$msgbody = $entity->parts($i)->bodyhandle;
#$picdata = $msgbody->as_string
$picdata = $entity->parts($i)->bodyhandle->as_string;
last;
}
}
}

sub writePicFile {
if ($picdata) {
$picname = localtime() . ".jpg";
$picname =~s/://g;
print LogFile "Attempting to write file: $picpath$picname\n";
open (picfile,">$picpath$picname")|| die "cannot open: $!";
binmode (picfile);
print picfile $picdata;
close (picfile);
&deleteMail();
}
else {
print LogFile "No Valid MimeTypes Found. Skipping Message.\n";
}

}

sub parseSender {
chomp $from_address;
@addy = split(' ' ,$from_address);

foreach $add(@addy) {
if ($add =~m/.+\@.+\.\D{3,}/) {
$sender=$add;
}
}
$sender =~s/[<,>]//g;
$sender =$senders{$sender} if exists $senders{$sender};

}

sub writeDesc {
## Write Sender info to description
open (DescFile,">>$picpath$desc")|| die "cannot open: $1";
print DescFile "~\n";
print DescFile "$picname\n";
print DescFile "$picname\n";
print DescFile "<p><center><small><small>";
print DescFile "from: $sender<BR> $messagetext";
print DescFile "</small></small></center>\n";
close DescFile;
}

sub deleteMail {
print LogFile "Deleting message $msg from Inbox.\n";
$pop->Delete($msg);
}

================================================

BR Tilly
« Last Edit: April 12, 2006, 06:21:51 pm by GauGau »
Logged
Pages: [1]   Go Up
 

Page created in 0.019 seconds with 20 queries.