Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IMAPClient
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
stuart.waters
IMAPClient
Commits
8d7948d6
Commit
8d7948d6
authored
Nov 28, 2017
by
stuart.waters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Final IMAP Commit
parent
45c01ca3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
57 deletions
+108
-57
emails.txt
emails.txt
+8
-0
imap.py
imap.py
+98
-57
readme.txt
readme.txt
+2
-0
No files found.
emails.txt
View file @
8d7948d6
...
...
@@ -2,3 +2,11 @@ Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
HI.
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
Li4uLi4uLi4uLi4uLi5BIG5vYj8/Pw0KDQrwn5iKDQo=
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Woah, Look you can see this secret message
imap.py
View file @
8d7948d6
...
...
@@ -5,95 +5,132 @@ import email
import
socket
# Tests that there is an active internet connection
# Can get rid of 'www.google.com' to check offline mode works
try
:
print
"
checking internet connection..
"
print
"
Checking Internet Connection
"
host
=
socket
.
gethostbyname
(
"www.google.com"
)
s
=
socket
.
create_connection
((
host
,
80
),
2
)
s
.
close
()
print
'Internet Connection Working'
internet
=
True
# If internet connection then true
print
'Active Internet Connection.'
internetConnection
=
True
except
Exception
,
e
:
print
e
print
"No Internet Connection"
internet
=
False
HOST
=
'elwood.yorkdc.net'
#If no internet connection then false
print
"No Internet Connection."
internetConnection
=
False
HOST
=
'elwood.yorkdc.net'
ssl
=
False
server
=
IMAPClient
(
HOST
,
use_uid
=
True
,
ssl
=
ssl
)
login
=
False
# If there is an active internet connection this is run
if
internet
==
True
:
try
:
if
internetConnection
==
True
:
# asks for username and stores it within USERNAME
# While login is false loops over asking user for username and password
# When logged in login is changed to true and the loop is broken
while
login
==
False
:
try
:
# Asks for username and stores it within USERNAME
USERNAME
=
raw_input
(
'Username: '
)
# asks for password and stores it within PASSWORD
# Asks for password and stores it within PASSWORD
PASSWORD
=
raw_input
(
'Password: '
)
# Attempts login with given username and password
server
.
login
(
USERNAME
,
PASSWORD
)
login
=
True
# If login fails then prints error
except
server
.
Error
,
e
:
print
'Username or Password incorrect'
print
'Username or Password Incorrect. Please Try Again'
login
=
False
select_info
=
server
.
select_folder
(
'INBOX'
)
messages
=
server
.
search
([
'NOT'
,
'DELETED'
])
response
=
server
.
fetch
(
messages
,
[
'FLAGS'
,
'RFC822.SIZE'
])
#runs through code until user chooses to logout, then program terminates
# Runs through code until user chooses to logout, then program terminates
while
True
:
user_input
=
raw_input
(
'Please choose an option:
\n
1: Logout
\n
2: List Folders
\n
3: Create Folder
\n
4: Delete Folder
\n
5: Select Folder
\n
6: Examine
\n
7: Status
\n
8: Fetch
\n
'
)
# Lists
the
folders
# Lists folders
if
user_input
==
'2'
:
list
=
server
.
list_folders
(
directory
=
u''
,
pattern
=
u'*'
)
print
(
list
)
# Creat
e
a folder
# Creat
ing
a folder
if
user_input
==
'3'
:
folder_name
=
raw_input
(
'Please enter a name for the folder: '
)
server
.
create_folder
(
folder_name
)
print
(
folder_name
+
' has been created'
)
# Delet
e
a folder
# Delet
ing
a folder
if
user_input
==
'4'
:
try
:
folder_name
=
raw_input
(
'Please enter the name of the folder you wish to delete: '
)
server
.
delete_folder
(
folder_name
)
print
(
folder_name
+
' has been deleted'
)
except
server
.
Error
,
e
:
print
(
'Folder does not exist.'
)
#
Selecting a F
older
#
Selecting a f
older
if
user_input
==
'5'
:
folder
=
raw_input
(
'Enter the folder you wish to select: '
)
try
:
server
.
select_folder
(
folder
,
readonly
=
False
)
print
(
folder
+
' has been selected'
)
# Once a folder is selected menu pops up
copySearch
=
raw_input
(
'Please Select if you wish to copy or search :
\n
1: Copy
\n
2: Search
\n
'
)
# Copying the selected folder
# When folder is selected this menu appears
copySearch
=
raw_input
(
'Please Select if you wish to copy or search :
\n
1: Copy
\n
2: Search
\n
3: Fetch'
)
# Copying a folder
if
copySearch
==
'1'
:
copyTo
=
raw_input
(
'Enter the name of the folder you wish to copy to: '
)
server
.
copy
(
messages
,
copyTo
)
print
(
'Copy to '
+
copyTo
+
' has been successful'
)
# Searching the folder
else
:
if
copySearch
==
'2'
:
# Searching a folder
print
server
.
search
(
criteria
=
u'ALL'
,
charset
=
None
)
else
:
try
:
response
=
server
.
fetch
(
messages
,
[
'RFC822'
,
'BODY[TEXT]'
])
f
=
open
(
'emails.txt'
,
'w'
)
for
msgid
,
data
in
response
.
iteritems
():
msg
=
email
.
message_from_string
(
data
[
'RFC822'
])
message
=
msg
.
get_payload
(
0
)
.
as_string
()
f
.
write
(
message
)
print
message
f
.
close
()
except
server
.
Error
,
e
:
print
(
'No emails to display.'
)
except
server
.
Error
,
e
:
print
(
'Folder does not exist.'
)
# Examine a folder
if
user_input
==
'6'
:
folder
=
raw_input
(
'Enter the folder you wish to examine: '
)
try
:
server
.
select_folder
(
folder
,
readonly
=
True
)
print
(
folder
+
' is being examined'
)
except
server
.
Error
,
e
:
print
(
'Folder does not exist.'
)
# Status of folder
if
user_input
==
'7'
:
folder
=
raw_input
(
'Enter the name of the folder you wish to see the status of: '
)
try
:
print
server
.
folder_status
(
folder
,
what
=
None
)
except
server
.
Error
,
e
:
print
(
'Folder does not exist.'
)
# Fetches and prints the emails.
# Also writes them onto a text document for offline mode
# Fetching emails in selected folder
if
user_input
==
'8'
:
try
:
response
=
server
.
fetch
(
messages
,
[
'RFC822'
,
'BODY[TEXT]'
])
f
=
open
(
'emails.txt'
,
'w'
)
for
msgid
,
data
in
response
.
iteritems
():
...
...
@@ -102,15 +139,19 @@ if internet == True:
f
.
write
(
message
)
print
message
f
.
close
()
except
server
.
Error
,
e
:
print
(
'No emails to display.'
)
#
User l
ogout
#
L
ogout
if
user_input
==
'1'
:
print
(
USERNAME
+
' is being logged out'
)
server
.
logout
()
break
# If no internet connection then offline mode can be run
if
internet
==
False
:
if
internetConnection
==
False
:
# Offline mode
user_input
=
raw_input
(
'Press 1 for offline mode: '
)
if
user_input
==
'1'
:
f
=
open
(
'emails.txt'
,
'r'
)
...
...
readme.txt
View file @
8d7948d6
...
...
@@ -3,6 +3,8 @@ Password = PQ7RDEAE
To choose something from the command line menu press the corresponding number key for the chosen option
To force offline mode delete 'www.google.com' from line 11. The program won't recieve a ping and therefore allow offline mode
Files included:
imap.py
emails.txt
...
...
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