source: subversion/branches/devel-vnext/_old/bin/msgimport @ 588

Last change on this file since 588 was 588, checked in by till, 6 years ago
  • moved old files into _old/
  • prepairing for rc1-based commit
  • Property svn:executable set to *
File size: 2.3 KB
Line 
1#!/usr/bin/php -qC
2<?php
3
4$CWD = $INSTALL_PATH = preg_replace('/bin\/$/', '', getcwd() . '/');
5ini_set('include_path',  ini_get('include_path') . PATH_SEPARATOR . $CWD.'program/');
6
7require_once('include/rcube_shared.inc');
8require_once('include/rcube_imap.inc');
9require_once('include/main.inc');
10require_once('include/bugs.inc');
11
12/**
13 * Parse commandline arguments into a hash array
14 */
15function get_args($aliases=array())
16{
17        $args = array();
18        for ($i=1; $i<count($_SERVER['argv']); $i++)
19        {
20                $arg = $_SERVER['argv'][$i];
21                if (substr($arg, 0, 2) == '--')
22                {
23                        $sp = strpos($arg, '=');
24                        $key = substr($arg, 2, $sp - 2);
25                        $value = substr($arg, $sp+1);
26                }
27                else if ($arg{0} == '-')
28                {
29                        $key = substr($arg, 1);
30                        $value = $_SERVER['argv'][++$i];
31                }
32                else
33                        continue;
34
35                $args[$key] = preg_replace(array('/^["\']/', '/["\']$/'), '', $value);
36               
37                if ($alias = $aliases[$key])
38                        $args[$alias] = $args[$key];
39        }
40
41        return $args;
42}
43
44
45// get arguments
46$args = get_args(array('h' => 'host', 'u' => 'user', 'p' => 'pass', 'f' => 'file'));
47
48if (!($args['host'] && $args['user'] && $args['pass'] && $args['file']))
49{
50        print "Missing required parameters.\n";
51        print "Usage:  msgimport -h imap-host -u user-name -p password -f message-file\n";
52        print "-host   IMAP host\n";
53        print "-user   IMAP user name\n";
54        print "-pass   IMAP password\n";
55        print "-file   Message file to upload\n";
56        exit;
57}
58else if (!is_file($args['file']))
59{
60        print "Cannot read message file\n";
61        exit;   
62}
63
64
65// parse $host URL
66$a_host = parse_url($args['host']);
67if ($a_host['host'])
68{
69        $host = $a_host['host'];
70        $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? TRUE : FALSE;
71        $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : 143);
72}
73else
74{
75        $host = $args['host'];
76        $imap_port = 143;
77}
78
79// instantiate IMAP class
80$IMAP = new rcube_imap(null);
81
82// try to connect to IMAP server
83if ($IMAP->connect($host, $args['user'], $args['pass'], $imap_port, $imap_ssl))
84{
85        print "IMAP login successful.\n";
86        print "Uploading message...\n";
87       
88        // upload message from file
89        if  ($IMAP->save_message('INBOX', file_get_contents($args['file'])))
90                print "Message successfully added to INBOX.\n";
91        else
92                print "Adding message failed!\n";
93}
94else
95{
96        print "IMAP login failed.\n";
97}
98
99?>
Note: See TracBrowser for help on using the repository browser.