Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-helpdesk
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-helpdesk
Commits
1fe65fac
Commit
1fe65fac
authored
Jul 24, 2010
by
Frank Bergmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- more or less working
parent
ce4d7532
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
64 deletions
+45
-64
import-pop3.perl
perl/import-pop3.perl
+45
-64
No files found.
perl/import-pop3.perl
View file @
1fe65fac
...
...
@@ -107,71 +107,48 @@ if (0 == $n) {
# Get the list of messages
$msgList
=
$pop3_conn
->
list
();
foreach
$msg
(
keys
(
%
$msgList
))
{
$ref
=
$pop3_conn
->
get
(
$msg
);
print
@$ref
;
print
"\n\n"
;
}
$pop3_conn
->
quit
();
exit
0
;
# --------------------------------------------------------
# Check for new mail in the Maildir
open
(
MAILS
,
"find $maildir/new -type f |"
)
||
die
"import-pop3: Unable to get mails at $maildir/new.\n"
;
while
(
my
$mail_filename
=<
MAILS
>
)
{
chomp
(
$mail_filename
);
print
"$mail_filename\n"
;
# --------------------------------------------------------
# Extract the contents of the email
open
(
LINES
,
$mail_filename
)
||
die
"import-pop3: Unable to open file $mail_filename.\n"
;
my
$from
=
""
;
my
$to
=
""
;
my
$subject
=
""
;
my
$body
=
""
;
while
(
my
$line
=<
LINES
>
)
{
# Skip less interesting mail fields
if
(
$line
=~
/^Return-Path:/
)
{
next
;
}
if
(
$line
=~
/^Delivered-To:/
)
{
next
;
}
if
(
$line
=~
/^X-Original-To:/
)
{
next
;
}
if
(
$line
=~
/^Received:/
)
{
next
;
}
if
(
$line
=~
/^Date:/
)
{
next
;
}
if
(
$line
=~
/^Message-ID:/
)
{
next
;
}
if
(
$line
=~
/^User-Agent:/
)
{
next
;
}
if
(
$line
=~
/^MIME-Version:/
)
{
next
;
}
if
(
$line
=~
/^Content-Type:/
)
{
next
;
}
if
(
$line
=~
/^Content-Transfer-Encoding:/
)
{
next
;
}
# Skip the "id" line
if
(
$line
=~
/^\tid/
)
{
next
;
}
# Extract from, to and subject
if
(
$line
=~
/^From:(.*)/
)
{
$from
=
$1
;
next
;
}
if
(
$line
=~
/^To:(.*)/
)
{
$to
=
$1
;
next
;
}
if
(
$line
=~
/^Subject:(.*)/
)
{
$subject
=
$1
;
next
;
}
# Replace quote by double-quote for SQL security
$line
=~
s/'/"/g
;
$body
.=
$line
}
close
(
LINES
);
print
"\n$from$to$subject$body\n"
if
(
$debug
>
1
);
# Loop for each of the mails
foreach
$msg
(
keys
(
%
$msgList
))
{
# Get the mail as a file handle
$fh
=
$pop3_conn
->
getfh
(
$msg
);
my
$from
=
""
;
my
$to
=
""
;
my
$subject
=
""
;
my
$body
=
""
;
while
(
my
$line
=
<
$fh
>
)
{
chomp
(
$line
);
# Skip less interesting mail fields
if
(
$line
=~
/^Return-Path:/
)
{
next
;
}
if
(
$line
=~
/^Delivered-To:/
)
{
next
;
}
if
(
$line
=~
/^X-Original-To:/
)
{
next
;
}
if
(
$line
=~
/^Received:/
)
{
next
;
}
if
(
$line
=~
/^Date:/
)
{
next
;
}
if
(
$line
=~
/^Message-ID:/
)
{
next
;
}
if
(
$line
=~
/^User-Agent:/
)
{
next
;
}
if
(
$line
=~
/^MIME-Version:/
)
{
next
;
}
if
(
$line
=~
/^Content-Type:/
)
{
next
;
}
if
(
$line
=~
/^Content-Transfer-Encoding:/
)
{
next
;
}
# Skip the "id" line
if
(
$line
=~
/^\tid/
)
{
next
;
}
# Extract from, to and subject
if
(
$line
=~
/^From:(.*)/
)
{
$from
=
$1
;
next
;
}
if
(
$line
=~
/^To:(.*)/
)
{
$to
=
$1
;
next
;
}
if
(
$line
=~
/^Subject:(.*)/
)
{
$subject
=
$1
;
next
;
}
# Replace quote by double-quote for SQL security
$line
=~
s/'/"/g
;
$body
.=
$line
;
}
close
(
LINES
);
print
"\n$from$to$subject$body\n"
if
(
$debug
>=
1
);
# --------------------------------------------------------
# Calculate ticket database fields
...
...
@@ -355,7 +332,11 @@ while (my $mail_filename=<MAILS>) {
}
}
close
(
MAILS
);
# --------------------------------------------------------
# Close the connection to the POP3 server
$pop3_conn
->
quit
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment