! curl https://raw.githubusercontent.com/mafudge/datasets/master/ist256/07-Files/enron-allen-inbox.txt -o enron-allen-inbox.txt
! curl https://raw.githubusercontent.com/mafudge/datasets/master/ist256/07-Files/enron-donohoe-inbox.txt -o enron-donohoe-inbox.txt
! curl https://raw.githubusercontent.com/mafudge/datasets/master/ist256/07-Files/enron-lay-inbox.txt -o enron-lay-inbox.txt
! curl https://raw.githubusercontent.com/mafudge/datasets/master/ist256/07-Files/enron-williams-inbox.txt -o enron-williams-inbox.txt
! curl https://raw.githubusercontent.com/mafudge/datasets/master/ist256/07-Files/enron-onemail-inbox.txt -o enron-onemail-inbox.txt

"""
Explanation: Homework: Mass Email Marketing
The Problem
You have been contracted by former energy company Enron to create a database of email addresses for "mass marketing" ahem ,cough: SPAMMING. You will get the emails for this "mass marketing" campaign from the email inboxes of the sales team, provided here.

enron-allen-inbox.txt
enron-donohoe-inbox.txt
enron-lay-inbox.txt
enron-williams-inbox.txt
enron-onemail-inbox.txt ( a sample with just one email in it - helpful for testing)

Run this cell to download the files.
End of explanation
"""


# Step 2: Write code here


"""
Explanation: Your task is to provide a drop-down so the user of the program can select one of the 5 mailboxes. Upon running the interaction the program will:

read the selected mailbox file a line at a time
find any lines beginning with From:.
extract out the email address from the From: line.
use the isEmail() function (provided below) to ensure its a valid email address.
print the email address
write the email to the emails file. (for example enron-allen-inbox.txt would write the emails to enron-allen-emails.txt.
NOTE: any emails from the enron.com domain are internal and should be omitted from the list. We don't need to "mass market" to ourselves!

HINTS: 

We saw how to extract emails in the Lab. This approach should work here.
The problem simplification approach is a good approach to this problem. Start with a simpler problem and add one more piece of complexity with each iteration:
First solve a simpler problem which you extract the single email from the enron-onemail-inbox.txt file.
Then re-write your program to use another mailbox like enron-allen-inbox.txt to make sure it prints multiple emails.
Next re-write your program to omit any emails with the domain enron.com
Next not only print the emails, but write them back out to the file: enron-allen-emails.txt
Finally add the ipywidget drop-down where you can select a mailbox and save to a different emails file based on the inbox file name.



Part 1: Problem Analysis
Inputs:
TODO: Inputs
Outputs:
TODO: Outputs
Algorithm (Steps in Program):  
```
TODO:Steps Here
```
Part 2: Code Solution
You may write your code in several cells, but place the complete, final working copy of your code solution within this single cell below. Only the within this cell will be considered your solution. Any imports or user-defined functions should be copied into this cell.
End of explanation
"""


# run this code to turn in your work!
from coursetools.submission import Submission
Submission().submit()

"""
Explanation: Part 3: Questions

Did you write your own user-defined function? For what purpose?

--== Double-Click and Write Your Answer Below This Line ==--  

Explain how you might re-write this program to create one large file from all the mailboxes. No code, just explain it.

--== Double-Click and Write Your Answer Below This Line ==--  

Devise an approach to remove duplicate emails from the output file. You don't have to write as code, just explain it.

--== Double-Click and Write Your Answer Below This Line ==--  
Part 4: Reflection
Reflect upon your experience completing this assignment. This should be a personal narrative, in your own voice, and cite specifics relevant to the activity as to help the grader understand how you arrived at the code you submitted. Things to consider touching upon: Elaborate on the process itself. Did your original problem analysis work as designed?  How many iterations did you go through before you arrived at the solution? Where did you struggle along the way and how did you overcome it? What did you learn from completing the assignment? What do you need to work on to get better? What was most valuable and least valuable about this exercise? Do you have any suggestions for improvements?
To make a good reflection, you should journal your thoughts, questions and comments while you complete the exercise.
Keep your response to between 100 and 250 words.
--== Double-Click and Write Your Reflection Below Here ==--
End of explanation
"""


