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
45c01ca3
Commit
45c01ca3
authored
Nov 27, 2017
by
stuart.waters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IMAPClient
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
0 deletions
+131
-0
emails.txt
emails.txt
+4
-0
imap.py
imap.py
+118
-0
readme.txt
readme.txt
+9
-0
No files found.
emails.txt
0 → 100644
View file @
45c01ca3
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
HI.
imap.py
0 → 100644
View file @
45c01ca3
from
__future__
import
unicode_literals
from
imapclient
import
IMAPClient
import
email
import
socket
# Tests that there is an active internet connection
try
:
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
except
Exception
,
e
:
print
e
print
"No Internet Connection"
internet
=
False
HOST
=
'elwood.yorkdc.net'
ssl
=
False
server
=
IMAPClient
(
HOST
,
use_uid
=
True
,
ssl
=
ssl
)
# If there is an active internet connection this is run
if
internet
==
True
:
try
:
# asks for username and stores it within USERNAME
USERNAME
=
raw_input
(
'Username: '
)
# asks for password and stores it within PASSWORD
PASSWORD
=
raw_input
(
'Password: '
)
server
.
login
(
USERNAME
,
PASSWORD
)
except
server
.
Error
,
e
:
print
'Username or Password incorrect'
#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
if
user_input
==
'2'
:
list
=
server
.
list_folders
(
directory
=
u''
,
pattern
=
u'*'
)
print
(
list
)
# Create 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'
)
# Delete a folder
if
user_input
==
'4'
:
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'
)
#Selecting a Folder
if
user_input
==
'5'
:
folder
=
raw_input
(
'Enter the folder you wish to select: '
)
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
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
:
print
server
.
search
(
criteria
=
u'ALL'
,
charset
=
None
)
# Examine a folder
if
user_input
==
'6'
:
folder
=
raw_input
(
'Enter the folder you wish to examine: '
)
server
.
select_folder
(
folder
,
readonly
=
True
)
print
(
folder
+
' is being examined'
)
# Status of folder
if
user_input
==
'7'
:
folder
=
raw_input
(
'Enter the name of the folder you wish to see the status of: '
)
print
server
.
folder_status
(
folder
,
what
=
None
)
# Fetches and prints the emails.
# Also writes them onto a text document for offline mode
if
user_input
==
'8'
:
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
()
# User logout
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
:
user_input
=
raw_input
(
'Press 1 for offline mode: '
)
if
user_input
==
'1'
:
f
=
open
(
'emails.txt'
,
'r'
)
for
line
in
f
:
print
line
readme.txt
0 → 100644
View file @
45c01ca3
Username = stuart.waters
Password = PQ7RDEAE
To choose something from the command line menu press the corresponding number key for the chosen option
Files included:
imap.py
emails.txt
readme.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