Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh/Improve email printing #9669

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions src/components/MenuEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ import NcActionInput from '@nextcloud/vue/dist/Components/NcActionInput.js'
import AlarmIcon from 'vue-material-design-icons/Alarm.vue'
import logger from '../logger.js'
import moment from '@nextcloud/moment'
import { shortRelativeDatetime } from '../util/shortRelativeDatetime.js'
import { mapGetters } from 'vuex'

export default {
Expand Down Expand Up @@ -567,8 +568,45 @@ export default {
setCustomSnooze() {
this.onSnooze(this.customSnoozeDateTime.valueOf())
},
onPrint() {
window.print()
async onPrint() {
await this.$emit('print')

const printStyles = `
* {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Cantarell, Ubuntu, 'Helvetica Neue', Arial, 'Noto Color Emoji', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
};
`

let combinedContent = ''
const messageFrames = document.querySelectorAll('iframe.message-frame')

messageFrames.forEach(frame => {
const doc = frame.contentDocument || frame.contentWindow.document
combinedContent += doc.body.innerHTML
})

const frame = document.createElement('iframe')
frame.name = 'printFrame'
frame.style.position = 'absolute'
frame.style.top = '-1000000px'
document.body.appendChild(frame)
const frameDoc = frame.contentWindow ? frame.contentWindow : frame.contentDocument.document ? frame.contentDocument.document : frame.contentDocument
frameDoc.document.open()
frameDoc.document.write('<html><head><style>')
frameDoc.document.write(printStyles)
frameDoc.document.write('</style></head><body>')
frameDoc.document.write(document.querySelector('#mail-thread-header h2').outerHTML)
frameDoc.document.write(`<h4>${this.envelope.from[0].label}, ${this.envelope.from[0].email}</h4>`)
GVodyanov marked this conversation as resolved.
Show resolved Hide resolved
frameDoc.document.write(`<h4>${shortRelativeDatetime(new Date(this.envelope.dateInt * 1000))}</h4>`)
frameDoc.document.write(combinedContent)
frameDoc.document.write('</body></html>')
frameDoc.document.close()

setTimeout(function() {
window.frames.printFrame.focus()
window.frames.printFrame.print()
document.body.removeChild(frame)
}, 500)
},
},
}
Expand Down
52 changes: 4 additions & 48 deletions src/components/Thread.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
:expanded="expandedThreads.includes(env.databaseId)"
:full-height="thread.length === 1"
@delete="$emit('delete', env.databaseId)"
@print="printSetup"
@move="onMove(env.databaseId)"
@toggle-expand="toggleExpand(env.databaseId)" />
</template>
Expand Down Expand Up @@ -309,6 +310,9 @@ export default {
}
}
},
printSetup(databaseId) {
this.expandedThreads = [databaseId]
},
},
}
</script>
Expand Down Expand Up @@ -429,54 +433,6 @@ export default {
}
}

@media print {
#mail-thread-header-fields {
position: relative;
}
.app-content-details,
.splitpanes__pane-details {
max-width: unset !important;
width: 100% !important;
}
#header,
.app-navigation,
#reply-composer,
#forward-button,
#mail-message-has-blocked-content,
.app-content-list,
.message-composer,
.splitpanes__pane-list,
.splitpanes__splitter,
.mail-message-attachments {
display: none !important;
}
.app-content {
margin-left: 0 !important;
overflow: visible;
position: fixed;
}
#content-vue {
margin: 0;
width: 100%;
height: auto !important;
overflow-y: visible;
border-radius: 0;
position: fixed;
}
#mail-thread-header {
position: relative;
}
.envelope__header .right div {
display: none;
}
.avatar-header {
display: none;
}
html, #body-user {
height: auto !important;
}
}

.message-source {
font-family: monospace;
white-space: pre-wrap;
Expand Down
3 changes: 2 additions & 1 deletion src/components/ThreadEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@
:with-show-source="true"
:more-actions-open.sync="moreActionsOpen"
@reply="onReply"
@delete="$emit('delete',envelope.databaseId)"
@delete="$emit('delete', envelope.databaseId)"
@print="$emit('print', envelope.databaseId)"
@show-source-modal="onShowSourceModal"
@open-tag-modal="onOpenTagModal"
@open-move-modal="onOpenMoveModal"
Expand Down
Loading