About srand:
I dont know if this are updated now, but when I first begun learning perl, I noticed that if I would run 2 instances of a script printing a sequence of random digits, both scripts would show the same sequence if not srand; was runned in the beginning. Therefore, I have get used to srand; in the beginning when Im gonna use rand();
About repeated calls to rand:
The repeated calls to rand is to force leading zeroes in case I get a number like 000001. Perl would normally strip off all leading zeroes leading to strange filenames.
By calling int(rand(10) repeated times, I guarantee that the resulting number will have this number of digits. So if I would want to generate a 10 digit number, thats ALWAYS 10 digits, even if the number coming out is 1, I would run:
$number = int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10));That would force the number to the string "0000000001" if it gets that number, and not "1".
About testing if $foldername exist
Since the filename is consisted of time() and 5 random digits, for the chance to happen that it would write the mail in the same folder, is in the following prerequistes:
-2 or more mails must be finished by postfix in the exact same second.
-Both 5 digit random numbers must be exactly same. The chance for this happening is: 0,001 %.
you would have a higher chance of winning lucky numbers on TV, than both of these prerequistes happening at the same time. And IF that would happen, no ill would be happen except for 2 mails getting merged into one.
The mail SMTP server IS located in the Web server, they are running on the same machine! Thats why I want to skip all overhead with going internally through IMAP and POP3. I also prefer to block incoming IMAP and POP3 in fw for security reasons and only have port 80, 25 and 53 open in fw.
The problem with parsing the mail as-its opened by the receiver, is if someone would send you a lets say a 50 MB mail with attachments of 49MB. You might not want to have to download that attachment, but you want to still read the body of the mail. You would still have to wait until the attachments is parsed before body can be opened.
Theres NO MIME parser in the webmail system. All the webmail system does is to scan a folder of files and generating a output based on that. MIME::Parser will have parsed everything when a email has been received.
About permissions: I prefer to code the permission system itself. As you might see, the mail is placed in the /my/ folder. Thats a user of the webmail system. When I have get all running, I will implement so the system will place the mail in the /$user/ folder where $user is the part before @. No malicious user can access other user's mail since their login will make the webmail system read from "their" folder. Theres no need to config unix permissions since no unauthorized has admin/physical access to the server machine.
About maildir: Maildir are writing the mail to the disk before its parsed. Thats means parsing has to wait until mail is fully delivered. By letting postfix stream in the mail into the parser while the remote MTA is still writing to my postfix server, I can launch parsing at the same time as the remote MTA sends "DATA" to me. This speeds up things. The mail is written to disk completely parsed and ready for the webmail system to pick up.
About switching mailservers: I selected postfix because its efficient and it can stream the mail to a mailbox command's STDIN. If I would switch mailserver, I would require that the mailserver can do that. If theres a MUST to switch a mailserver to a noncompatible type, it would be as easy to replace parse(\*STDIN) in my script with parse_open($path_to_mailfile_in_mailserver) since most, if not all SMTP servers, would write a MIME file somewhere.
In reply to Re^2: Get CID inline attachments with MIME::Parser
by sebastiannielsen
in thread Get CID inline attachments with MIME::Parser
by sebastiannielsen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |