Skip to content

Instantly share code, notes, and snippets.

@poppen
Created October 10, 2010 13:43
Show Gist options
  • Save poppen/619251 to your computer and use it in GitHub Desktop.
Save poppen/619251 to your computer and use it in GitHub Desktop.
patch for vpasswd2postfix http://vpasswd2postfix.sourceforge.net/
--- vpass2postfix.orig 2010-10-10 13:20:51.000000000 +0900
+++ vpass2postfix 2010-10-12 18:33:39.000000000 +0900
@@ -16,23 +16,36 @@
<?php
-if($argc < 2) {
- echo "Use $argv[0] vpasswd_file\n\n";
-} else {
+if ($argc < 3) {
+ die("Use $argv[0] domain vpasswd_file");
+}
require_once('functions.inc.php');
require_once('config.inc.php');
-$handle = @fopen($argv[1], "r");
-if ($handle) {
- while (!feof($handle)) {
+$domain = trim($argv[1]);
+if (!($handle = fopen($argv[2], "r"))) {
+ die("can't open vpasswd file!");
+}
+
+while (!feof($handle)) {
$buffer = fgets($handle, 4096);
$tmp = explode(":",$buffer);
+
+ if (count($tmp) < 7) continue;
+
$username = trim($tmp[0]);
- $mailbox = trim($tmp[0]);
$password = trim($tmp[1]);
$name_tmp = explode(" ",$tmp[4]);
- $name = trim("$name_tmp[0].$name_tmp[1]");
+ if (count($name_tmp) == 2) {
+ $name = trim("$name_tmp[0].$name_tmp[1]");
+ } else {
+ $name = $tmp[4];
+ }
+ $mailbox = trim($tmp[5]);
+ if (preg_match('/^\$/', $password) === 0) {
+ $password = "{crypt}${password}";
+ }
$quota = trim($tmp[6]);
if($quota == "NOQUOTA" or $quota == "0") {
$quota = 0;
@@ -41,7 +54,6 @@
$quota = $quota / 1024;
$quota = substr($quota,0,3);
}
- $domain = "fcm.uncu.edu.ar";
$mail = trim("$username@$domain");
$active = "1";
@@ -51,7 +63,7 @@
$fName = $name;
$fMail = $mail;
$fQuota = $quota;
- $fDomain = "fcm.uncu.edu.ar";
+ $fDomain = $domain;
$fActive = "1";
@@ -99,21 +111,24 @@
if ($error != 1)
{
- if ($CONF['domain_path'] == "YES")
- {
- if ($CONF['domain_in_mailbox'] == "YES")
- {
- $maildir = $fDomain . "/" . $fMailbox . "/";
- }
- else
- {
- $maildir = $fDomain . "/" . escape_string (strtolower($fMailbox)) . "/";
- }
- }
- else
- {
- $maildir = $fMailbox . "/";
- }
+// if ($CONF['domain_path'] == "YES")
+// {
+// if ($CONF['domain_in_mailbox'] == "YES")
+// {
+// $maildir = $fDomain . "/" . $fMailbox . "/";
+// }
+// else
+// {
+// $maildir = $fDomain . "/" . escape_string (strtolower($fMailbox)) . "/";
+// }
+// }
+// else
+// {
+// $maildir = $fMailbox . "/";
+// }
+
+ $maildir = preg_replace('!/home/vpopmail/domains/!', '', $fMailbox) . "/Maildir/";
+
if (!empty ($fQuota))
{
@@ -164,11 +179,9 @@
} else {
$tMessage .= $PALANG['pCreate_mailbox_result_succes_nosubfolders'] . "<br />($fUsername$tShowpass)";
}
- mail($fUsername, "Cuenta migrada", "Su cuenta fue migrada a los nuevos servidores satisfactoriamente.");
+ //mail($fUsername, "Cuenta migrada", "Su cuenta fue migrada a los nuevos servidores satisfactoriamente.");
}
}
}
fclose($handle);
-}
-}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment