Commit cf25c7bad7
Unsigned
Layout: unified · split
content/blog/2025-02-24-email-migration.org +19 −18
| @@ -83,23 +83,23 @@ import shutil | ||
| 83 | 83 | |
| 84 | 84 | # Loop through all files in the current folder |
| 85 | 85 | for file in glob.glob("*.eml"): |
| 86 | # Create boolean to check if we should move the file | |
| 87 | move = False | |
| 86 | # Create boolean to check if we should move the file | |
| 87 | move = False | |
| 88 | 88 | |
| 89 | # Open the current file | |
| 90 | f = open(file, 'r') | |
| 89 | # Open the current file | |
| 90 | f = open(file, 'r') | |
| 91 | 91 | |
| 92 | # For each line in file, find the From header | |
| 92 | # For each line in file, find the From header | |
| 93 | 93 | for line in f: |
| 94 | 94 | if line.startswith("From:"): |
| 95 | # If we find ourself, mark the message for move | |
| 95 | # If we find ourself, mark the message for move | |
| 96 | 96 | if "user@example.com" in line: |
| 97 | 97 | move = True |
| 98 | 98 | |
| 99 | 99 | # Close the file |
| 100 | f.close() | |
| 100 | f.close() | |
| 101 | 101 | |
| 102 | # Move the file, if marked for move | |
| 102 | # Move the file, if marked for move | |
| 103 | 103 | if move == True: |
| 104 | 104 | filepath = os.path.join("/Users/YOUR_USERNAME/.maildir/migadu/Archive/cur/", file) |
| 105 | 105 | new_filepath = os.path.join("/Users/YOUR_USERNAME/.maildir/migadu/Sent/cur/", file) |
| @@ -164,24 +164,24 @@ import shutil | ||
| 164 | 164 | |
| 165 | 165 | # Loop through all files in the sub-folders under Archive |
| 166 | 166 | for file in glob.glob("*.eml"): |
| 167 | # Create boolean to check if we should move the file | |
| 168 | move = False | |
| 167 | # Create boolean to check if we should move the file | |
| 168 | move = False | |
| 169 | 169 | |
| 170 | # Open the current file | |
| 170 | # Open the current file | |
| 171 | 171 | f = open(file, 'r') |
| 172 | 172 | |
| 173 | # For each line in file, find the X-Pm-Date header | |
| 173 | # For each line in file, find the X-Pm-Date header | |
| 174 | 174 | for line in f: |
| 175 | 175 | if line.startswith("X-Pm-Date"): |
| 176 | # Split the line into a list by spaces; | |
| 177 | # Then select the item that contains the year | |
| 176 | # Split the line into a list by spaces; | |
| 177 | # Then select the item that contains the year | |
| 178 | 178 | year = line.split(" ")[4] |
| 179 | 179 | move = True |
| 180 | 180 | |
| 181 | 181 | # Close the file |
| 182 | f.close() | |
| 182 | f.close() | |
| 183 | 183 | |
| 184 | # Move the file, if marked for move | |
| 184 | # Move the file, if marked for move | |
| 185 | 185 | if move == True: |
| 186 | 186 | filepath = os.path.join("/Users/YOUR_USERNAME/.maildir/migadu/Archive/cur/", file) |
| 187 | 187 | new_filepath = os.path.join(f"/Users/YOUR_USERNAME/.maildir/migadu/Archive/{year}/cur/", file) |
| @@ -220,9 +220,10 @@ import shutil | ||
| 220 | 220 | |
| 221 | 221 | # Loop through all files in the sub-folders under Archive |
| 222 | 222 | for file in glob.glob("*/cur/*"): |
| 223 | # Remove the characters at the end of the file name created by =mu= | |
| 223 | # Remove the characters at the end of the file name created by =mu= | |
| 224 | 224 | new_file = file.split(",U=",1)[0] |
| 225 | # Move the file to the new file name | |
| 225 | ||
| 226 | # Move the file to the new file name | |
| 226 | 227 | shutil.move(file, new_file) |
| 227 | 228 | #+end_src |
| 228 | 229 | |