Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NetworkingIMAPCLIENT
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
matthew.seaman
NetworkingIMAPCLIENT
Commits
514a4dbd
Commit
514a4dbd
authored
Nov 27, 2017
by
matthew.seaman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Networking assigment
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
0 deletions
+121
-0
Emails.txt
Emails.txt
+18
-0
Networking.py
Networking.py
+103
-0
No files found.
Emails.txt
0 → 100644
View file @
514a4dbd
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
SGV5IHh48J+Slg0K
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
WW91IGFscmlnaHQNCg0KX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18NCkZyb206IE1B
VFRIRVcgU0VBTUFODQpTZW50OiAyNyBOb3ZlbWJlciAyMDE3IDEwOjIxOjA4DQpUbzogbWF0dGhl
dy5zZWFtYW5AZWx3b29kLnlvcmtkYy5uZXQNClN1YmplY3Q6DQoNCkhleSB4ePCfkpYNCg==
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Yo yo yo
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Test for offline mode
Networking.py
0 → 100644
View file @
514a4dbd
from
__future__
import
unicode_literals
from
imapclient
import
IMAPClient
import
email
import
socket
try
:
print
"checking internet connection.."
host
=
socket
.
gethostbyname
(
"www.google.com"
)
s
=
socket
.
create_connection
((
host
,
80
),
2
)
s
.
close
()
print
'internet on.'
connection
=
True
except
Exception
,
e
:
print
e
print
"internet off."
connection
=
False
if
connection
==
True
:
HOST
=
'elwood.yorkdc.net'
USERNAME
=
raw_input
(
"Please enter your username
\n
"
)
#'matthew.seaman'
PASSWORD
=
raw_input
(
"Password
\n
"
)
#'AE8LLUAD'
ssl
=
False
server
=
IMAPClient
(
HOST
,
use_uid
=
True
,
ssl
=
ssl
)
server
.
login
(
USERNAME
,
PASSWORD
)
select_info
=
server
.
select_folder
(
'INBOX'
)
print
(
'
%
d messages in INBOX'
%
select_info
[
'EXISTS'
])
messages
=
server
.
search
([
'NOT'
,
'DELETED'
])
print
(
"
%
d messages that aren't deleted"
%
len
(
messages
))
print
()
print
(
"Messages:"
)
response
=
server
.
fetch
(
messages
,
[
'FLAGS'
,
'RFC822.SIZE'
])
for
msgid
,
data
in
response
.
iteritems
():
print
(
' ID
%
d:
%
d bytes, flags=
%
s'
%
(
msgid
,
data
[
b
'RFC822.SIZE'
],
data
[
b
'FLAGS'
]))
while
True
:
userChoice
=
raw_input
(
"Weclome to the webmail client
\n
Please choose an option below
\n
1:List
\n
2:Create
\n
3:Delete
\n
4:Select
\n
5:Examine
\n
6:Status
\n
7:Fetch
\n
8:Logout
\n
"
)
if
userChoice
==
'1'
:
list
=
server
.
list_folders
(
directory
=
u''
,
pattern
=
u'*'
)
print
(
list
)
if
userChoice
==
'2'
:
create
=
raw_input
(
"Enter a name for the folder you wish to create
\n
"
)
server
.
create_folder
(
create
)
print
(
create
+
'Has been created'
)
if
userChoice
==
'3'
:
delete
=
raw_input
(
"Enter the folders name you wish to delete
\n
"
)
server
.
delete_folder
(
delete
)
print
(
delete
+
'Has been deleted'
)
if
userChoice
==
'4'
:
select
=
raw_input
(
"Enter the folders name you wish to select
\n
"
)
server
.
select_folder
(
select
,
readonly
=
False
)
print
(
select
+
'Has been selected
\n
'
)
copySearch
=
raw_input
(
"Please select if you would like to 1:copy or 2:search
\n
"
)
if
copySearch
==
'1'
:
copy
=
raw_input
(
"Enter the folders name which you wish to copy to
\n
"
)
server
.
copy
(
messages
,
copy
)
print
(
"messages have been copied to"
+
copy
)
if
copySearch
==
'2'
:
print
server
.
search
(
criteria
=
u'ALL'
,
charset
=
None
)
if
userChoice
==
'5'
:
select
=
raw_input
(
"Enter the folders name you wish to examine
\n
"
)
server
.
select_folder
(
select
,
readonly
=
True
)
print
(
select
+
'Has been examined
\n
'
)
if
userChoice
==
'6'
:
status
=
raw_input
(
"Enter the folders name you wish to see the status off
\n
"
)
print
server
.
folder_status
(
status
,
what
=
None
)
if
userChoice
==
'7'
:
file
=
open
(
"Emails.txt"
,
"w"
)
fetch
=
server
.
fetch
(
messages
,
[
'RFC822'
,
'BODY[TEXT]'
])
for
msgid
,
data
in
fetch
.
iteritems
():
msg
=
email
.
message_from_string
(
data
[
'RFC822'
])
a
=
msg
.
get_payload
(
0
)
.
as_string
()
file
.
write
(
a
)
print
a
file
.
close
()
if
userChoice
==
'8'
:
print
(
USERNAME
+
"Has logged out"
)
server
.
logout
break
else
:
if
connection
==
False
:
print
(
"You require internet connection to recive new emails"
)
print
(
"Here are the ofline messges"
)
txt
=
open
(
"Emails.txt"
,
"r"
)
for
offlineEmail
in
txt
:
print
offlineEmail
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