My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package org.joe_e.servlet.mail.notjoe_e;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
* Mechanism for interacting with Postfix in a secure way. This class can not be created
* by Joe-E code, but it's instance methods can be accessed by Joe-E.
*
* Provides methods for adding virtual accounts to the postfix database
*
* Note: this class is not Joe-E code.
* @author akshay
*
* @TODO: validate names of users to write to the virtual_mailbox_recipients
*/
public class PostfixClient {

private final String recipients = "/etc/postfix/virtual_mailbox_recipients";
private final String hostname = "boink.joe-e.org";

/**
* Adds the specified username to the virtual_mailbox_recipients file
* and runs the postmap command
*
* @param accounts
* @param username
*/
public boolean updateDatabase(String username) {
boolean done = false;
try {
BufferedReader reader = new BufferedReader(new FileReader(recipients));
String line = null;
while ((line = reader.readLine())!= null) {
if (line.contains(username+"@"+hostname)) {
done = true;
}
}
} catch (FileNotFoundException e1) {
return false;
} catch (IOException e1) {
return false;
}

try {
if (!done) {
BufferedWriter writer = new BufferedWriter(new FileWriter(recipients, true));
writer.write(username+"@"+hostname+"\t"+hostname+"/"+username+"/Maildir/");
writer.newLine();
writer.close();
}
Process p = Runtime.getRuntime().exec("/usr/sbin/postmap /etc/postfix/virtual_mailbox_recipients");
p.waitFor();
if (p.exitValue() == 0) {
return true;
}
return false;
} catch (IOException e) {
return false;
} catch (InterruptedException e) {
return false;
}
}

/**
* for testing purposes.
* @param args
*/
public static void main (String[] args) {
PostfixClient client = new PostfixClient();
try {
client.updateDatabase("asdfg");

} catch (Exception e) {
e.printStackTrace();
}
}
}

Change log

r368 by krish.akshay on Jan 30, 2010   Diff
sanitizing username on account creation,
synchronized access to file system, paying
attention to postfixclients return value
Go to: 
Project members, sign in to write a code review

Older revisions

r362 by krish.akshay on Jan 29, 2010   Diff
fixed CookieView behavior to only
commit cookies that were modified.
This involves maintaining two lists of
cookies in each view, updated code-
generation tool to reflect this
r353 by daw+goo...@taverner.cs.berkeley.edu on Jan 28, 2010   Diff
delete a method that Akshay says is
not used
r311 by krish.akshay on Oct 2, 2009   Diff
implemented wrapping the servlet
response without using anything
container specific
All revisions of this file

File info

Size: 2114 bytes, 82 lines
Powered by Google Project Hosting